-
-
Save quandqn/5d7fa41d479e8e752c0bbf9935d1f18c to your computer and use it in GitHub Desktop.
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
from Crypto.Util.number import * | |
import random | |
from flag import FLAG | |
def generate(nbits): | |
p = getPrime(nbits) | |
q = getPrime(nbits) | |
n = p * q * p | |
g = random.randint(1, n) | |
h = pow(g, n, n) | |
return (n, g, h) | |
def encrypt(m, n, g, h): | |
r = random.randint(1, n) | |
c = pow(pow(g, m, n) * pow(h, r, n), 1, n) | |
return c | |
m = [ord(char) for char in FLAG] | |
n, g, h = generate(90) | |
open("pubkey.txt", "w").write("{0}:{1}:{2}".format(n, g, h)) | |
c = [encrypt(mi, n, g, h) for mi in m] | |
open("enc.txt", "w").write(str(c)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment