Skip to content

Instantly share code, notes, and snippets.

@samueltangz
Created November 27, 2018 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samueltangz/2867fb88eef8d431fcdb21f64e2d923f to your computer and use it in GitHub Desktop.
Save samueltangz/2867fb88eef8d431fcdb21f64e2d923f to your computer and use it in GitHub Desktop.
|-------------------------------------|
| Options: |
| [C]ipher text |
| [E]ncryption function |
| [M]akekey function |
| [P]ubkey |
| [S]end decrypted message |
| [Q]uit |
|-------------------------------------|
$ C
enc = 10904516867469635139255759541454954169488892141616940550266307864409136719019115859114980590682020444990229017090013633370290350759569451239505458406461585916557735769790323235850244371212514502957484816450064988838206110183270650494899323423108401359578487861390809505613047635198904827419553757598009323337405714351726869977868247626399243151801564878019302562765796428884109103303888748017954983775573524461151382337966669151466740475811624386320872144427999542468553044347305230873376392264344174163962169733258615584184267021902711932590260911188333344449164340590734944180995458533547921903342027319344928206773
$ E
def encrypt(m, pubkey):
m = bytes_to_long(m)
e, n = pubkey
assert m < n
while True:
r = random.randint(1, n - 1)
if gcd(r, n) == 1:
c = (pow(r, e, n**2) * (r**2 + m*n)) % n ** 2
break
return c
$ M
def makekey(nbit):
D = getRandomRange(1, nbit**3)
p = gmpy.next_prime(fprime + D)
q = getPrime(nbit)
pubkey = (0x10001, int(p*q))
return pubkey
$ P
pubkey = (65537, 147634621206546655912071607153021322529961741409736056141229382725401558262591776081574840839992973276729736761478777971404160649739550489097303755015155535602273712461897029108955022566822368668347960262091923319475704875360907551550478716929914483834063232200518033814387633649416527534210286558740943638781L)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment