Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ashutosh1206
GitHub Repository: ashutosh1206/crypton
Path: blob/master/Discrete-Logarithm-Problem/Challenges/Baby-DLP/Server/server.py
1402 views
1
# Python 3
2
from signal import alarm
3
from Crypto.Util.number import *
4
5
p = 160634950613302858781995506902938412625377360249559915379491492274326359260806831823821711441204122060415286351711411013883400510041411782176467940678464161205204391247137689678794367049197824119717278923753940984084059450704378828123780678883777306239500480793044460796256306557893061457956479624163771194201
6
g = 2
7
8
bits = size(p)
9
10
with open("flag", "r") as f:
11
flag = f.readline().strip().encode("latin1")
12
m = bytes_to_long(flag)
13
14
def run(fin, fout):
15
alarm(1200)
16
try:
17
while True:
18
line = fin.readline()[:4+bits//4]
19
s = int(line, 16) # Note: input is HEX
20
c = pow(g, m ^ s, p)
21
fout.write(hex(c) + "\n")
22
fout.flush()
23
except:
24
pass
25
26
if __name__ == "__main__":
27
run(sys.stdin, sys.stdout)
28
29