-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdecryptQbotString.py
More file actions
47 lines (40 loc) · 1.24 KB
/
decryptQbotString.py
File metadata and controls
47 lines (40 loc) · 1.24 KB
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
45
46
47
import sys
CRYPTO_BLOB1 = 0xA740
CRYPTO_BLOB1_SZ = 0x347C
CRYPTO_BLOB2 = 0xED20
def decryptString(const, fileData):
"""Decrypt a string."""
i = 0
andVal = 0x3f
decryptedStr = ""
strLen = 0x0
pos = const
# The first loop is used to determine the length of the string we are about to decrypt
while pos < 0x347b:
offsPos = pos & andVal
xorb = fileData[CRYPTO_BLOB2 + offsPos]
z = xorb ^ fileData[CRYPTO_BLOB1 + pos]
if z == 0:
strLen = pos - const
print(f"Zero reached after {hex(strLen)} iterations")
print(f"String length = {hex(strLen)}")
break
pos += 1
i = 0
pos = const + i
# This loop is used for decryption itself and actually fills the second heap with the decrypted string
while i < strLen:
offsPos = (pos & andVal)
xorb = fileData[CRYPTO_BLOB2 + offsPos]
decryptChar = xorb ^ fileData[CRYPTO_BLOB1 + pos]
i += 1
pos += 1
decryptedStr += chr(decryptChar)
return decryptedStr
def main():
"""Main."""
testConst = 0x596
fileData = open(sys.argv[1], "rb").read()
string = decryptString(testConst, fileData)
if __name__ == '__main__':
main()