Skip to content

Instantly share code, notes, and snippets.

@elliptic-shiho
Created October 14, 2014 09:03
Show Gist options
  • Save elliptic-shiho/417ca82d46910c987d4f to your computer and use it in GitHub Desktop.
Save elliptic-shiho/417ca82d46910c987d4f to your computer and use it in GitHub Desktop.
RSA Encryption & Decryption
#!/usr/bin/python
import sys, struct, zlib
rsa_data = {}
text = int(sys.argv[1].encode("hex"), 16)
for x in open("id_rsa.private").readlines():
if len(x.split("=")) > 1:
rsa_data[x.split("=")[0].rstrip()] = long("".join(x.split("=")[1].split(":")), 16)
print pow(text, rsa_data["publicExponent"], rsa_data["modulus"])
#!/usr/bin/python
import sys, struct, zlib
rsa_data = {}
ciphertext = int(sys.argv[1])
for x in open("id_rsa.private").readlines():
if len(x.split("=")) > 1:
rsa_data[x.split("=")[0].rstrip()] = long("".join(x.split("=")[1].split(":")), 16)
print ("%x" % pow(ciphertext, rsa_data["privateExponent"], rsa_data["modulus"])).decode("hex")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment