babycrypto
Description
#!/usr/bin/python3 -u
import os
from binascii import hexlify, unhexlify
flag = open("./flag","rb").read()
class bb(object):
def __init__(self, key):
self.meh = [x for x in range(256)]
j = 0
for i in range(256):
j = (j + self.meh[i] + key[i%len(key)])&0xff
self.meh[i], self.meh[j] = self.meh[j], self.meh[i]
self.cat = 0
self.mouse = 0
def crypt(self, string):
out = []
for c in string:
self.cat = (self.cat+1)&0xff
self.mouse = (self.cat+self.meh[self.cat])&0xff
self.meh[self.cat], self.meh[self.mouse] = self.meh[self.mouse], self.meh[self.cat]
k = self.meh[ (self.meh[self.cat]+self.meh[self.mouse])&0xff ]//2
out.append((c+k)&0xff)
return bytearray(out)
cipher = bb(os.urandom(32))
while True:
print("Commands: \n(e)ncrypt msg or (p)rint flag")
choice = input()
if choice == 'e':
message = input()
print(hexlify(cipher.crypt(unhexlify(message))))
elif choice == 'p':
print(hexlify(cipher.crypt(flag)))
else:
print("meh!")Solution
Last updated