Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #2

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions 2proc_pmutex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import sys
import threading

interested = []
interested.append(False)
interested.append(False)
interested = [False, False]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 7-9 refactored with the following changes:



def enter_region(process):
Expand All @@ -33,7 +31,7 @@ def leave_region(process):


def proc(n):
t = int(random.randint(0, 1))
t = random.randint(0, 1)
Comment on lines -36 to +34
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function proc refactored with the following changes:

enter_region(n)
time.sleep(t)
leave_region(n)
Expand Down
6 changes: 2 additions & 4 deletions CVE-2017-7679.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ def check_url(url, buff=None):

opener = urllib2.build_opener(urllib2.HTTPSHandler(context=ctx))
if buff:
opener.addheaders.append(("Content-Type", "text/html;" + buff))
opener.addheaders.append(("Content-Type", f"text/html;{buff}"))
else:
opener.addheaders.append(("Content-Type", "text/html;"))

data = opener.open(url).read()

return data
return opener.open(url).read()
Comment on lines -24 to +28
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function check_url refactored with the following changes:



s1 = check_url(sys.argv[1])
Expand Down
31 changes: 7 additions & 24 deletions SIMM_Pin_Recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,11 @@ def encode_pin_cmd(self, n, s):
B = 0x30 + int(N[1])
C = 0x30 + int(N[2])
D = 0x30 + int(N[3])
E = 0xFF
F = 0xFF
G = 0xFF
H = 0xFF

if l > 4:
E = 0x30 + int(N[4])
if l > 5:
F = 0x30 + int(N[5])
if l > 6:
G = 0x30 + int(N[6])
if l > 7:
H = 0x30 + int(N[7])

COMM = [
E = 0x30 + int(N[4]) if l > 4 else 0xFF
F = 0x30 + int(N[5]) if l > 5 else 0xFF
G = 0x30 + int(N[6]) if l > 6 else 0xFF
H = 0x30 + int(N[7]) if l > 7 else 0xFF
return [
Comment on lines -86 to +90
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Attack.encode_pin_cmd refactored with the following changes:

This removes the following comments ( why? ):

# APDU with command pkt

0xA0,
0x20,
0x00,
Expand All @@ -111,9 +101,7 @@ def encode_pin_cmd(self, n, s):
F,
G,
H,
] # APDU with command pkt

return COMM
]

def crack_pin(self):
"""The function just forms a APDU with the pin then sends it to the reader and waits for the status."""
Expand Down Expand Up @@ -186,12 +174,7 @@ def crack_pin(self):
connection = r[0].createConnection()
connection.connect()

if args.startpin:
# n= 00274710
n = int(args.startpin)
else:
n = 0

n = int(args.startpin) if args.startpin else 0
Comment on lines -189 to +177
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 189-194 refactored with the following changes:

This removes the following comments ( why? ):

# n= 00274710

if args.lenght:
if 4 <= int(args.lenght) <= 8:
l = int(args.lenght)
Expand Down
2 changes: 1 addition & 1 deletion TOTP_test2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
secret = row[2]
issuer = row[6]

data = "otpauth://totp/%s?secret=%s&issuer=%s" % (account, secret, issuer)
data = f"otpauth://totp/{account}?secret={secret}&issuer={issuer}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 26-26 refactored with the following changes:

img = qrcode.make(data)
img.show()
2 changes: 1 addition & 1 deletion X16Rlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def round(b, n, s=32):
try:
d = h.digest(s)
except:
d = h.digest()[0 : s * 2]
d = h.digest()[:s * 2]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function round refactored with the following changes:

return d


Expand Down
10 changes: 4 additions & 6 deletions asus_thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ def beep(f):


def gettemp():
fp = open("/sys/class/thermal/thermal_zone0/temp", "r")
temp = float(fp.read()) / 1000
fp.close()
with open("/sys/class/thermal/thermal_zone0/temp", "r") as fp:
temp = float(fp.read()) / 1000
Comment on lines -13 to +14
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function gettemp refactored with the following changes:

return temp


def getfan():
fp = open("/sys/devices/platform/asus-nb-wmi/hwmon/hwmon2/fan1_input")
rpm = int(fp.read())
fp.close()
with open("/sys/devices/platform/asus-nb-wmi/hwmon/hwmon2/fan1_input") as fp:
rpm = int(fp.read())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getfan refactored with the following changes:

return rpm


Expand Down
4 changes: 2 additions & 2 deletions bigquery_batch_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def query(SQL, table_dest):

tmp = tmp.split(";")
for sql in tmp:
if sql != "" and sql != "\n":
sql = sql + ";"
if sql not in ["", "\n"]:
sql = f"{sql};"
Comment on lines -43 to +44
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 43-44 refactored with the following changes:

print(sql)
query(sql, table_dest)
38 changes: 19 additions & 19 deletions binet_oeis_crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ def binet(a,b,n):

"""


l = 20
for i in range(0,l):
for j in range(i,l):
tmp = []
if i != j:
for k in range(1,l):
try:
tmp.append(str(round(binet(i,j,k))))
except:
pass
q = ",".join(tmp)
try:
res=op.resultEois(q)
m = "a: %d, b: %d, Name: A%06d, Desc: %s\n" % (i,j,op.getNumber(res[0]),op.getName(res[0]))
except:
m = ""
pass
sys.stderr.write(m)
sys.stdout.write(m)
sys.stdout.flush()
sys.stderr.flush()
for j in range(i,l):
tmp = []
if i != j:
for k in range(1,l):
try:
tmp.append(str(round(binet(i,j,k))))
except:
pass
q = ",".join(tmp)
try:
res=op.resultEois(q)
m = "a: %d, b: %d, Name: A%06d, Desc: %s\n" % (i,j,op.getNumber(res[0]),op.getName(res[0]))
except:
m = ""
sys.stderr.write(m)
sys.stdout.write(m)
sys.stdout.flush()
sys.stderr.flush()
Comment on lines +19 to +39
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 21-39 refactored with the following changes:


3 changes: 1 addition & 2 deletions bitnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def make_request(*args):


def getjson(url):
jdata = json.loads(make_request(url))
return jdata
return json.loads(make_request(url))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getjson refactored with the following changes:



data = getjson(url)
Expand Down
19 changes: 9 additions & 10 deletions bitshuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ def Transpose16X16(tmp):


def bitshuffle(buff, mode):
if len(buff) % 8 == 0:
buff2 = ""
if mode == 8:
for i in xrange(0, len(buff) - 1, 8):
buff2 += Transpose8X8(buff[i : i + 8])
elif mode == 16:
for i in xrange(0, len(buff) - 1, 16):
buff2 += Transpose16X16(buff[i : i + 16])
return buff2
else:
if len(buff) % 8 != 0:
raise Exception("Buffer must be a multiple of 8 bytes")
buff2 = ""
if mode == 8:
for i in xrange(0, len(buff) - 1, 8):
buff2 += Transpose8X8(buff[i : i + 8])
elif mode == 16:
for i in xrange(0, len(buff) - 1, 16):
buff2 += Transpose16X16(buff[i : i + 16])
return buff2
Comment on lines -34 to +43
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function bitshuffle refactored with the following changes:



if __name__ == "__main__":
Expand Down
31 changes: 11 additions & 20 deletions bitsigtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,24 @@ def download_page(url):
import urllib.request # urllib library for Extracting web pages

try:
headers = {}
headers[
"User-Agent"
] = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
}
req = urllib.request.Request(url, headers=headers)
resp = urllib.request.urlopen(req)
respData = str(resp.read())
# print (len(respData) // 1024),"KB"

return respData
return str(resp.read())
except Exception as e:
return None
else: # If the Current Version of Python is 2.x
import urllib2

try:
headers = {}
headers[
"User-Agent"
] = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17"
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17"
}
req = urllib2.Request(url, headers=headers)
response = urllib2.urlopen(req)
page = response.read()
# print (len(page) // 1024),"KB"

return page
return response.read()
Comment on lines -28 to +45
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function download_page refactored with the following changes:

This removes the following comments ( why? ):

# print (len(page) // 1024),"KB"
# print (len(respData) // 1024),"KB"

except:
return None

Expand Down Expand Up @@ -86,10 +78,9 @@ def _get_all_items(page):
item, end_content = _get_next_item(page)
if item == "no_links":
break
else:
items.append(item) # Append all the links in the list named 'Links'
# time.sleep(0.1) #Timer could be used to slow down the request for image downloads
page = page[end_content:]
items.append(item) # Append all the links in the list named 'Links'
# time.sleep(0.1) #Timer could be used to slow down the request for image downloads
page = page[end_content:]
Comment on lines -89 to +83
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _get_all_items refactored with the following changes:

if len(item) > 10000:
break
return items
Expand Down
8 changes: 2 additions & 6 deletions btcaddrinputget.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ def getinputs(addr_test, offset):
)
f = urllib2.urlopen(req)

data = ""
addrs = []

for line in f:
data += line

data = "".join(f)
Comment on lines -12 to +14
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getinputs refactored with the following changes:

json_obj = json.loads(data)

for item in json_obj["txs"]:
Expand All @@ -23,8 +20,7 @@ def getinputs(addr_test, offset):
if addr != addr_test:
addrs.append(addr)

addrs = sorted(set(addrs))
return addrs
return sorted(set(addrs))


for i in range(0, 800):
Expand Down
16 changes: 7 additions & 9 deletions check_nmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@


def loadfile(f):
fp = open(f, "r")
d = fp.read()
fp.close()
with open(f, "r") as fp:
d = fp.read()
Comment on lines -17 to +18
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function loadfile refactored with the following changes:

return d


def savefile(f, data):
fp = open(f, "w")
fp.write(data)
fp.close()
with open(f, "w") as fp:
fp.write(data)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function savefile refactored with the following changes:



def json2file(f, s):
json_data = str(json.dumps(s))
json_data = json.dumps(s)
Comment on lines -30 to +28
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function json2file refactored with the following changes:

savefile(f, json_data)


Expand All @@ -41,7 +39,7 @@ def file2json(f):

def getold_nm(host):
try:
old_nm = file2json(".check_nmap.py." + host + ".cache")
old_nm = file2json(f".check_nmap.py.{host}.cache")
Comment on lines -44 to +42
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getold_nm refactored with the following changes:

except:
old_nm = None
return old_nm
Expand Down Expand Up @@ -79,7 +77,7 @@ def proc_results(nm, old_nm, host, ports):
if a != b:
output += "tcp port: %s, old_state: %s, state: %s\n" % (port, a, b)
num_status = 2
output0 += "tcp %s: %s," % (port, b)
output0 += f"tcp {port}: {b},"
Comment on lines -82 to +80
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function proc_results refactored with the following changes:

else:
num_status = 3
output = "Could not get scan results, check your firewall!"
Expand Down
2 changes: 1 addition & 1 deletion classic_shor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def factor(N, g, P):
N = mpz(gmpy2.next_prime(2 ** bits) * gmpy2.next_prime((2 ** bits) + offset))
# N= 1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139

while len(s) == 0:
while not s:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 48-48 refactored with the following changes:

g = random.randint(2, 2 ** bits)
print("N:", N, "g:", g)
s = factor(N, g, P=max_p)
Expand Down
5 changes: 1 addition & 4 deletions compression_test1.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ def test2(data):

# test(str(bytearray((1024**2)*100)))

data = ""
for line in fileinput.input():
data += line

data = "".join(fileinput.input())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 85-88 refactored with the following changes:

test(data)
test2(data)
10 changes: 2 additions & 8 deletions count_bits_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@


def count_ones(s):
tmp = 0
for i in range(0, len(s) - 1):
if s[i] == "1":
tmp += 1
return tmp
return sum(1 for i in range(0, len(s) - 1) if s[i] == "1")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function count_ones refactored with the following changes:



d = {}
Expand All @@ -26,8 +22,6 @@ def count_ones(s):

data = []
for k in dict(sorted(d.items())[::-1]):
for i in d[k]:
data.append(i)

data.extend(iter(d[k]))
Comment on lines -29 to +25
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 29-31 refactored with the following changes:

for line in data:
print(data)
Loading
Loading