import random
import string
length = random.randint(8,13)
password = string.ascii_letters + string.digits + string.punctuation
gen_password = "".join(random.sample(password, length))
print(password)
print(length)
print(gen_password)
最近我开始涉足破译领域,主要是学习加密和解密算法以及相关流程。在破解密码时,密码字典是一个非常关键的步骤。下面是一个关于密码生成器的Python代码示例。我们将使用Python的string和random库函数来实现:
import random
import math
alpha = "abcdefghijklmnopqrstuvwxyz"
num = "0123456789"
special = ".@#$%&*"
#pass_len = int(input("Enter Password Length: "))
pass_len=random.randint(8,13)
# length of password 5:3:2
alpha_len = pass_len//2
num_len = math.ceil(pass_len*30/100)
special_len = pass_len-(alpha_len+num_len)
password = []
def generate_pass(length, array, is_alpha=False):
for i in range(length):
index = random.randint(0, len(array) - 1)
character = array[index]
if is_alpha:
case = random.randint(0, 1)
if case == 1:
character = character.upper()
password.append(character)
generate_pass(alpha_len, alpha, True)
generate_pass(num_len, num)
generate_pass(special_len, special)
random.shuffle(password)
# convert List To string
gen_password = ""
for i in password:
gen_password = gen_password + str(i)
print(pass_len)
print(password)
print(gen_password)