Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zvodd
Created February 1, 2017 01:06
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 zvodd/9fca2de8010e1d356325dc4296f1e82f to your computer and use it in GitHub Desktop.
Save zvodd/9fca2de8010e1d356325dc4296f1e82f to your computer and use it in GitHub Desktop.
Python3 rotates and decodes all variation of rot on a file, hunts for an egg string.
import re
from pprint import pprint, pformat
FILENAME = 'possibly_rot13.bin'
MYEGG = 'WPA'
#Generic String finder
STRINGS_RE = re.compile(r'[\!\@\#\$\%\^\&\*\(\)\_\+\`\~\-\=\\\|\[\]\{\}\;\:\'\"\,\.\/\<\>\?a-zA-Z\d\s]{3,}')
def find_strings(instr):
return STRINGS_RE.findall(instr)
def find_egg(instr, egg):
return instr.find(egg)
def rot_table(rot):
return bytes(((b + rot)%256 for b in range(0,256)))
def xor_table(uint8):
return bytes(((b ^ uint8)%256 for b in range(0,256)))
def main():
with open(FILENAME, 'rb') as fh:
fcontents = fh.read()
for i in range(0, 256):
# table = xor_table(i)
table = rot_table(i)
ncont = fcontents.translate(table)
text = ncont.decode('ascii', errors='ignore')
found = find_egg(text, MYEGG)
if found > 0:
print (i)
# found = find_strings(text)
# pprint(found)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment