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
|
import random
lower="abcdefghijklmnopqrstuvwxyz"
upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
symbols="!%@#^,./?*;:_"
number="0123456789"
def getstr(legth,str1):
tmp=""
for i in range(legth):
tmp = tmp + random.choice(str1)
return tmp
def getpwd(pwd,key,legth,havesymbol):
passworld=""
random.seed(pwd+key)
if(havesymbol):
passworld = getstr(1,upper)+getstr(1,lower)+getstr(1,number)+getstr(1,symbols)
for i in range(legth-4):
switch=random.randint(0,3)
if(switch==0):
passworld += getstr(1,upper)
elif(switch==1):
passworld += getstr(1,lower)
elif(switch==2):
passworld += getstr(1,number)
else:
passworld += getstr(1,symbols)
else:
passworld = getstr(1,upper)+getstr(1,lower)+getstr(1,number)
for i in range(legth-3):
switch=random.randint(0,2)
if(switch==0):
passworld += getstr(1,upper)
elif(switch==1):
passworld += getstr(1,lower)
else:
passworld += getstr(1,number)
return passworld
pwd=input("请输入公匙:")
while(True):
key=input("请输入关键字(或输入 exit 退出):")
if(key!="exit"):
print("密码为: "+ getpwd(pwd,key,12,True))
else:
break
|