-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeygenMe - 01.c
166 lines (136 loc) · 3.99 KB
/
keygenMe - 01.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
hi guys, there is a simple Keygen Me
Just try harder to generate a good serial
code.
:) Good luck
*/
#include <stdio.h>
#include <stdlib.h>
#define MAX_USER_NAME 100
#define MAX_KEY_LENGTH MAX_USER_NAME
#define BUFFER_SIZE 128
#define COUNT 10
char *getEncrytKey(const char *uName);
int _strlen(const char *string); // calcul automatiquement la longueur d'une chaine
void clearBuffer(char *buffer); // here we cleaning the buffer
void ExitWithError(const char *message);
void tryToKeygenMe(int count); // this function are called if the user select opt 2
void printTitle(void); // main title
int _strcmpKey(const char *string1, const char *string2); // return 1 if the two strings are equals and 0 else
void printRules(void); // rules of this challenge
int main(void)
{
printTitle();
int choice;
printf("(1) - rules \n");
printf("(2) - start Training \n");
printf(" Select an option : ");
scanf("%d", &choice);
// start switching ...
switch (choice)
{
case 1:
printRules();
break;
case 2:
tryToKeygenMe(COUNT);
break;
default:
printf("Please do a correct choice ! \n");
break;
}
system("pause");
return 0;
}
void tryToKeygenMe(int count){
char uName[MAX_USER_NAME],
serialKey[MAX_KEY_LENGTH],
buffer[BUFFER_SIZE];
// the username must be 4 caracters minimum
do{
printf(" Enter Your Username (4 chars at min) : "); // ask the user name
scanf("%s", uName);
clearBuffer(buffer);
}while(_strlen(uName) < 4);
do{
count--;
printf(" Password : ");
scanf("%s", serialKey);
clearBuffer(buffer);
if(_strcmpKey(serialKey, getEncrytKey(uName)))
printf("Good Password ! \n");
else
{
printf("-> (%d / %d)\n", (COUNT-count), COUNT);
printf("Wrong password for the username \"%s\": ! Try again ... \n", uName);
}
if(count == 0)
printf("Just try at the next time. GoodBye :) \n");
} while (count>0);
printf("\n");
}
void printTitle(void){
puts("\t*****************************");
puts("\t* *");
puts("\t* KEYGEN ME *");
puts("\t* By @Danofred *");
puts("\t* Powered by crackmes.one *");
puts("\t* Difficulty : 3.0 *");
puts("\t*****************************\n");
}
int _strcmpKey(const char *string1, const char *string2)
{
int is_equals = 1; // there two trings are equals as default
int n = _strlen(string1),
m = _strlen(string2);
if(n == m){
for(int i=0; i < n; i++){
if(string1[i] != string2[i]){
is_equals = 0;
return is_equals;
}
}
}else is_equals=0;
return is_equals;
}
char *getEncrytKey(const char *uName)
{
char *key = "tryHarderToMakeAGoodKeyGen";
int l = _strlen(key),
n = _strlen(uName);
char *goodSerial = (char *)malloc(sizeof(char) * n);
if(goodSerial == NULL)
ExitWithError("Erreur d'allocation dynamique");
for(int i=0, j=0; i<n; i++){
j = ((int)uName[i] ^ l) % n;
goodSerial[i] = uName[j];
}
return goodSerial;
}
void ExitWithError(const char *message)
{
fprintf(stderr, "%s \n", message);
exit(EXIT_FAILURE);
}
void clearBuffer(char *buffer)
{
int i=0;
while((buffer[i] = getchar()) != '\n'){
i++;
}
}
int _strlen(const char *string)
{
int size = 0;
for(int i=0; string[i] != '\0'; i++)
size++;
return size;
}
void printRules(void)
{
puts("Hi cracker and welcome on this keygenme maked by @Danofred\n");
puts("RULES :");
puts("\t- Don't patch this program");
puts("\t- Try to make a keygen");
puts("\n\t\t:) Good Luck");
}