-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed password
86 lines (64 loc) · 1.81 KB
/
seed password
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
// C program for the above approach
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int N;
// Function to randomly generates password
// of length N
void randomPasswordGeneration(int N)
{
// Initialize counter
int i = 0;
int seed=0;
int randomizer;
// Seed the random-number generator
// with current time so that the
// numbers will be different every time
printf("put lenth to your password");
scanf("%d",&N);
printf("put seed");
scanf("\n%d",&seed);
srand(seed);
// Array of numbers
char numbers[] = "0123456789";
// Array of small alphabets
char letter[] = "abcdefghijklmnoqprstuvwyzx";
// Array of capital alphabets
char LETTER[] = "ABCDEFGHIJKLMNOQPRSTUYWVZX";
// Array of all the special symbols
char symbols[] = "!@#$^&*?";
// Stores the random password
char password[N];
// To select the randomizer
// inside the loop
// Iterate over the range [0, N]
for (i = 0; i < N; i++) {
if (randomizer == 1) {
password[i] = numbers[rand() % 10];
randomizer = rand() % 4;
printf("%c", password[i]);
}
else if (randomizer == 2) {
password[i] = symbols[rand() % 8];
randomizer = rand() % 4;
printf("%c", password[i]);
}
else if (randomizer == 3) {
password[i] = LETTER[rand() % 26];
randomizer = rand() % 4;
printf("%c", password[i]);
}
else {
password[i] = letter[rand() % 26];
randomizer = rand() % 4;
printf("%c", password[i]);
}
}//end for loop
}
// Driver Code
int main()
{
// Function Call
randomPasswordGeneration(N);
return 0;
}