RSA1 with autogen, someone please test if the autogen works if possible

This commit is contained in:
neptunia 2017-03-04 17:52:26 -05:00
parent 956b004f27
commit 93d5f2479c
3 changed files with 51 additions and 0 deletions

1
RSA1/description.md Normal file
View file

@ -0,0 +1 @@
I found somebody's notes on their private RSA! Help me crack [this](${ciphertext_txt}).

46
RSA1/grader.py Normal file
View file

@ -0,0 +1,46 @@
from cStringIO import StringIO
flag = "wh3n_y0u_h4ve_p&q_RSA_iz_ez"
def modx(base,exp,mod):
r = 1;
while (exp > 0):
if (exp % 2 == 1):
r = (r * base) % mod
base = (base * base) % mod
exp = exp/2
return r
def probprime(s):
while (modx(2,s-1,s) != 1 or modx(3,s-1,s) != 1 or modx(5,s-1,s) != 1 or modx(7,s-1,s) != 1):
s += 1
return(s)
def get_problem(random):
# add Probable Prime function later
p = probprime(random.randint(10**39,9*10**39))
q = probprime(random.randint(10**39,9*10**39))
e = 3
salt = "".join([random.choice("0123456789abcdef") for i in range(8)])
return (p, q, e, salt)
def generate_ciphertext(random):
p, q, e, salt = get_problem(random)
encoded = int(("easyctf{%s_%s}" % (flag, salt)).encode('hex'),16)
ciphertext = 'p: '+str(p)+'\n'
ciphertext += 'q: '+str(q)+'\n'
ciphertext += 'e: '+str(e)+'\n'
ciphertext += 'c: '+str(pow(encoded, e, p*q))+'\n'
return StringIO(ciphertext)
def generate(random):
return dict(files={
"ciphertext_rsa1.txt": generate_ciphertext
})
def grade(random, key):
n, salt = get_problem(random)
if key.find("%s_%s" % (flag, salt)) >= 0:
return True, "Correct!"
return False, "Nope."

4
RSA1/problem.yml Normal file
View file

@ -0,0 +1,4 @@
title: RSA 1
value: 25
author: neptunia
autogen: true