-
Notifications
You must be signed in to change notification settings - Fork 0
/
CumulativeEncoder.c
120 lines (113 loc) · 1.84 KB
/
CumulativeEncoder.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
/*
><><><><><><><><><><><><><><><><><><><><><><><><><><><
>
>
> Filename : CumulativeEncoder.c
> Explanation : Cumulative Cipher Encoder
>
> Compiler : TDM-GCC 4.9.2
>
> Developer : Emre Berber
> Other : emreberber.com
>
><><><><><><><><><><><><><><><><><><><><><><><><><><><
*/
#include <stdio.h>
#include <stdlib.h>
void Cumulative(char Array[] , char Cipher[] )
{
int sum = 0 , temp , i ;
if(Array[0]<91)
{
for(i=0 ; Array[i] != '\0' ; i++)
{
if(Array[i]==' ')
{
Cipher[i] = ' ' ;
}
else
{
sum += Array[i] - 64 ;
temp = sum / 3 ;
if(temp<1)
{
temp = sum ;
}
while(temp>26)
{
temp -= 26 ;
}
Cipher[i] = 64 + temp ;
}
}
}
else if(Array[0]>96)
{
for(i=0 ; Array[i] != '\0' ; i++)
{
if(Array[i]==' ')
{
Cipher[i] = ' ' ;
}
else
{
sum += Array[i] - 96 ;
temp = sum / 3 ;
if(temp<1)
{
temp = sum ;
}
while(temp>26)
{
temp -= 26 ;
}
Cipher[i] = 96 + temp ;
}
}
}
Cipher[i]='\0' ;
}
int main()
{
char Array[40];
char Cipher[40];
int param = 0 ,i ;
printf("Cumulative Encoder \n\n");
printf("Press String : "); gets(Array);
if(Array[0]<91)
{
for(i=0 ; Array[i] != '\0' ; i++)
{
if(Array[i]>90 && Array[i]!=32)
{
param = 1 ;
}
}
}
else if(Array[0]>96)
{
for(i=0 ; Array[i] != '\0' ; i++)
{
if(Array[i]<97 && Array[i]!=32)
{
param = 1 ;
}
}
}
Cumulative(Array,Cipher);
printf("Cipher Text : ");
if(param==0)
{
for(i=0 ; Cipher[i] != '\0' ; i++)
{
printf("%c",Cipher[i]);
}
}
else if(param==1)
{
printf("Error ! ");
}
printf("\n\n");
system("pause");
return 0;
}