-
Notifications
You must be signed in to change notification settings - Fork 0
/
CaesarDecoder.c
126 lines (123 loc) · 1.96 KB
/
CaesarDecoder.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
/*
><><><><><><><><><><><><><><><><><><><><><><><><><><><
>
>
> Filename : CaesarDecoder.c
> Explanation : Decode caesar cipher
>
> Compiler : TDM-GCC 4.9.2 64-bit
>
> Developer : Emre Berber
> Other : emreberber.com
>
><><><><><><><><><><><><><><><><><><><><><><><><><><><
*/
#include <stdlib.h>
#include <stdio.h>
void Decoder(char array[] )
{
int i=0,counter=0,a;
for(a=0 ; a<25 ; a++)
{
i=0;
while(array[i] != '\0')
{
if(array[i]==32)
{
array[i]=32;
i++;
}
array[i]+=1;
if(array[i]==91)
{
array[i]=65;
}
if(array[i]==123)
{
array[i]=97;
}
i++;
}
printf("%s \n",array);
}
}
void Key(char array[] , int counter)
{
int i=0,a=1;
if(counter>26)
{
counter = counter % 26 ;
}
else if(counter<0)
{
if(counter<-26)
{
counter = -counter ;
counter = counter % 26 ;
}
else if(counter >-26)
{
counter = -counter ;
}
counter = 26 - counter ;
}
while(array[i]!='\0')
{
a=1;
if(array[i]==' ')
{
array[i]==' ';
i++;
}
if(array[i]>64 && array[i]<91)
{
while(a<=counter)
{
array[i]+=1;
if(array[i]==91)
{
array[i]=65;
}
a++;
}
i++;
}
else if(array[i]>96 && array[i]<123)
{
while(a<=counter)
{
array[i]+=1;
if(array[i]==123)
{
array[i]=97;
}
a++;
}
i++;
}
}
}
int main()
{
char array[50];
int key;
char b_or_k[1];
printf("Cipher Text : "); gets(array);
printf("Brute Force[b] or Key[k] ? :"); scanf("%c",&b_or_k[0]);
if(b_or_k[0] == 'b')
{
Decoder(array);
}
else if(b_or_k[0] == 'k')
{
printf("Key : "); scanf("%d",&key);
Key(array,key);
printf("Plain Text : %s \n\n",array);
}
else
{
printf("Error ! ");
}
system("PAUSE");
return 0;
}