Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
goelp14
GitHub Repository: goelp14/easyctf-iv-problems
Path: blob/master/license_check/grader.py
671 views
1
from io import BytesIO
2
import string
3
4
5
def grade(random, key):
6
try:
7
if (len(key) != 16):
8
return False, "Invalid length, only submit the license key."
9
email_key = 0x0aed12f1
10
final_xor = 0x0aecbcc2
11
hsh = 0
12
for i in range(0, 4):
13
n = int(key[(i*4):((i+1)*4)], 30)
14
if (n == 0):
15
return False, "Bad key value"
16
hsh ^= n
17
if ((final_xor ^ email_key ^ hsh) == 0):
18
return True, "Correct"
19
return False, "Key was incorrect"
20
except:
21
return False, "Invalid Key"
22
23