Last active
May 15, 2018 08:36
-
-
Save zhouyunao/e48caaa71bbfba845f815d7712478d27 to your computer and use it in GitHub Desktop.
uncle-sam
This file contains 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
def generate_key(k): | |
p,q = getPrime(k),getPrime(k) | |
pubkey = p**2*q | |
l = (p-1)*(q-1) / gcd(p-1,q-1) | |
privkey = inverse(pubkey,l) | |
return pubkey,privkey | |
def encrypt(m,pubkey): | |
return pow(bytes_to_long(m),pubkey,pubkey) | |
def decrypt(m,privkey,pubkey): | |
return pow(m,privkey,pubkey) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment