2 # -*- coding: utf-8 -*-
12 return ''.join(random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for _ in range(N))
15 def isprintable(mystr):
16 return all(c in string.printable for c in mystr)
20 r = random.randint(0, 5)
21 HASH = [md5, sha1, sha224, sha256, sha384, sha512]
23 l = random.randint(10, 40)
24 pr("Please submit a printable string X, such that", HASH[r].__name__.split('_')[1] + "(X)[-6:] =",
25 HASH[r](X).hexdigest()[-6:], 'and len(X) =', l)
27 return isprintable(Y) and HASH[r](Y).hexdigest()[-6:] == HASH[r](X).hexdigest()[-6:] and len(Y) == l
33 vux = inp.replace(list(pm)[0] * 2, chr(0)).replace(list(pm)[1] * 2, chr(1))
34 if set(vux) == set([chr(0), chr(1)]) and len(inp) <1<<10:
35 return True and len(inp) > 4
47 return [random.randint(32, 64), random.randint(-64, -32)][random.randint(0, 1)]
50 rs = (random.randint(0, 128) + 128, random.randint(0, 128) + 128)
52 if GCD(rs[0], rs[1]) == 1:
54 rs = (random.randint(0, 128) + 128, random.randint(0, 128) + 128)
61 c = first_number, d = second_number;
62 int a = first_random, b = second_random;
69 def var_handler(first_var, second_var, first_rand, second_rand, first_number, second_number):
72 tmp_code = str(tmp_code).replace("first_random", str(first_rand))
73 tmp_code = str(tmp_code).replace("second_random", str(second_rand))
74 tmp_code = str(tmp_code).replace("first_number", str(first_var) + "c+" + str(first_number))
75 tmp_code = str(tmp_code).replace("second_number", str(second_var) + "d+" + str(second_number))
76 random_name = genrandstr(16)
77 full_random_name = '/tmp/' + random_name + '.cpp'
78 c_file = open(full_random_name, 'w')
79 c_file.write(tmp_code)
82 command1 = "g++ " + full_random_name + " -o " + "/tmp/" + random_name
83 command2 = "/tmp/" + random_name
85 process = subprocess.Popen(command2, shell=True, stdout=subprocess.PIPE)
87 os.remove("/tmp/" + random_name)
88 os.remove('/tmp/' + random_name + '.cpp')
89 if str(process.returncode) == '0':
99 pr(border, "Elliot has been trying to defeat the Red Army since May 9th hacking incident. ", border)
100 pr(border, "He has ultimately found a way to their hidden bank using a Mr.Robot! ", border)
101 pr(border, "You have to play your role in the story and help Elliot to arrange his attack!", border)
103 first_number, second_number = [rangen() for _ in range(2)]
104 first_rand, second_rand = rancof()
106 pr("| Options: \n|\t[G]et the C source code \n|\t[T]ry to solve \n|\t[Q]uit!")
111 tmp_code = str(tmp_code).replace("second_number", str(second_number))
112 tmp_code = str(tmp_code).replace("first_number", str(first_number))
113 tmp_code = str(tmp_code).replace("first_random", str(first_rand))
114 tmp_code = str(tmp_code).replace("second_random", str(second_rand))
117 pr("Please enter first variable:")
119 pr("Please enter second variable:")
121 if isprintable(first_var) and isprintable(second_var) and aux(first_var) and aux(second_var):
122 if var_handler(first_var, second_var, first_rand, second_rand, first_number, second_number):
123 die("You win the battle, here you are :", flag)
127 die("000ps... Inappropriate variable")
129 die(border, "Quiting ...")
131 die(border, "Bye ...")
133 die('PoW challenge failed :P')
141 s = " ".join(map(str, args))
142 sys.stdout.write(s + "\n")
146 return sys.stdin.readline().strip()
148 if __name__ == '__main__':