yapf formatted
This commit is contained in:
parent
94b1c908c4
commit
5695cf04bb
1 changed files with 71 additions and 69 deletions
44
libexam.py
44
libexam.py
|
@ -9,6 +9,7 @@ BS = 16
|
|||
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS).encode()
|
||||
unpad = lambda s: s[:-ord(s[len(s) - 1:])]
|
||||
|
||||
|
||||
def iv():
|
||||
"""
|
||||
The initialization vector to use for encryption or decryption.
|
||||
|
@ -16,6 +17,7 @@ def iv():
|
|||
"""
|
||||
return chr(0) * 16
|
||||
|
||||
|
||||
class AESCipher(object):
|
||||
"""
|
||||
https://github.com/dlitz/pycrypto
|
||||
|
@ -42,8 +44,11 @@ class AESCipher(object):
|
|||
dec = cipher.decrypt(enc)
|
||||
return unpad(dec).decode('utf-8')
|
||||
|
||||
|
||||
class question:
|
||||
def __init__(self, qtype, qproblem, qoption1, qoption2, qoption3, qoption4):
|
||||
|
||||
def __init__(self, qtype, qproblem, qoption1, qoption2, qoption3,
|
||||
qoption4):
|
||||
qtype = self.qtype
|
||||
qproblem = self.qproblem
|
||||
qoption1 = self.qoption1
|
||||
|
@ -70,7 +75,6 @@ class libexam:
|
|||
return f"""Mode: {mode}
|
||||
Username: {username}\n"""
|
||||
|
||||
|
||||
def setuser(user):
|
||||
username = user
|
||||
print(f"Username set to: {user}\n")
|
||||
|
@ -104,7 +108,9 @@ class libexam:
|
|||
print(f"Hashes match: {rhash}\n")
|
||||
break
|
||||
else:
|
||||
print(f"Hashes does not match !\nExpected: {ehash}\nGot: {rhash}\n")
|
||||
print(
|
||||
f"Hashes does not match !\nExpected: {ehash}\nGot: {rhash}\n"
|
||||
)
|
||||
return 1
|
||||
sha256.update(temp)
|
||||
|
||||
|
@ -112,8 +118,6 @@ class libexam:
|
|||
questiondocs = open("question.txt", "r")
|
||||
temp = questiondocs.readline()
|
||||
|
||||
|
||||
|
||||
while (True):
|
||||
temp = questiondocs.readline()
|
||||
if (temp == "chk"):
|
||||
|
@ -123,16 +127,14 @@ class libexam:
|
|||
temp = questiondocs.readline()
|
||||
temp = temp.split("|")
|
||||
|
||||
questions.append(question(qtype,temp[0],temp[1],temp[2],temp[3],temp[4]))
|
||||
|
||||
|
||||
questions.append(
|
||||
question(qtype, temp[0], temp[1], temp[2], temp[3], temp[4]))
|
||||
|
||||
def writeanswer(qn, ans):
|
||||
if (username == ""):
|
||||
print(f"Username not set!\n")
|
||||
return 1
|
||||
|
||||
|
||||
md5 = hashlib.md5()
|
||||
md5.update(username)
|
||||
filename = md5.digest()
|
||||
|
@ -140,7 +142,6 @@ class libexam:
|
|||
|
||||
sha256 = hashlib.sha256()
|
||||
|
||||
|
||||
datadocs = open(f"{filename}.txt", "r")
|
||||
n = datadocs.readline()
|
||||
sha256.update(n)
|
||||
|
@ -157,11 +158,12 @@ class libexam:
|
|||
print(f"Hashes match: {rhash}\n")
|
||||
break
|
||||
else:
|
||||
print(f"Hashes does not match !\nExpected: {ehash}\nGot: {rhash}\n")
|
||||
print(
|
||||
f"Hashes does not match !\nExpected: {ehash}\nGot: {rhash}\n"
|
||||
)
|
||||
return 1
|
||||
sha256.update(temp)
|
||||
|
||||
|
||||
datadocs.close()
|
||||
datadocs = open(f"{filename}.txt", "r+")
|
||||
|
||||
|
@ -204,7 +206,6 @@ class libexam:
|
|||
datadocs.writelines(data)
|
||||
datadocs.close()
|
||||
|
||||
|
||||
datadocs = open(f"{filename}.txt", "r+")
|
||||
n = datadocs.readline()
|
||||
sha256.update(n)
|
||||
|
@ -219,7 +220,6 @@ class libexam:
|
|||
|
||||
print(f"New hash generated: {targethash}\n")
|
||||
|
||||
|
||||
# read a list of lines into data
|
||||
data = datadocs.readlines()
|
||||
|
||||
|
@ -237,7 +237,6 @@ class libexam:
|
|||
print(f"Username not set!\n")
|
||||
return 1
|
||||
|
||||
|
||||
md5 = hashlib.md5()
|
||||
md5.update(username)
|
||||
filename = md5.digest()
|
||||
|
@ -245,7 +244,6 @@ class libexam:
|
|||
|
||||
sha256 = hashlib.sha256()
|
||||
|
||||
|
||||
datadocs = open(f"{filename}.txt", "r")
|
||||
n = datadocs.readline()
|
||||
sha256.update(n)
|
||||
|
@ -262,7 +260,9 @@ class libexam:
|
|||
print(f"Hashes match: {rhash}\n")
|
||||
break
|
||||
else:
|
||||
print(f"Hashes does not match !\nExpected: {ehash}\nGot: {rhash}\n")
|
||||
print(
|
||||
f"Hashes does not match !\nExpected: {ehash}\nGot: {rhash}\n"
|
||||
)
|
||||
return 1
|
||||
sha256.update(temp)
|
||||
|
||||
|
@ -280,7 +280,9 @@ class libexam:
|
|||
if (s1hash == s1h.digest()):
|
||||
print(f"Hashes match: {s1hash}\n")
|
||||
else:
|
||||
print(f"Hashes does not match !\nExpected: {s1h.digest()}\nGot: {s1hash}\n")
|
||||
print(
|
||||
f"Hashes does not match !\nExpected: {s1h.digest()}\nGot: {s1hash}\n"
|
||||
)
|
||||
return 1
|
||||
|
||||
userhash = hashlib.sha256()
|
||||
|
@ -302,7 +304,9 @@ class libexam:
|
|||
if (s2hash == s2h.digest()):
|
||||
print(f"Hashes match: {s2hash}\n")
|
||||
else:
|
||||
print(f"Hashes does not match !\nExpected: {s2h.digest()}\nGot: {s2hash}\n")
|
||||
print(
|
||||
f"Hashes does not match !\nExpected: {s2h.digest()}\nGot: {s2hash}\n"
|
||||
)
|
||||
return 1
|
||||
|
||||
timestamp = int(s2data[0:15], 16)
|
||||
|
@ -310,5 +314,3 @@ class libexam:
|
|||
|
||||
print(f"Found answer: {s2data[16:]}")
|
||||
return s2data[16:]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue