zvodd
2/1/2017 - 1:06 AM

Python3 rotates and decodes all variation of rot on a file, hunts for an egg string.

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()