Skip to content

Instantly share code, notes, and snippets.

@ricardojba
Last active July 6, 2020 11:05
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 ricardojba/2eeb5c1b0b051ca1b51ed03f27053793 to your computer and use it in GitHub Desktop.
Save ricardojba/2eeb5c1b0b051ca1b51ed03f27053793 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
def xor(data,key):
return bytearray(((data[i]^key[i%len(key)]) for i in range(0,len(data))))
data = bytearray(open("my_magic_bytes.jpg.enc","rb").read())
# Known plaintext from wikipedia https://en.wikipedia.org/wiki/List_of_file_signatures - XOR the enc file with it first
#key = bytearray([0xFF,0xD8,0xFF,0xE0,0x00,0x10,0x4A,0x46,0x49,0x46,0x00,0x01])
# 12 bytes key extracted from the file after the first above XOR
key = bytearray([0x46,0xcc,0xf9,0xa5,0x71,0xf0,0xff,0xb1,0x7e,0x41,0xcb,0x84])
out = xor(data,key)
fout = open("my_magic_bytes.jpg","wb")
fout.write(out)
fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment