Skip to content

Instantly share code, notes, and snippets.

@hub2
Created June 6, 2019 08:32
Show Gist options
  • Save hub2/bcba0f30c7f05dd390415dac4a58ec31 to your computer and use it in GitHub Desktop.
Save hub2/bcba0f30c7f05dd390415dac4a58ec31 to your computer and use it in GitHub Desktop.
import random
import string
random.seed(3)
indent_counter = 0
global_val = 0
def indent(func):
def wrapper(*args):
global indent_counter, global_val
out = func(*args)
o = []
current = random.randint(0,1000000000000000)
global_val += current
out = """try:
{}
raise CustomException({})
except CustomException as e_{}:""".format(out, current, indent_counter)
for line in out.split("\n"):
o.append(" "*indent_counter + line)
indent_counter+=1
return "\n".join(o) + "\n"
return wrapper
@indent
def real_sub_number(name, one, two):
return """{} = {}-{}""".format(name, one, two, random.randint)
@indent
def real_add_number(name, one, two):
return """{} = {}+{}""".format(name, one, two)
@indent
def real_new_number(name, number):
return """{} = {}""".format(name, number)
@indent
def real_xor_number(name, one, two):
return """{} = {}^{}""".format(name, one, two)
@indent
def print_var(var):
return """print({})""".format(var)
def finish():
global indent_counter
return " " * indent_counter + "pass"
def just_indent(code):
return " " * indent_counter + code + "\n"
def new_number(name, number):
a = random.randint(0, number)
b = random.randint(0, number)
c = random.randint(0, number)
d = random.randint(0, number)
out = number-a+b-c+d
val_name = id_generator(10)
a_name = id_generator(10)
b_name = id_generator(10)
c_name = id_generator(10)
d_name = id_generator(10)
#print(a,b,c,d,out)
t1 = real_new_number(val_name, out)
t2 = real_add_number(a_name, val_name, a) + real_sub_number(b_name, a_name, b) + real_add_number(c_name, b_name, c) + real_sub_number(name, c_name, d)
return t1+t2
def id_generator(size=6, chars=string.ascii_uppercase):
return ''.join(random.choice(chars) for _ in range(size))
varz = [
id_generator(10) for i in range(32)
]
varz1 = [
id_generator(10) for i in range(32)
]
code = [
"from Crypto.Cipher import AES\n",
"class CustomException(Exception):\n pass\n",
"i=input()\n"
]
for idx, var in enumerate(varz):
val = random.randint(0, 256)
open("vars", "a+").write(str(val)+"\n")
code.append(new_number(var, val))
code.append(real_xor_number(varz1[idx], var, "ord(i[{}])".format(idx)))
key = "".join(varz1)
open("keys", "w").write(key)
code.append(just_indent("l=locals()"))
code.append(just_indent("s=str(sum([int(str(l[x])) for x in l if x.startswith('e_')])**2)"))
code.append(just_indent("out=AES.new(s[:32].encode('utf-8'), AES.MODE_CBC, b'\\x00'*16).encrypt(b''.join([bytes([x]) for x in [{}]])[:32])".format(",".join(varz1))))
#code.append(just_indent("print(out)"))
code.append(just_indent("if out==b'`X\\xd6n1\\xf1HKP\\x08/\\xf4D\\x89\\x1dP\\x99LSx\\x92\\x8f4\\xa3\\xb6\\xd1\\xb0 \\xd7\\xcb\\xfa\\x1f': print('yes')"))
code.append(just_indent("else: print('no')"))
code.append(finish())
out = "".join(code)
print(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment