forked from Praman1997/De-Code-v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
De-Code.cpp
205 lines (201 loc) · 4.4 KB
/
De-Code.cpp
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
/*
Author: Praman Kasliwal
Licence: Free(Open Source)
Note from Author:
Oh! So you really looked into the source code?! Wow!!! I mean you really are Geek...
Well what can I really do?...
*horribly singing*
What can I say, except, your Welcome?! I'm just an ordinary human guy...
*stopping after hearing my own voice* *clears throat*
Bon Chance!!! Au revoir!!!
Enjoy!
*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<dos.h>
#include<time.h>
void pinc();
int delay(unsigned long milisec)
{
struct timespec req={0};
time_t sec=(int)(milisec/1000);
milisec=milisec-(sec*1000);
req.tv_sec=sec;
req.tv_nsec=milisec*1000000L;
while(nanosleep(&req,&req)==-1)
continue;
return 1;
}
void fpage()
{
system("cls");
system("COLOR 0C");
for (int i =0; i<110;i++)
printf("_");
printf("\n\t\t\t\tWELCOME TO"); delay(1000);
system("COLOR 0B");
printf(" De-CODE\n");delay(1000);
system("COLOR 09");
printf("\t\t\t\t\tCODE ");delay(1000);
printf("TO ");delay(1000);
printf("MYSTERY..."); delay(1000);
system("COLOR 0F");
printf("\n\nDisclaimer: This software is created for the purpose of secured messages to be transfered from one user to another.");
printf(" In case of any difficulties faced or a bad memory, contact the Developers"); delay(2000);
printf("\n\n\n\n Press any key to continue...");getch();
}
// coding of encipher***********************************************
void encipher()
{
system("cls");
int a, b, d[1002];
FILE *p;
char str[1002];
system("COLOR F2");
printf("\t\t\t\t~~~Enciphering~~~\n");
printf("Type in your Message and press Enter to terminate\n");
gets(str);
fflush(stdin);
printf("Please wait while Enciphering");delay(1000);
printf(".");delay(1000);
printf(".");delay(1000);printf(".\n");delay(1000);
// converting every alphabet into number*******************************
a = 1;
for (int s=0;s<strlen(str);s++)
{
if(str[s]==' ')
{
a = 1;
continue;
}
b = 26 * a;
d[s] = str[s]+b;
d[s] -= 96;
a++;
}
printf("Code Generated:\n");delay(1000);
for (int s=0;s<strlen(str);s++)
{ if(str[s]!=' ')
{
printf("%d ",d[s]);
}
}
// making new file and storing *****************************
p = fopen("ciphered.txt","w");
for (int s=0;s<strlen(str);s++)
fprintf(p,"%d\n",d[s]);
fclose(p);
}
void decipher(int c)
{
int a, b, g[1002];
char m[10002];
FILE *p;
p = fopen("CIPHERED.txt","r");
printf("Please wait while Deciphering");delay(1000);
printf(".");delay(1000);
printf(".");delay(1000);
printf(".\n");delay(1000);
printf("Code Retrieved: ");
for (int s=0;s<c;s++)
{
fscanf(p,"%d\n", &a);
if (a>2000||a<26)
{
printf("");
continue;
}
printf("%d ",a);
b = a % 26;
g[s] = a;
m[s]=96+b;
}
fclose(p);
delay(1000);
printf("\nDeciphered Message: \n--> ");
for (int s=0;s<c;s++)
{
if (g[s]<g[s-1])
printf(" %c",m[s]);
else
printf("%c",m[s]);
}
}
void demain()
{
system("cls");
system("COLOR 20");
int a,n=0,b=0;
FILE *p;
p = fopen("CIPHERED.txt","r");
while ((n=fgetc(p)) != EOF)
{
if (n == '\n')
b++;
}
printf("\t\t\t\t~~~Deciphering~~~\n");
fclose(p);
if (b == 0)
{
system("cls");
system("COLOR 4F");
printf("\tError 404:\n\t\tFile not found or may be present by different name.");delay(2000);
printf("\n\t\tIn case of neither, contact the developers.");delay(6000);
pinc();
}
else
decipher(b);
}
void pinc()
{
int a;
m: system("cls");
system("COLOR F4");
printf("Select from the following: \n 1) To Encipher\n 2) To Decipher\n Your Selection: ");
scanf("%d",&a);
fflush(stdin);
if (a==1)
encipher();
else if (a==2)
demain();
else
{
printf("Incorrect Selection!");
fflush(stdin);
getch();
goto m;
}
}
int main()
{
system("TITLE De-CODE: Code to Mystery");
fpage();
s: system("cls");
int a;
char pin[4];
printf("Enter PIN: ");
for(int i =0;i<4;i++)
{
pin[i]=getch();
printf("*");
}
if (pin[0]=='2'&&pin[1]=='3'&&pin[2]=='2'&&pin[3]=='8')
{
pinc();
}
else
{
printf("\nIncorrect PIN!");
getch();
goto s;
}
getch();
system("cls");
system("COLOR 70");
printf("\n\t\t\tCredits\n\t\t\t--------\n");delay(1000);
printf("\t\tCreated By: \n\t\t\tPraman Kasliwal");
delay(3000);
return 0;
}