|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdlib.h> |
| 3 | +#include <time.h> |
| 4 | + |
| 5 | +/** |
| 6 | + * f4 - finds the biggest number |
| 7 | + * @usrn: username |
| 8 | + * @len: length of username |
| 9 | + * Return: the biggest number |
| 10 | + */ |
| 11 | +int f4(char *usrn, int len) |
| 12 | +{ |
| 13 | + int ch; |
| 14 | + int vch; |
| 15 | + unsigned int rand_num; |
| 16 | + |
| 17 | + ch = *usrn; |
| 18 | + vch = 0; |
| 19 | + |
| 20 | + while (vch < len) |
| 21 | + { |
| 22 | + if (ch < usrn[vch]) |
| 23 | + ch = usrn[vch]; |
| 24 | + vch += 1; |
| 25 | + } |
| 26 | + |
| 27 | + srand(ch ^ 14); |
| 28 | + rand_num = rand(); |
| 29 | + |
| 30 | + return (rand_num & 63); |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * f5 - multiplies each char of username |
| 35 | + * @usrn: username |
| 36 | + * @len: length of username |
| 37 | + * Return: multiplied char |
| 38 | + */ |
| 39 | +int f5(char *usrn, int len) |
| 40 | +{ |
| 41 | + int ch; |
| 42 | + int vch; |
| 43 | + |
| 44 | + ch = vch = 0; |
| 45 | + |
| 46 | + while (vch < len) |
| 47 | + { |
| 48 | + ch = ch + usrn[vch] * usrn[vch]; |
| 49 | + vch += 1; |
| 50 | + } |
| 51 | + |
| 52 | + return (((unsigned int)ch ^ 239) & 63); |
| 53 | +} |
| 54 | + |
| 55 | +/** |
| 56 | + * f6 - generates a random char |
| 57 | + * @usrn: username |
| 58 | + * Return: a random char |
| 59 | + */ |
| 60 | +int f6(char *usrn) |
| 61 | +{ |
| 62 | + int ch; |
| 63 | + int vch; |
| 64 | + |
| 65 | + ch = vch = 0; |
| 66 | + |
| 67 | + while (vch < *usrn) |
| 68 | + { |
| 69 | + ch = rand(); |
| 70 | + vch += 1; |
| 71 | + } |
| 72 | + |
| 73 | + return (((unsigned int)ch ^ 229) & 63); |
| 74 | +} |
| 75 | + |
| 76 | +/** |
| 77 | + * main - Entry point |
| 78 | + * @argc: arguments count |
| 79 | + * @argv: arguments vector |
| 80 | + * Return: Always 0 |
| 81 | + */ |
| 82 | +int main(int argc, char **argv) |
| 83 | +{ |
| 84 | + char keygen[7]; |
| 85 | + int len, ch, vch; |
| 86 | + long alph[] = { |
| 87 | + 0x3877445248432d41, 0x42394530534e6c37, 0x4d6e706762695432, |
| 88 | + 0x74767a5835737956, 0x2b554c59634a474f, 0x71786636576a6d34, |
| 89 | + 0x723161513346655a, 0x6b756f494b646850 }; |
| 90 | + (void) argc; |
| 91 | + |
| 92 | + for (len = 0; argv[1][len]; len++) |
| 93 | + ; |
| 94 | + /* ----------- f1 ----------- */ |
| 95 | + keygen[0] = ((char *)alph)[(len ^ 59) & 63]; |
| 96 | + /* ----------- f2 ----------- */ |
| 97 | + ch = vch = 0; |
| 98 | + while (vch < len) |
| 99 | + { |
| 100 | + ch = ch + argv[1][vch]; |
| 101 | + vch = vch + 1; |
| 102 | + } |
| 103 | + keygen[1] = ((char *)alph)[(ch ^ 79) & 63]; |
| 104 | + /* ----------- f3 ----------- */ |
| 105 | + ch = 1; |
| 106 | + vch = 0; |
| 107 | + while (vch < len) |
| 108 | + { |
| 109 | + ch = argv[1][vch] * ch; |
| 110 | + vch = vch + 1; |
| 111 | + } |
| 112 | + keygen[2] = ((char *)alph)[(ch ^ 85) & 63]; |
| 113 | + /* ----------- f4 ----------- */ |
| 114 | + keygen[3] = ((char *)alph)[f4(argv[1], len)]; |
| 115 | + /* ----------- f5 ----------- */ |
| 116 | + keygen[4] = ((char *)alph)[f5(argv[1], len)]; |
| 117 | + /* ----------- f6 ----------- */ |
| 118 | + keygen[5] = ((char *)alph)[f6(argv[1])]; |
| 119 | + keygen[6] = '\0'; |
| 120 | + for (ch = 0; keygen[ch]; ch++) |
| 121 | + printf("%c", keygen[ch]); |
| 122 | + return (0); |
| 123 | +} |
0 commit comments