-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfactorizeRSA.py
57 lines (47 loc) · 2.29 KB
/
factorizeRSA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
# -*- coding: utf8 -*-
import sys
import string
import urllib2
import urllib
import gmpy
def getpass(username):
# Prepare the data
query_args = { 'username': username }
# This urlencodes your data (that's why we need to import urllib at the top)
data = urllib.urlencode(query_args)
# Send HTTP POST request
url = 'http://103.10.24.99/13da382b97c306b7746bfa3681e006d7/register.php'
request = urllib2.Request(url, data)
response = urllib2.urlopen(request)
cookie = response.info()['set-cookie'][11:-8]
html = response.read()[697:]
return html, cookie
def str2int(mystr):
myhex = mystr.encode('hex')
myint = int(myhex, 16)
return myint
def str2intnew(mystr):
res = ''
for char in mystr:
res = res + str(ord(char))
return res
def str_int(s):
a=0
for i in range(0,len(s)):
a=a+ord(s[i])*256**i
return a
N = gmpy.mpz(1234567901234567901234567901234567901234567901234567901234567901234567901234567901234567901234567901234717283950617286419848309592787370341273747873748589842596504841720640394292494902982398728707626152070858561887866820294694355043665630787554216250435696249211077918492329836269203487802969283814463105539751494270071615655993342320948911726155780461076389165979343111846372150233530706650782398611627761941453287668879721303235540318234064753133821318150932201158894328482335388315649950679451828519628822971)
r = int(gmpy.ceil(gmpy.sqrt(N)))
p = gmpy.mpz(1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111178333333333334444487294872309872209128742098742420984723982734329843732987178261897634983473987323987439874932873402398720978429874230987340298723116269)
q = gmpy.mpz(1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111178333333333334444487294872309872209128742098742420984723982734329843732987178261897634983473987323987439874932873402398720978429874230987340298723109959)
e = 65537L
phi = (p-1)*(q-1)
d = gmpy.gcdext(e, phi)[1]
if d < 0:
d = d + phi
val = getpass('factor 1')
username = pow(gmpy.mpz(int(val[0])), e, N)
username = 418296719726
password = pow(gmpy.mpz(username), d, N)
print password