Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ashutosh1206
GitHub Repository: ashutosh1206/crypton
Path: blob/master/RSA-encryption/Intro-Challenges/Meth_M4th/encrypt.py
1402 views
1
from Crypto.Util.number import *
2
from Crypto.PublicKey import RSA
3
import gmpy2
4
from secret import flag
5
6
p = getPrime(512)
7
q = getPrime(512)
8
n = p*q
9
phin = (p-1)*(q-1)
10
11
s = p*(n-p-q+1)
12
e = 65537
13
assert GCD(e, phin) == 1
14
d = inverse(e, phin)
15
16
message = bytes_to_long(flag)
17
ciphertext = pow(message, e, n)
18
ciphertext = long_to_bytes(ciphertext)
19
ciphertext = ciphertext.encode("hex")
20
21
obj1 = open("data.txt",'w')
22
write_data = "[1] Ciphertext: " + ciphertext + "\n" + "[2] Modulus: " + str(n) + "\n" + "[3] Public Key exponent: " + str(e) + "\n" + "[4] s: " + str(s)
23
obj1.write(write_data)
24
obj1.close()
25