Skip to content

Instantly share code, notes, and snippets.

@mtask
Last active September 15, 2023 14:06
Show Gist options
  • Save mtask/5bba6a10a508715ede06aa94afb5f2bb to your computer and use it in GitHub Desktop.
Save mtask/5bba6a10a508715ede06aa94afb5f2bb to your computer and use it in GitHub Desktop.
stuff
import re
import itertools
RES = []
def xor(var, key):
return bytes(a ^ b for a, b in zip(var, key))
def xorbyte(b):
r = []
for n in range(0, 256):
x = hex(n).replace("0x", "")
if len(x) < 2:
x = "0"+x
key = bytes.fromhex(x)
try:
res = xor(b, key).decode('utf-8')
if re.match('[ -~]', res):
r.append(res)
except UnicodeDecodeError:
pass
return r
with open("test.txt.enc", "rb") as f:
while (b := f.read(1)):
r = xorbyte(b)
if r:
RES.append(r)
for i in itertools.product(*RES):
print(''.join(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment