Skip to content

Instantly share code, notes, and snippets.

@pawlos
Created April 9, 2018 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawlos/2aa28a77fe9b3c1b404d56e77ff46b7d to your computer and use it in GitHub Desktop.
Save pawlos/2aa28a77fe9b3c1b404d56e77ff46b7d to your computer and use it in GitHub Desktop.
Bruteforcing a xor key char
import sys
import string
data = 'e7225ea6c31ec63e843f53e3da21e104c5611c80c82cea02e7225ea6c31dea13d12955b7c819e604cc165da0d927e115e83e5db1df27e117855b'.decode('hex')
data = bytearray(data)
deciphered = ['Cy',' d','a:','Cy','ur','hM','Le','!\x00']
chrset = string.ascii_lowercase+string.digits+string.ascii_uppercase+'!'+'\x00'+':'+' '+'_'+'@'
print chrset
ofs = 2
for i in range(255):
r = ''
n = ~i
for k in range(0,len(data)-ofs,8):
r += deciphered[k/8]
r += chr((data[k+ofs] ^ i) & 255)
r += chr((data[k+ofs+1] ^ n) & 255)
r += ' '
r += deciphered[7]
if all(c in chrset for c in r):
print hex(i), r#, r.encode('hex')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment