Skip to content

Instantly share code, notes, and snippets.

@cbscribe
Last active May 27, 2021 03:14
Show Gist options
  • Save cbscribe/a161a78f45b0c189ad9aa9fa8dacc49e to your computer and use it in GitHub Desktop.
Save cbscribe/a161a78f45b0c189ad9aa9fa8dacc49e to your computer and use it in GitHub Desktop.
Manually decrypt text RSA-style, given "N" and "D".
ciphertext = input("Ciphertext: ")
m = int(input("m: "))
d = int(input("D: "))
num_digits = len(str(m))
cleartext = ""
print("Decrypting (may take a while)...")
for i in range(0, len(ciphertext), num_digits):
num = int(ciphertext[i:i+num_digits])
cleartext += chr((num ** d) % m)
print()
print(cleartext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment