-
Notifications
You must be signed in to change notification settings - Fork 1
/
final.c
338 lines (285 loc) · 11.5 KB
/
final.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum status { Pass, Fail };
int CrackThePassword(char pwd[])
{
int c = 1;
for (int i = 0; i < 7; i++)
{
if (pwd[i] == pwd[6 - i])
{
c = 1;
}
else
{
c = 0;
}
}
return c;
}
void clrscr()
{
system("@cls||clear");
}
int main()
{
enum status GameStatus = Pass;
int id;
char pwd[7], username[20];
clrscr();
printf("\n -----------------------------------Welcome to Treasure Hunt!!!----------------------------------- \n");
printf("\nRules : \n\n1. You have to retreive keys by solving variety to puzzles to proceed to further levels.\n");
printf("\n2. You will be given only three chances in each level to correcly determine and submit the keys. \n");
printf("\n3. If you complete all three levels only then you will win.\n");
printf("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Best Of Luck!!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n");
printf("\nLevel 01 : Crack the password!\n");
printf("\nA Palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward");
printf(", such as racecar or 123454321 etc. \nThe word Palindrome was introduced by Henry Peachman in 1638. It is derived from the");
printf("Greek roots. The ancient Greek poet Sotades(3rd century BCE)\ninvented a form of ionic meter called as Sotadic or ");
printf("Sotadean verse, which is sometimes said to have been palindromic, but no exapmles survive,\nand the exact nature of");
printf("'reverse' readings is unclear.\n");
printf("\nEnter the user id (Institute Roll Number) : ");
scanf("%d", &id);
printf("\nEnter the username : ");
scanf("%s", username);
printf("\nEnter the password (it's 7 characters long) : ");
scanf("%s", pwd);
int count = 0;
while (count < 3)
{
if (CrackThePassword(pwd) == 1)
{
printf("\nVoila!!! You are on fire... Proceed to next level..\n");
GameStatus = Pass;
break;
}
else
{
printf("\nYou got %d tries left.", 2 - count);
if (count != 2)
{
printf(" Give it another go : ");
scanf("%s", pwd);
}
else
{
printf(" Better Luck next time!!!");
GameStatus = Fail;
break;
}
}
count++;
}
count = 0;
//LEVEL 2
if (GameStatus == Pass)
{
clrscr();
char keyone[20] = "three";
char key[12];
// Game starts (round 1)
printf("\n Level 02 : Hangman \nRound 1\n");
printf(" +---+\n");
printf(" | |\n");
printf(" O |\n | Clue:twelve = six\n | six = three\n | ten = ?\n");
printf("Enter key here:");
scanf("%s", key);
if (strcmp(key, keyone) == 0)
{
printf("**************************\n");
printf("congrats!! You cracked this treasure!!\nPress enter for round 2\n");
printf("**************************\n");
getchar();
}
else
{
clrscr();
printf(" +---+\n");
printf(" | |\n");
printf(" O |\n /|\\ | Clue:twelve = six\n | six = three\n | ten = ? \n");
printf("(Wrong ! Try again)\n");
if (strcmp(key, "five") == 0)
printf("We don't make it this much easy for you :)\n");
printf("Enter key here:");
scanf("%s", key);
if (strcmp(key, keyone) == 0)
{
printf("**************************\n");
printf("congrats!! You cracked this treasure!!\nPress enter for round 2\n");
printf("**************************\n");
getchar();
}
else
{
clrscr();
printf(" +---+\n");
printf(" | |\n");
printf(" O |\n /|\\ | Clue:twelve = six\n / | six = three\n | ten = ? \n");
printf("(***Again Wrong key! This is your last chance)\nEnter key here:");
scanf("%s", key);
if (strcmp(key, keyone) == 0)
{
printf("**************************\n");
printf("congrats!! You cracked this treasure!!\nPress enter for round 2\n");
printf("**************************\n");
getchar();
}
else
{
clrscr();
printf(" +---+\n");
printf(" | |\n");
printf(" O |\n /|\\ | \n / \\ |\n | \n");
printf("**************************\n");
printf("Sorry!! You failed this hunt\n");
printf("**************************\n");
GameStatus = Fail;
}
}
}
//Round 2
if (strcmp(key, keyone) == 0) // this condition checks whether round 1 is won or not
{
clrscr();
printf("Round2\n");
printf(" +---+\n");
printf(" | |\n");
printf(" O |\n | Clue: You are the key to crack this treasure!!\n |\n |\n");
printf("Enter key here:");
scanf("%s", key);
if (strcmp(key, username) == 0)
{
printf("**************************\n");
printf("congrats!! You cracked this treasure!!\n");
printf("**************************\n");
GameStatus = Pass;
}
else
{
clrscr();
printf(" +---+\n");
printf(" | |\n");
printf(" O |\n /|\\ | Clue: You are key to crack this treasure!!\n |\n | \n");
printf("(Wrong ! Try again)\nClue2: Its all started with you and will end with you\n");
printf("Enter key here:");
scanf("%s", key);
if (strcmp(key, username) == 0)
{
printf("**************************\n");
printf("congrats!! You cracked this treasure!!\n");
printf("**************************\n");
GameStatus = Pass;
}
else
{
clrscr();
printf(" +---+\n");
printf(" | |\n");
printf(" O |\n /|\\ | Clue: You are key to crack this treasure!!\n / |\n | \n");
printf("(***Again Wrong key! This is your last chance)\nClue3:Think of from where you started this hunt\nEnter key here:");
scanf("%s", key);
if (strcmp(key, username) == 0)
{
printf("**************************\n");
printf("congrats!! You cracked this treasure!!\n");
printf("**************************\n");
GameStatus = Pass;
}
else
{
clrscr();
printf(" +---+\n");
printf(" | |\n");
printf(" O |\n /|\\ | \n / \\ |\n | \n");
printf("**************************\n");
printf("Sorry!! You failed this hunt\n");
printf("**************************\n");
GameStatus = Fail;
}
}
}
}
getchar();
if (GameStatus == Pass)
{
clrscr();
char word[7] = "success", cipher[7] = "", answer[7] = "";
printf("\n -------------LAST LEVEL------------- \n");
printf("\nCryptography is a method of protecting information and communications through the use of codes, so that only those \nfor whom the information is intended can read and process it.");
printf(" Some of the methods of cryptography include Caesar Cipher, \nPolyalphabetic Cipher and One Time Pad.");
/* Ciphering the word "success", getting the pseudorandom numbers with seed = 7 and increasing the ascii values of
respective alphabets by the displayed pseudorandom numbers, is the final ascii value > 122, the remainder will be added
to 96 (this is done so that there are no special characters in the cipher text */
srand(7);
for (int i = 0; i <= 6; i++)
{
int num = rand() % 26 + 1;
int ascii = word[i];
ascii = ascii + num;
if (ascii > 122)
{
ascii = ascii % 122 + 96;
}
char c = ascii;
cipher[i] = c;
}
printf("\n\nNow, what you have to do is to crack this encrypted code : %s\nKEY : 7\n\n", cipher);
printf("We will give you the data, all you have to do is give us the seed, but remember, \nyou will only get 5 chances!\n\n");
int count2 = 5;
while (count2 != 0)
{
int choice = 0;
printf("Chances remaining : %d\n\n", count2);
printf("Want us to display the data? Enter 1 if yes, any other number if no : ");
scanf("%d", &choice);
count2--;
if (choice == 1)
{
int seed = 0;
printf("Enter the seed to get data : ");
scanf("%d", &seed);
srand(seed);
printf("Data : ");
for (int i = 0; i <= 9; i++)
{
int num1 = rand() % 26 + 1;
printf("%d ", num1);
}
printf("\n");
}
printf("Enter the answer : ");
scanf("%s", answer);
//If the input answer matches the word "success", the loop will terminate, else it will continue until the given 5 chances are over
if (strcmp(answer, "success") == 0)
{
break;
}
else
{
printf("Oh, oh, wrong answer :(");
}
printf("\n\n");
}
if (strcmp(answer, "success") == 0)
{
printf("\nWell done!! You have achieved %s in cracking the code!\n", cipher);
GameStatus = Pass;
}
else
{
printf("Sorry :( you lost the game!\n");
GameStatus = Fail;
}
}
else
{
printf("Game Over!!");
}
}
else
{
printf("Game Over!!");
}
return 0;
}