fix up prp generator, add another problem
This commit is contained in:
parent
90610332eb
commit
d4a1baf6a1
4 changed files with 14 additions and 12 deletions
|
@ -1 +0,0 @@
|
||||||
I found somebody's notes on their private RSA! Help me crack [this](${ciphertext_txt}).
|
|
1
rsa2/description.md
Normal file
1
rsa2/description.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Some more RSA! This time, there's no P and Q... [this](${ciphertext_txt}).
|
|
@ -1,6 +1,6 @@
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
flag = "wh3n_y0u_h4ve_p&q_RSA_iz_ez"
|
flag = "l0w_n"
|
||||||
|
|
||||||
def modx(base,exp,mod):
|
def modx(base,exp,mod):
|
||||||
r = 1;
|
r = 1;
|
||||||
|
@ -12,23 +12,25 @@ def modx(base,exp,mod):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def probprime(s):
|
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
|
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)
|
return(s)
|
||||||
|
|
||||||
def get_problem(random):
|
def get_problem(random):
|
||||||
# add Probable Prime function later
|
# add Probable Prime function later
|
||||||
p = probprime(random.randint(3*10**59,4*10**59))
|
p = probprime(random.randint(10**20,9*10**20))
|
||||||
q = probprime(random.randint(3*10**59,4*10**59))
|
q = probprime(random.randint(10**20,9*10**20))
|
||||||
e = 3
|
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)
|
return (p, q, e, salt)
|
||||||
|
|
||||||
def generate_ciphertext(random):
|
def generate_ciphertext(random):
|
||||||
p, q, e, salt = get_problem(random)
|
p, q, e, salt = get_problem(random)
|
||||||
encoded = int(("easyctf{%s_%s}" % (flag, salt)).encode('hex'),16)
|
encoded = int(("flag{%s_%s}" % (flag, salt)).encode('hex'),16)
|
||||||
ciphertext = 'p: '+str(p)+'\n'
|
ciphertext = 'n: '+str(p*q)+'\n'
|
||||||
ciphertext += 'q: '+str(q)+'\n'
|
|
||||||
ciphertext += 'e: '+str(e)+'\n'
|
ciphertext += 'e: '+str(e)+'\n'
|
||||||
ciphertext += 'c: '+str(pow(encoded, e, p*q))+'\n'
|
ciphertext += 'c: '+str(pow(encoded, e, p*q))+'\n'
|
||||||
|
|
||||||
|
@ -36,7 +38,7 @@ def generate_ciphertext(random):
|
||||||
|
|
||||||
def generate(random):
|
def generate(random):
|
||||||
return dict(files={
|
return dict(files={
|
||||||
"ciphertext_rsa1.txt": generate_ciphertext
|
"ciphertext_rsa2.txt": generate_ciphertext
|
||||||
})
|
})
|
||||||
|
|
||||||
def grade(random, key):
|
def grade(random, key):
|
|
@ -1,4 +1,4 @@
|
||||||
title: RSA 1
|
title: RSA 2
|
||||||
value: 25
|
value: 35
|
||||||
author: neptunia
|
author: neptunia
|
||||||
autogen: true
|
autogen: true
|
Loading…
Reference in a new issue