Skip to content

Instantly share code, notes, and snippets.

p, q, e = 17, 23, 5
n = p * q
phi = (p - 1) * (q - 1)
d = pow(e, -1, phi)
P = "TranTanQuan"
cipher = [pow(ord(ch), e, n) for ch in P]
decrypted = "".join(chr(pow(c, d, n)) for c in cipher)
plaintext = "tran tan quan"
key = 12
alphabet = "abcdefghijklmnopqrstuvwxyz"
ciphertext = ""
for i in plaintext:
if i in alphabet:
j = alphabet.index(i)
kq = (j + key) % 26
ciphertext += alphabet[kq]