Is 3
Is 3
Input
"""
"""
import random
while b != 0:
a, b = b, a % b
return a
n=p*q
phi = (p - 1) * (q - 1)
e = random.randrange(1, phi)
# print("e=",e)
g = gcd(e, phi)
while g != 1:
e = random.randrange(1, phi)
g = gcd(e, phi)
d = multiplicative_inverse(e, phi)
x1 = 0
x2 = 1
y1 = 1
temp_phi = phi
while e > 0:
temp1 = temp_phi // e
temp_phi = e
e = temp2
x = x2 - temp1 * x1
y = d - temp1 * y1
x2 = x1
x1 = x
d = y1
y1 = y
if temp_phi == 1:
return d + phi
key, n = public_key
return cipher
return ''.join(plain)
print("Plaintext:", plaintext)
print("Ciphertext:", ciphertext)
output:
Ciphertext: [59, 337, 32, 337, 36, 118, 16, 325, 59, 87, 77, 36, 32, 118]