-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prac4.c
36 lines (36 loc) · 803 Bytes
/
Prac4.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
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
void main()
{
char pt[100], key[100], table[26][26], c[100];
int i = 0, j = 0, val;
printf("Enter Plain text:");
gets(pt);
printf("Enter Key:");
gets(key);
for (i = 0, j = 0; pt[i] != NULL; i++, j++)
{
if (j >= strlen(key))
{
j = 0;
}
c[i] = 65 + (((toupper(pt[i]) - 65) + (toupper(key[j]) - 65)) % 26);
}
puts(c);
for (i = 0, j = 0; c[i] != NULL; i++, j++)
{
if (j >= strlen(key))
{
j = 0;
}
val = (c[i] - toupper(key[j]));
if (val < 0)
{
val = val + 26;
}
printf("%c", 65 + (val % 26));
}
getch();
}