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..222805a --- /dev/null +++ b/rsa1/grader.py @@ -0,0 +1,49 @@ +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): + 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**79,4*10**79)) + q = probprime(random.randint(3*10**79,4*10**79)) + 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..0015feb --- /dev/null +++ b/rsa1/problem.yml @@ -0,0 +1,7 @@ +title: RSA 1 +author: neptunia +hint: Go google RSA if you're stuck. +category: Cryptography +autogen: true +programming: false +value: 25 \ No newline at end of file diff --git a/rsa2/problem.yml b/rsa2/problem.yml index 210bc96..e9fb2d1 100644 --- a/rsa2/problem.yml +++ b/rsa2/problem.yml @@ -1,4 +1,7 @@ title: RSA 2 -value: 35 author: neptunia -autogen: true \ No newline at end of file +hint: It's like RSA 1 but harder. Have fun! +category: Cryptography +autogen: true +programming: false +value: 35 \ No newline at end of file