-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode_uo_pass.py
44 lines (37 loc) · 1.08 KB
/
decode_uo_pass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def decrypt(key, cyphertext):
plaintext = ''
key = key.encode('utf-8')
kidx = 0
for i in range(0, len(cyphertext), 2):
byte = int(cyphertext[i:i+2], 16)
k = key[kidx]
kidx += 1
kidx = kidx % len(key)
c = chr(byte ^ k)
plaintext += c
return plaintext
def encrypt(key, plaintext):
plaintext = plaintext.encode('utf8')
cyphertext = ''
key = key.encode('utf8')
kidx = 0
for plainbyte in plaintext:
k = key[kidx]
kidx += 1
kidx = kidx % len(key)
byte = plainbyte ^ k
cyphertext += str.format('{:02X}', byte)
return cyphertext
def main():
# password from default.xml in razor dir
# omit the 1+
# the actual problem was not the code, but finding this algorithm
cyphertext = '0500000E0E4D3223302D29'
key = 'melba' # windows username
print(decrypt(key, cyphertext))
print(encrypt(key, 'hello WORLD'))
# random test
plaintext = 'hello world'
assert plaintext == decrypt(key, encrypt(key, plaintext))
if __name__ == '__main__':
main()