如何用C语言编一个密码生成器
发布网友
发布时间:2022-04-23 00:13
我来回答
共3个回答
热心网友
时间:2023-07-02 19:02
C语言实现密码生成器,参考代码如下:
#include
#include
#include
//const char lower_chars[] = "abcdefghijklmnopqrstuvwxyz";
//const char upper_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//const char number_chars[] = "01234567";
const char lower_chars[] = "abcdefghijkmnpqrstuvwxyz"; // no l or o
const char upper_chars[] = "ABCDEFGHJKLMNPQRSTUVWXYZ"; // no I or O
const char number_chars[] = "234567"; // no 1 or 0
const char special_chars[] = "!@#$%^&*()-=_+[]{};:'\"<>,.?/";
const int _ks_pass_len = 17;
void mkpass(char pass[_ks_pass_len+1])
{
int i = 0, j = 0, k = 0,n = 0;
n = _ks_pass_len/4;
for (; i < n; i++)
{
pass[i] = lower_chars[rand()%(strlen(lower_chars))];
pass[i+n] = upper_chars[rand()%(strlen(upper_chars))];
pass[i+2*n] = number_chars[rand()%(strlen(number_chars))];
pass[i+3*n] = special_chars[rand()%(strlen(special_chars))];
}
j = _ks_pass_len - 4*n;
for (i = 0; i<j; i++) {
pass[i+4*n] = special_chars[rand()%(strlen(special_chars))];
}
//字符乱序
for (i = 0; i < 32; i++)
{
j = rand()%(_ks_pass_len);
k = pass[j];
pass[j] = pass[i%_ks_pass_len];
pass[i%_ks_pass_len] = k;
}
pass[_ks_pass_len] = '\0';
}
int _tmain(int argc, _TCHAR* argv[])
{
srand(time(0));
char szPass[_ks_pass_len+1];
for (int i=0; i<16; i++)
{
mkpass(szPass);
printf("%s\n",szPass);
}
return 0;
}<j; i++)
热心网友
时间:2023-07-02 19:02
这个问题很好解决哦! 先定义一个数组(16位),数组初始化为0, 然后将你输入的字符存入数组! 根据你输入的元素设计一个简单算法! 输出结果就行啊!追问可是我对代码不专业,能不能帮忙写一下呢
热心网友
时间:2023-07-02 19:03
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int n; scanf("%d", &n);
srand(n);
printf("%03d%03d%03d", rand() % 1000, rand() % 1000, rand() % 1000);
return 0;
}