-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
executable file
·61 lines (52 loc) · 1.35 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/local/bin/python -u
from Crypto.Util.number import getPrime, isPrime, getRandomInteger
import sys, random
print("Are you truly the master here?")
print()
print("We'll have to find out...")
print()
def fail():
print("You are not the master!")
sys.exit(1)
def challenge1():
p = getPrime(44)
q = getPrime(1024)
n = p * q
return [p, q], n
def challenge2():
p = getPrime(1024)
q = p + getRandomInteger(524)
if q % 2 == 0: q += 1
while not isPrime(q): q += 2
n = p * q
return [p, q], n
def challenge3():
small_primes = [n for n in range(2,10000) if isPrime(n)]
def gen_smooth(N):
r = 2
while True:
p = random.choice(small_primes)
if (r * p).bit_length() > N:
return r
r *= p
p = 1
while not isPrime(p):
p = gen_smooth(1024) + 1
q = getPrime(1024)
n = p * q
return [p, q], n
challenges = [challenge1, challenge2, challenge3]
responses = ["Okay, not bad.", "Nice job.", "Wow."]
for i, chal in enumerate(challenges):
print(f"CHALLENGE {i+1}")
factors, n = chal()
factors.sort()
print(f"n = {n}")
guess = input("factors = ? ")
if guess != " ".join(map(str,factors)):
fail()
print(responses[i])
print()
print("Here's your flag:")
with open("flag.txt") as f:
print(f.read().strip())