Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ashutosh1206
GitHub Repository: ashutosh1206/crypton
Path: blob/master/RSA-encryption/Attack-Common-Modulus/Challenges/RSA-1s-Fun/encrypt.py
1402 views
1
from Crypto.Util.number import *
2
3
e1 = 9
4
e2 = 123
5
6
def prime_gen():
7
while True:
8
p = getPrime(1024)
9
q = getPrime(1024)
10
n = p*q
11
phin = (p-1)*(q-1)
12
if GCD(e1, phin) == 1 and GCD(e2, phin) == 1:
13
return (p, q, n)
14
p, q, n = prime_gen()
15
16
print "p: ", p
17
print "q: ", q
18
print "n: ", n
19
20
flag = bytes_to_long(open("flag.txt").read().strip())
21
assert flag < n
22
assert flag**9 > n
23
24
c1 = pow(flag, e1, n)
25
c2 = pow(flag, e2, n)
26
27
print "c1: ", c1
28
print "c2: ", c2
29
30