Created
September 7, 2016 19:51
-
-
Save eenblam/298521aab139a88041a68e069832430b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import math | |
from Crypto.Util.number import * | |
import Crypto.PublicKey.RSA as RSA | |
with open('key1','r') as f1, open('key2', 'r') as f2: | |
# Short n | |
n1 = long(f1.readline().strip()) | |
# Long n | |
n2 = long(f2.readline().strip()) | |
#e = long(f2.readline().strip()) | |
e = long(65537) | |
rhs = ((n2 - n1 - 4) / 2) + 1 | |
f1 = n1 - rhs | |
f2 = n1 + rhs | |
d1 = inverse(e, f1) | |
d2 = inverse(e, f2) | |
rsa1 = RSA.construct((n1, e, d1)) | |
rsa2 = RSA.construct((n2, e, d2)) | |
with open('encrypted', 'r') as f, open('out', 'w') as out: | |
encrypted = long(f.read().strip()) | |
msg = rsa1.decrypt(rsa2.decrypt(encrypted)) | |
out.write(long_to_bytes(msg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment