-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaesarCipher.c
More file actions
70 lines (59 loc) · 962 Bytes
/
CaesarCipher.c
File metadata and controls
70 lines (59 loc) · 962 Bytes
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
#include<stdio.h>
#include<string.h>
char* encpt(char encpt_txt[])
{
int i, n;
char ch;
for(i=0;i<strlen(encpt_txt);i++)
{
n=encpt_txt[i];
n=n+3;
if(n>90)
{
n=n-90+64;
ch=n;
encpt_txt[i]=ch;
}
else
{
ch=n;
encpt_txt[i]=ch;
}
}
return encpt_txt;
}
char* decpt(char decpt_txt[])
{
int i, n;
char ch;
for(i=0;i<strlen(decpt_txt);i++)
{
n=decpt_txt[i];
n=n-3;
if(n<65)
{
n=91-(65-n);
ch=n;
decpt_txt[i]=ch;
}
else
{
ch=n;
decpt_txt[i]=ch;
}
}
return decpt_txt;
}
int main()
{
char input[500], encpt_txt[500], decpt_txt[500];
printf("Enter the text to be sent: \n");
scanf("%s", &input);
strcpy(encpt_txt,encpt(input));
printf("\nThe encrypted text is: \n");
printf("%s",encpt_txt);
strcpy(decpt_txt,decpt(encpt_txt));
printf("\n\nThe decrypted text is: \n");
printf("%s",decpt_txt);
return 0;
}