· 6 years ago · Oct 22, 2019, 02:14 AM
1#import FLAG from FLAGS
2#import SECRET_KEY from SECRET_KEYS
3
4def encrypt(plane_text, secret_key):
5 cipher_text = ""
6 for pt, key in zip(plane_text, secret_key):
7 cipher_num = ord(pt) ^ ord(key)
8 cipher_text += format(cipher_num, '02x')
9 return cipher_text
10
11def padding(plane_text):
12 pt_l = len(plane_text)
13 if pt_l == 50:
14 return plane_text
15 else:
16 plane_text += "%" * (50 - pt_l)
17 return plane_text
18
19def main():
20 secret_key = SECRET_KEY
21 plane_text = padding(FLAG)
22 cipher_text = encrypt(plane_text, secret_key)
23 with open("result.txt", 'a') as f:
24 f.write("FLAG result: " + FLAG)
25
26if __name__ == "__main__":
27 main()