-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path103-keygen.c
127 lines (112 loc) · 2.08 KB
/
103-keygen.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/**
* f4 - finds the biggest number
*
* @usrn: username
* @len: length of username
* Return: the biggest number
*/
int f4(char *usrn, int len)
{
int ch;
int vch;
unsigned int rand_num;
ch = *usrn;
vch = 0;
while (vch < len)
{
if (ch < usrn[vch])
ch = usrn[vch];
vch += 1;
}
srand(ch ^ 14);
rand_num = rand();
return (rand_num & 63);
}
/**
* f5 - multiplies each char of username
*
* @usrn: username
* @len: length of username
* Return: multiplied char
*/
int f5(char *usrn, int len)
{
int ch;
int vch;
ch = vch = 0;
while (vch < len)
{
ch = ch + usrn[vch] * usrn[vch];
vch += 1;
}
return (((unsigned int)ch ^ 239) & 63);
}
/**
* f6 - generates a random char
*
* @usrn: username
* Return: a random char
*/
int f6(char *usrn)
{
int ch;
int vch;
ch = vch = 0;
while (vch < *usrn)
{
ch = rand();
vch += 1;
}
return (((unsigned int)ch ^ 229) & 63);
}
/**
* main - Entry point
*
* @argc: arguments count
* @argv: arguments vector
* Return: Always 0
*/
int main(int argc, char **argv)
{
char keygen[7];
int len, ch, vch;
long alph[] = {
0x3877445248432d41, 0x42394530534e6c37, 0x4d6e706762695432,
0x74767a5835737956, 0x2b554c59634a474f, 0x71786636576a6d34,
0x723161513346655a, 0x6b756f494b646850 };
(void) argc;
for (len = 0; argv[1][len]; len++)
;
/* ----------- f1 ----------- */
keygen[0] = ((char *)alph)[(len ^ 59) & 63];
/* ----------- f2 ----------- */
ch = vch = 0;
while (vch < len)
{
ch = ch + argv[1][vch];
vch = vch + 1;
}
keygen[1] = ((char *)alph)[(ch ^ 79) & 63];
/* ----------- f3 ----------- */
ch = 1;
vch = 0;
while (vch < len)
{
ch = argv[1][vch] * ch;
vch = vch + 1;
}
keygen[2] = ((char *)alph)[(ch ^ 85) & 63];
/* ----------- f4 ----------- */
keygen[3] = ((char *)alph)[f4(argv[1], len)];
/* ----------- f5 ----------- */
keygen[4] = ((char *)alph)[f5(argv[1], len)];
/* ----------- f6 ----------- */
keygen[5] = ((char *)alph)[f6(argv[1])];
keygen[6] = '\0';
for (ch = 0; keygen[ch]; ch++)
printf("%c", keygen[ch]);
return (0);
}