Skip to content

Instantly share code, notes, and snippets.

@minhtt159
Created August 30, 2018 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minhtt159/04af3804b877b0c4946f3606fc2f43db to your computer and use it in GitHub Desktop.
Save minhtt159/04af3804b877b0c4946f3606fc2f43db to your computer and use it in GitHub Desktop.
MeePwn CTF Final 2018 - Fake Prince
#!/usr/bin/env python2
from gmpy2 import powmod, is_prime
from flag import FLAG
import sys
from hashlib import sha256
from os import urandom
import sys
def write_to_file(num):
f = open('number.log', 'a+')
f.write('{}\n'.format(num))
pow = powmod
# -------------------------------------------------------------
strong_primes = [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,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293]
def rabmil(n):
if n & 1 == 0:
return False
else:
s, d = 0, n - 1
while d & 1 == 0:
s, d = s + 1, d >> 1
for a in strong_primes:
x = pow(a, d, n)
if x != 1 and x + 1 != n:
for r in range(1, s):
x = pow(x, 2, n)
if x == 1:
return False
elif x == n - 1:
a = 0
break
if a:
return False
return True
# -------------------------------------------------------------
def proof_of_shit():
"""
This function has very special purpose
:)) Simply to screw you up
"""
raw = urandom(6)
print 'prefix = {}'.format(raw.encode('hex'))
print('Challenge: ')
sys.stdout.flush()
challenge = sys.stdin.readline().strip()
temp = sha256(raw + challenge).hexdigest()
if temp.startswith('25455'):
return True
else:
return False
if __name__ == '__main__':
if proof_of_shit():
introduction = """
This time, the challenge is my redemption.
Have fun.! It just a warm up challenge.
"""
print introduction
try:
print ' p: ',
sys.stdout.flush()
num = int(sys.stdin.readline().strip())
write_to_file(num)
if rabmil(num) == True and is_prime(num) == False:
print '\n Congratz! I give you my thumb up if you solve this. \n'
print FLAG
else:
print "\n Try harder."
except:
print "Take your time to think of the inputs."
pass
sys.exit(0)
else:
print "Nah."
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment