-
Notifications
You must be signed in to change notification settings - Fork 5
/
pp2k.py
executable file
·165 lines (126 loc) · 3.51 KB
/
pp2k.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python
import hashlib
import random
import os, sys, time
from optparse import OptionParser
from subprocess import *
def hashf1(i, strh):
i = i%10
if i == 0:
return hashlib.sha1(strh).hexdigest()
elif i == 1:
return hashlib.sha224(strh).hexdigest()
elif i == 2:
return hashlib.sha256(strh).hexdigest()
elif i == 3:
return hashlib.sha384(strh).hexdigest()
elif i == 4:
return hashlib.sha512(strh).hexdigest()
elif i == 5:
h = hashlib.new("ripemd160")
h.update(strh)
return h.hexdigest()
elif i == 6:
h = hashlib.new("dss1")
h.update(strh)
return h.hexdigest()
elif i == 6:
h = hashlib.new("mdc2")
h.update(strh)
return h.hexdigest()
elif i == 7:
return hashlib.md5(strh).hexdigest()
elif i == 8:
h = hashlib.new("md4")
h.update(strh)
return h.hexdigest()
elif i == 9:
return hashlib.sha256(hashlib.sha512(strh).hexdigest()).hexdigest()
def hashf2(i, strh):
return len64(hashf1(i, strh))
def len64(string):
l = len(string)
if l == 32:
string = string[12:32] + string + string[0:12]
elif l == 40:
string = hashlib.sha1(string).hexdigest()[12:36] + string
elif l == 56:
string = hashlib.sha256(string).hexdigest()[25:33] + string
elif l == 64:
string = string[35:48] + string[1:27] + string[29:31] + string[0] + string[31:35] + string[27:29] + string[48:64]
elif l == 96:
string = string[3:27] + string[40:80]
elif l == 128:
string = string[45:82] + string[90:113] + string[3:7]
return string
def pat(hlist, slist, rand):
if rand == -1:
p = random.randrange(0, 700, 1)
else:
p = rand
if p < 700:
mot1 = ""
for i in range(7):
mot1 = mot1 + hashf2(int(p/10)%10, hashf2(hlist[i], slist[i]))
if i == int(p/100):
mot1 = mot1 + hashf2(int(p/10)%10, hashf2(hlist[i], slist[i]))
mot1 = hashf2(p%10, mot1)
for i in range(128):
mot1 = hashf2(i, mot1)
ret = hashf2(p%10, mot1)
return [p, ret]
def main():
parser = OptionParser(usage="%prog [options]", version="%prog 1.0")
parser.add_option("--passphrase", dest="pp",
help="passphrase")
parser.add_option("--code", dest="code",
help="code")
parser.add_option("--keynumber", dest="keynumber",
help="keynumber")
parser.add_option("--size", dest="size",
help="number of displayed keys",
default="10")
parser.add_option("-p", "--pwpath", dest="pwpath",
help="pywallet.py directory (default = ./)",
default="./")
(options, args) = parser.parse_args()
passphrase = options.pp
slist = []
for i in range(7):
slist.append(random.randrange(0, 10, 1))
if options.code is not None:
code = options.code
for i in range(0, 11-len(code)):
code = "0" + code
rand = int(code[0:4])
for i in range(7):
slist[i] = int(code[i+4])
else:
rand = random.randrange(0, 700)
for j in range(int(options.size)):
if options.keynumber is not None:
j = int(options.keynumber)
print("Key %d"%j)
passphrase = options.pp + "%d"%(j)
lm = passphrase.split(" ")
nm = len(lm)
if nm < 7 or len(passphrase) < 40:
print("Passphrase MUST be at least 7 words and 40 characters long")
exit(0)
for i in range(7, nm):
lm[i%7]=lm[i%7]+lm[i]
lm = lm[0:7]
result = pat(slist, lm, rand)
code = "%.4d"%result[0]
seckey = result[1]
for i in range(7):
code = code + "%d"%slist[i]
print("Code: " + code)
print("Secrkey: " + seckey)
a=Popen(options.pwpath + "pywallet.py --info --importhex --importprivkey " + seckey, shell=True, bufsize=-1, stdout=PIPE).stdout
print(a.read())
a.close()
if options.keynumber is not None:
break
if __name__ == '__main__':
main()