-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.py
More file actions
188 lines (175 loc) · 4.72 KB
/
sol.py
File metadata and controls
188 lines (175 loc) · 4.72 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import sys
sys.path.append('..')
import dataoper
import randtext
import re
import hashlib
helpstr='''
This is a program which can product random password.
Please input 'a,b(,c)(,d)'
a means website.
b means username.
c means format.Deafult is 2.
d means length.Deafult is 12.
input form to find the form.
'''
formstr='''
1 means number
2 means lowercase and number
3 means lowercase and uppercase and number and symbol
4 means lowercase and uppercase
5 means lowercase and uppercase and number
6 means uppercase and number
'''
def has_dev(str):
hashh = hashlib.md5()
hashh.update(bytes(str,encoding='utf-8'))
return hashh.hexdigest()
def form_dev(str,fo):
ans = ""
cha = ""
must = ""
char = ""
if fo[0]>'0' and fo[0] <= '9':
if fo == '1':
for i in range(10):
cha += chr(ord('0')+i)
elif fo == '2':
for i in range(10):
cha += chr(ord('0')+i)
for i in range(26):
cha += chr(ord('a')+i)
must = "a0"
elif fo == '3':
for i in range(10):
cha += chr(ord('0')+i)
for i in range(26):
cha += chr(ord('a')+i)
cha += chr(ord('A')+i)
must = "a0.A"
char = "!@#$%^&*(),.[]"
cha += char
elif fo == '4':
for i in range(26):
cha += chr(ord('a')+i)
cha += chr(ord('A')+i)
must = 'Aa'
elif fo == '5':
for i in range(26):
cha += chr(ord('a')+i)
cha += chr(ord('A')+i)
for i in range(10):
cha += chr(ord('0')+i)
must = 'A0a'
elif fo == '6':
for i in range(10):
cha += chr(ord('0')+i)
for i in range(26):
cha += chr(ord('A')+i)
must = "A0"
else:
for i in range(10):
cha += chr(ord('0')+i)
for i in range(26):
cha += chr(ord('a')+i)
else:
for i in range(len(fo)):
if fo[i] == '0':
for j in range(10):
cha += chr(ord('0')+j)
elif fo[i] == 'a':
for j in range(26):
cha += chr(ord('a')+j)
elif fo[i] == 'A':
for j in range(26):
cha += chr(ord('A')+j)
else:
cha += fo[i]
char += fo[i]
str = int(str,16)
for i in range(len(must)):
if must[i] == '0':
ans += chr(ord('0')+(str%256)%10)
elif must[i] == 'a':
ans += chr(ord('a')+(str%256)%10)
elif must[i] == 'A':
ans += chr(ord('A')+(str%256)%10)
else:
ans+= char[(str%256)%len(char)]
str //= 256
while str > 0:
ans += cha[(str%256)%len(cha)]
str //= 256
return ans
def pan(str):
if len(str) == 1:
if str[0]>='0' and str[0]<='9':
return True
else :
return False
else:
se = set()
for i in range(len(str)):
if str[i] in se:
return False
if((str[i]>'0' and str[i]<='9') or (str[i]>'A' and str[i]<='Z') or
(str[i]>'a' and str[i]<='z')):
return False
se.add(str[i])
return True
def solve(chaid,str='help',pas=''):
if str == "help":
return helpstr
if str == 'form':
return formstr
res=dataoper.find_table(chaid)
if res=="None":
dataoper.insert_table(chaid,randtext.get_randtext())
res=dataoper.find_table(chaid)
lis = re.split(r',',str)
if len(lis) < 2:
return "invalid input!"
has = has_dev(lis[0]+lis[1]+res)
if len(lis) < 3:
lis.append('2')
if len(lis) < 4:
lis.append(12)
try:
lis[3] = int(lis[3])
except:
return "invalid input!"
if pan(lis[2]) == False:
return "invalid input!"
if pas!= '':
has = pas
ans = form_dev(has,lis[2])
tm = ans
while len(ans) < lis[3]:
tm = has_dev(tm)
ans += tm
return form_dev(has,lis[2])[:lis[3]]
'''
if __name__ == "__main__":
print(helpstr)
inp = input()
usr = 'a'
a = solve(usr,inp)
# print('______')
# dataoper.display_table()
print(a)
res = dataoper.find_table(usr)
fr = open(devdata.pos,'r+')
fp = open(devdata.pos,'a+')
lis = fr.readlines()
flag = False
# print(len(lis))
for i in lis:
if i == res+'\n':
# print(i)
flag = True
break
if flag == False:
fp.write(res+'\n')
fr.close()
fp.close()
'''