-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROT13Cipher.c
69 lines (59 loc) · 938 Bytes
/
ROT13Cipher.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
#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+13;
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-13;
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 plaintext: \n");
scanf("%s", &input);
strcpy(encpt_txt,encpt(input));
printf("\nEncrypted text: \n");
printf("%s",encpt_txt);
strcpy(decpt_txt,decpt(encpt_txt));
printf("\n\nDecrypted text: \n");
printf("%s",decpt_txt);
return 0;
}