Last active
October 24, 2017 14:40
-
-
Save Tony3-sec/498537a3d9d1958af7a4e1d26e4dae2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
This script will XOR the data. | |
The key and the payload must be in hex format | |
''' | |
#from binascii import unhexlify ##for python3 | |
enc = "2dec09e50aa932e617e501a8" | |
key = "6589" | |
enc_length = len(enc) / 2 | |
key_length = len(key) | |
a = 0 | |
b = 2 | |
c = 0 | |
d = 2 | |
dec = "" | |
## If the key is single byte | |
if (key_length == 2): | |
for cnt in range(int(enc_length)): | |
dec += hex(int(enc[a:b], 16) ^ int(key[c:d], 16)).replace('0x', '').zfill(2) | |
a += 2 | |
b += 2 | |
else: | |
for cnt in range(enc_length): | |
## when the key gets to end, reset the key to beginning | |
if (d == key_length): | |
dec += hex(int(enc[a:b], 16) ^ int(key[c:d], 16)).replace('0x', '').zfill(2) | |
## I put zfill because I didn't want to lose the leading zero in hex | |
## eg) 0xd -> 0x0d (this is what I want) | |
c = 0 # reset the key to beginning | |
d = 2 # reset the key to beginning | |
a += 2 | |
b += 2 | |
else: | |
dec += hex(int(enc[a:b], 16) ^ int(key[c:d], 16)).replace('0x', '').zfill(2) | |
a += 2 | |
b += 2 | |
c += 2 | |
d += 2 | |
print("raw hex: ") | |
print("#######") | |
print(dec) | |
print("") | |
print("decoded string: ") | |
print("#######") | |
print(dec.decode('hex')) | |
## print(unhexlify(dec)) # for python3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment