easyctf-2017/paillier-service/grader.py

14 lines
1.1 KiB
Python

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."