Skip to content

Instantly share code, notes, and snippets.

@zhouyunao
Last active May 15, 2018 08:36
Show Gist options
  • Save zhouyunao/e48caaa71bbfba845f815d7712478d27 to your computer and use it in GitHub Desktop.
Save zhouyunao/e48caaa71bbfba845f815d7712478d27 to your computer and use it in GitHub Desktop.
uncle-sam
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