Skip to content

Instantly share code, notes, and snippets.

@ducnhse130201
Created May 2, 2018 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ducnhse130201/100198ce89d0920ca3c2ac3da4f4f20c to your computer and use it in GitHub Desktop.
Save ducnhse130201/100198ce89d0920ca3c2ac3da4f4f20c to your computer and use it in GitHub Desktop.
Crypto100-RSA(SVATTT-Quals-2017)
from libnum import *
to_int = lambda string : int(string,16)
n = 1552518092300708935148979488462502555256886017116696611139052038026050952686376886330878408828646477971459063658923221258297866648143023058142446317581796810373905913084934869211153276980011573717416472395713363686571638755823503877
BS = 32
p = 39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915641338868201294899
q = 39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915640806628012398823
phi = (p-1)*(q-1)
e = 3
d = modular.invmod(e,phi)
f = open('cipher.txt').read()
lst_c = f.split(' ')
c0 = to_int(lst_c[0])
print n2s(pow(c0,d,n))
for i in range(1,len(lst_c)):
c = pow(to_int(lst_c[i]),d,n)
c1 = int(hex(to_int(lst_c[i-1]))[2:-1][:BS*2+1], 16)
m = c - c1
print n2s(m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment