From d4a1baf6a1a6d4e426849fc945c032e50bf491b6 Mon Sep 17 00:00:00 2001 From: neptunia Date: Sun, 5 Mar 2017 11:36:31 -0500 Subject: [PATCH] fix up prp generator, add another problem --- RSA1/description.md | 1 - rsa2/description.md | 1 + {RSA1 => rsa2}/grader.py | 20 +++++++++++--------- {RSA1 => rsa2}/problem.yml | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) delete mode 100644 RSA1/description.md create mode 100644 rsa2/description.md rename {RSA1 => rsa2}/grader.py (60%) rename {RSA1 => rsa2}/problem.yml (53%) diff --git a/RSA1/description.md b/RSA1/description.md deleted file mode 100644 index d44c07b..0000000 --- a/RSA1/description.md +++ /dev/null @@ -1 +0,0 @@ -I found somebody's notes on their private RSA! Help me crack [this](${ciphertext_txt}). \ No newline at end of file diff --git a/rsa2/description.md b/rsa2/description.md new file mode 100644 index 0000000..d5802d9 --- /dev/null +++ b/rsa2/description.md @@ -0,0 +1 @@ +Some more RSA! This time, there's no P and Q... [this](${ciphertext_txt}). \ No newline at end of file diff --git a/RSA1/grader.py b/rsa2/grader.py similarity index 60% rename from RSA1/grader.py rename to rsa2/grader.py index 9d5b790..bca12b2 100644 --- a/RSA1/grader.py +++ b/rsa2/grader.py @@ -1,6 +1,6 @@ from cStringIO import StringIO -flag = "wh3n_y0u_h4ve_p&q_RSA_iz_ez" +flag = "l0w_n" def modx(base,exp,mod): r = 1; @@ -12,23 +12,25 @@ def modx(base,exp,mod): 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): + if s%2==0: s += 1 + smolprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97] + while len(set([modx(i,s-1,s) for i in smolprimes])) != 1 or modx(2,s-1,s) != 1: + s+=2 return(s) def get_problem(random): # add Probable Prime function later - p = probprime(random.randint(3*10**59,4*10**59)) - q = probprime(random.randint(3*10**59,4*10**59)) + p = probprime(random.randint(10**20,9*10**20)) + q = probprime(random.randint(10**20,9*10**20)) e = 3 - salt = "".join([random.choice("0123456789abcdef") for i in range(8)]) + salt = "".join([random.choice("0123456789abcdef") for i in range(4)]) 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' + encoded = int(("flag{%s_%s}" % (flag, salt)).encode('hex'),16) + ciphertext = 'n: '+str(p*q)+'\n' ciphertext += 'e: '+str(e)+'\n' ciphertext += 'c: '+str(pow(encoded, e, p*q))+'\n' @@ -36,7 +38,7 @@ def generate_ciphertext(random): def generate(random): return dict(files={ - "ciphertext_rsa1.txt": generate_ciphertext + "ciphertext_rsa2.txt": generate_ciphertext }) def grade(random, key): diff --git a/RSA1/problem.yml b/rsa2/problem.yml similarity index 53% rename from RSA1/problem.yml rename to rsa2/problem.yml index e46b8d2..210bc96 100644 --- a/RSA1/problem.yml +++ b/rsa2/problem.yml @@ -1,4 +1,4 @@ -title: RSA 1 -value: 25 +title: RSA 2 +value: 35 author: neptunia autogen: true \ No newline at end of file