我试图生成一个包含10个字符密码的密码列表,其中只有3-6个数字和3-6大写字母的组合。
我看到选项-d,它允许单个字符的重复设置限制,但我正在寻找将其应用于整个字符类型/集的选项。
我不想产生10个字符组合,有少于3个数字或大写字母或超过6个数字或大写字母。
为澄清起见:
接受: HAA6A51GQI 1 JAK6195G1 8 Accepted 328
多余: ALQBZFT2GA 1652B547B6 ASH6UEWVH6
这可能是在紧缩或任何其他软件中实现的吗?
发布于 2019-05-08 19:53:22
我不知道如何在紧要关头做到这一点,但我只是为您编写了一个python脚本。
from random import shuffle, randint
from sys import argv
charset = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','8','9']
if __name__ == "__main__":
if len(argv) < 2:
print("Error: please use like this:\npython rand_pass.py <number_of_passwords>")
else:
num_pass = argv[1]
passes = []
counter = 0
while counter < int(num_pass):
num_chars = 0
num_nums = 0
passwd = ""
i = 0
while len(passwd) < 10:
c = charset[randint(0,len(charset)-1)]
if num_nums < 6 and c.isnumeric():
num_nums += 1
passwd += c
elif num_chars < 6 and not c.isnumeric():
num_chars += 1
passwd += c
i += 1
passes.append(passwd)
print(passwd)
counter += 1
用法:python file_name_gen_pass.py <number_of_pass_to_generate>
它将通过列表洗牌和追踪字符/名词的数量随机生成num_pass密码。您可以改进它,可能是为了减少假阳性,但是如果您只是在做一些基线蛮力测试,这应该足以向涉众证明您的观点。
编辑:为您编写了一个C++实现,以安抚每个人:)
#include <iostream>
#include <vector>
#include <random>
#include <string>
const char charset[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','8','9'};
int main()
{
std::cout << "Please enter the number of passwords to generate here: ";
int num_pass;
std::cin >> num_pass;
std::random_device dev;
std::mt19937_64 rng(dev());
std::vector<std::string> passwds;
std::uniform_int_distribution<std::mt19937_64::result_type> dist(0, sizeof(charset) - 1);
for (int i = 0; i < num_pass; ++i) {
std::string pass = "";
int num_nums = 0, num_chars = 0;
while (pass.length() < 10) {
char c = charset[dist(rng)];
if (isdigit(c) && num_nums < 6) {
pass += c;
num_nums++;
}
else if (isalpha(c) && num_chars < 6) {
pass += c;
num_chars++;
}
}
passwds.push_back(pass);
std::cout << pass << std::endl;
}
std::cin.get();
}
只要运行它,输入要生成的密码数量,它就会启动。对于少量的人来说,这是相当快的。只需按如下方式运行:gen_pass.exe > pass.txt
然后打开该文件,删除第一行并运行以下命令:awk '!seen[$0]++' script.py
https://security.stackexchange.com/questions/209775
复制相似问题