From 93d5f2479c5f37094bfa5df957c59fce77276088 Mon Sep 17 00:00:00 2001 From: neptunia Date: Sat, 4 Mar 2017 17:52:26 -0500 Subject: [PATCH] RSA1 with autogen, someone please test if the autogen works if possible --- RSA1/description.md | 1 + RSA1/grader.py | 46 +++++++++++++++++++++++++++++++++++++++++++++ RSA1/problem.yml | 4 ++++ 3 files changed, 51 insertions(+) create mode 100644 RSA1/description.md create mode 100644 RSA1/grader.py create mode 100644 RSA1/problem.yml diff --git a/RSA1/description.md b/RSA1/description.md new file mode 100644 index 0000000..d44c07b --- /dev/null +++ b/RSA1/description.md @@ -0,0 +1 @@ +I found somebody's notes on their private RSA! Help me crack [this](${ciphertext_txt}). \ No newline at end of file diff --git a/RSA1/grader.py b/RSA1/grader.py new file mode 100644 index 0000000..e03de4a --- /dev/null +++ b/RSA1/grader.py @@ -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." diff --git a/RSA1/problem.yml b/RSA1/problem.yml new file mode 100644 index 0000000..e46b8d2 --- /dev/null +++ b/RSA1/problem.yml @@ -0,0 +1,4 @@ +title: RSA 1 +value: 25 +author: neptunia +autogen: true \ No newline at end of file