Skip to content

Instantly share code, notes, and snippets.

@trietptm
Created July 16, 2013 08:22
Show Gist options
  • Save trietptm/6006835 to your computer and use it in GitHub Desktop.
Save trietptm/6006835 to your computer and use it in GitHub Desktop.
Security Override - Programming Level 7 http://securityoverride.org/challenges/programming/7/index.php In order to complete Programming Challenge 7, you must code a script that will factor the number below into its prime factorization, and add those prime numbers together. Example: 42 -> 2, 3, 7 -> 12
import urllib2, re
import urllib
opener = urllib2.build_opener()
opener.addheaders.append(('cookie', 'fusion_visited=yes;PHPSESSID=myPHPSESSID;fusion_user=myfusion_user;__atuvc=my__atuvc'))
response = opener.open('http://securityoverride.org/challenges/programming/7/index.php','')
data = response.read()
regex = r"<code style='white-space:nowrap'>.*</code>"
result = re.search(regex, data, re.DOTALL)
result = result.group(0)
result = result.replace('\n', '')
result = result.replace('\t', '')
result = result.replace("<code style='white-space:nowrap'>", '')
result = result.replace('</code>', '')
print result
def prime_factors(x):
factor_list = []
loop = 2
while loop <= x:
if x % loop == 0:
x = x / loop
factor_list.append(loop)
else:
loop = loop + 1
return factor_list
number = int(result)
result = 0
factor_list = prime_factors(number)
for i in xrange(0, len(factor_list)):
result = result + factor_list[i]
print result
values = {'string':result,'submitbutton':'12 seconds to Submit',"CSRF_TOKEN":"<?php echo $_SESSION['CSRF_TOKEN'];?>"}
post_data = urllib.urlencode(values)
response = opener.open('http://securityoverride.org/challenges/programming/7/index.php', post_data)
file_handle = open('result.html', 'w')
while 1:
data = response.read()
if not data:
break
file_handle.write(data)
file_handle.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment