From 0a31b38383c87de972e4bed142fed182b4443f49 Mon Sep 17 00:00:00 2001 From: neptunia Date: Tue, 15 Nov 2016 19:47:06 -0500 Subject: [PATCH] added a problem, but someone has to get my program running on a server --- paillier-service/description.md | 3 +++ paillier-service/encrypt.py | 17 +++++++++++++++++ paillier-service/grader.py | 14 ++++++++++++++ paillier-service/problem.yml | 8 ++++++++ 4 files changed, 42 insertions(+) create mode 100644 paillier-service/description.md create mode 100644 paillier-service/encrypt.py create mode 100644 paillier-service/grader.py create mode 100644 paillier-service/problem.yml diff --git a/paillier-service/description.md b/paillier-service/description.md new file mode 100644 index 0000000..159bd5b --- /dev/null +++ b/paillier-service/description.md @@ -0,0 +1,3 @@ +My friend made some sort of encryption service using the Paillier Cryptosystem. Can you get him to encrypt the string `easyctf{3ncrypt_m3!}` for me? + +Access his encryption serice at `memes.com:1234` <- fix this later \ No newline at end of file diff --git a/paillier-service/encrypt.py b/paillier-service/encrypt.py new file mode 100644 index 0000000..81c2a9d --- /dev/null +++ b/paillier-service/encrypt.py @@ -0,0 +1,17 @@ +#easyctf{3ncrypt_m3!} +p = 8144194198641127053467521063088973929365485175581336279930490759203400725623086153929294542350943040473375790841894343662879542882143670576484983482676929 +q = 9349990237178389195581522619084514015305492951423232071317276234453300521753669715890246992825146527366147991960266180184131002960074501683578205688324193 +n = p*q +l = (p-1)*(q-1) +g = n+1 +mu = 50461441817124067084598541006218828107720370909059246792962232658242869571003990015294541684702084151173329882441771747115542549562899610400402036968340066285127945127930744036805832623326255171902722383305695091973581469008587730106329093915495096858331002656658189454919392650001488548518482449865519307486 +m = int(raw_input('Enter a message to encrypt: ')) +r = int(raw_input('Enter r (int): ')) +if m > 100000000000000000 or m < 0: + print('Bad m. We only take m from 0 to 100000000000000000.') + exit() +if r > 100000000000000000 or r < 0: + print('Bad r. We only take r from 0 to 100000000000000000.') + exit() +c = (pow(g,m,n**2)*pow(r,n,n**2))%(n**2) +print 'c: '+str(c) diff --git a/paillier-service/grader.py b/paillier-service/grader.py new file mode 100644 index 0000000..eccfd3e --- /dev/null +++ b/paillier-service/grader.py @@ -0,0 +1,14 @@ +def grade(autogen, answer): + try: + answer = int(answer) + p = 8144194198641127053467521063088973929365485175581336279930490759203400725623086153929294542350943040473375790841894343662879542882143670576484983482676929 + q = 9349990237178389195581522619084514015305492951423232071317276234453300521753669715890246992825146527366147991960266180184131002960074501683578205688324193 + n = p*q + l = (p-1)*(q-1) + g = n+1 + mu = 50461441817124067084598541006218828107720370909059246792962232658242869571003990015294541684702084151173329882441771747115542549562899610400402036968340066285127945127930744036805832623326255171902722383305695091973581469008587730106329093915495096858331002656658189454919392650001488548518482449865519307486 + if ((pow(answer,l,n**2)-1)//n * mu)%n == 578781299356711768839252397261103878073419506045: + return True, "Correct!" + return False, "Nope, try again." + except: + return False, "Nope, try again." diff --git a/paillier-service/problem.yml b/paillier-service/problem.yml new file mode 100644 index 0000000..f2f440e --- /dev/null +++ b/paillier-service/problem.yml @@ -0,0 +1,8 @@ +title: Paillier Service +author: neptunia +hint: https://en.wikipedia.org/wiki/Paillier_cryptosystem +category: Cryptography +autogen: false +programming: false +value: 400 + \ No newline at end of file