-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathceaser_cipher.c
More file actions
45 lines (42 loc) · 763 Bytes
/
Copy pathceaser_cipher.c
File metadata and controls
45 lines (42 loc) · 763 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
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
void main()
{
char plain[100],cipher[100],text[100];
int key,i,length;
int result;
printf("Enter PlainText :");
scanf("%s",&plain);
printf("\n Enter Key :");
scanf("%d",&key);
length=strlen(plain);
for(i=0;i<length;i++)
{
cipher[i]=plain[i] + key;
if (isupper(plain[i])&&(cipher[i] >'Z'))
{
cipher[i]=cipher[i] - 26;
}
if (islower(plain[i])&&(cipher[i] > 'z'))
{
cipher[i]=cipher[i] - 26;
}
}
printf("\nAfter Ecryption : %s",cipher);
for(i=0;i<length;i++)
{
text[i]=cipher[i]-key;
if (isupper(cipher[i])&&(text[i] < 'A'))
{
text[i]=text[i] - 26;
}
if (islower(cipher[i])&&(text[i] < 'a'))
{
text[i]=text[i] - 26;
}
}
printf("\nAfter Decryption : %s",text);
getch();
}