-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRE.c
More file actions
60 lines (49 loc) · 1.25 KB
/
Copy pathRE.c
File metadata and controls
60 lines (49 loc) · 1.25 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFER_SIZE 100
char Destination[] = "abcdefghijklmnopqrstuvwxyz0123456789";
char Username[BUFFER_SIZE + 1];
char GeneratedPassword[BUFFER_SIZE + 1] = { 0 };
char UserPassword[BUFFER_SIZE + 1] = { 0 };
void inputUsername()
{
printf("Enter username\n");
fgets(Username, BUFFER_SIZE, stdin);
int usernameLength = strcspn(Username, "\n");
Username[usernameLength] = 0;
}
void inputPassword()
{
printf("Enter password\n");
fgets(UserPassword, BUFFER_SIZE, stdin);
int passwordLength = strcspn(UserPassword, "\n");
UserPassword[passwordLength] = 0;
}
void checkPassword(char* password1, char* password2)
{
if (strcmp(password1, password2))
printf("Wrong\n");
else
printf("Ace!\n");
}
int main()
{
int destIdx = 0;
inputUsername();
int usernameLength = strlen(Username);
if (usernameLength < 6)
return 0;
for (int i = 0; i < usernameLength; i++)
{
char currentChar = Username[i];
destIdx += currentChar;
destIdx %= 36;
GeneratedPassword[i] = Destination[destIdx];
}
int bufferLength = strlen(Username);
GeneratedPassword[bufferLength] = 0;
inputPassword();
checkPassword(UserPassword, GeneratedPassword);
return 0;
}