Skip to content

Instantly share code, notes, and snippets.

@Tony3-sec
Created November 25, 2018 23:33
Show Gist options
  • Save Tony3-sec/e812f64d36a86148ad99c7086c2e9817 to your computer and use it in GitHub Desktop.
Save Tony3-sec/e812f64d36a86148ad99c7086c2e9817 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
'''
This script will XOR the data.
The key and the payload must be in hex format
The script is simplified from my_xor.py
'''
import binascii
enc = "f155f55cf610ee5feb5cfd"
key = "9930"
dec = ""
n = 2
## if key is single byte
if ( (len(key) / 2) == 1):
m = 0
for i in range(0, len(enc), n):
dec += hex(int(enc[i:i+n], 16) ^ int(key[m:m+n], 16)).replace('0x', '').zfill(2)
## I put zifll because I didn't want to lose the leading zero in hex
## eg) 0xd -> 0x0d (this is what I want)
else:
m = 0
for i in range(0, len(enc), n):
dec += hex(int(enc[i:i+n], 16) ^ int(key[m:m+n], 16)).replace('0x', '').zfill(2)
m += n
## if the key gets to end, set the key back to beginning.
if (m >= len(key)):
m = 0
print(dec)
#dec = dec.replace('0d0d', '0d0a') ## not sure why but when hex contains '0d0d' it doesn't print properly so replacing to '0d0a'
#print(binascii.unhexlify(dec))
print(repr(binascii.unhexlify(dec)))
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment