-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto.c
60 lines (58 loc) · 851 Bytes
/
auto.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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void encrypt(char *a,char *key)
{
int i,l=strlen(a);
for(i=0;i<l;i++)
{
a[i]=((a[i]-65)+(key[i]-65)+26)%26;
}
for(i=0;i<l;i++){
a[i]=a[i]+65;
printf("%c",a[i]);
}
printf("\n");
}
void decrypt(char *a,char *key)
{
int i,l=strlen(a);
for(i=0;i<l;i++)
{
a[i]=((a[i]-65)-(key[i]-65)+26)%26;
}
for(i=0;i<l;i++){
a[i]=a[i]+65;
}
for(i=0;i<l;i++)
printf("%c",a[i]);
printf("\n");
}
void newkey(char *a,char *b,int key)
{
int i,j,l=strlen(a);
b[0]=65+key;
for(i=1,j=0;i<l;i++)
{
b[i]=a[j]-65;
j++;
}
for(i=1;i<l;i++){
b[i]=b[i]+65;
}
printf("key value is\n");
for(i=0;i<l;i++)
printf("%c",b[i]);
printf("\n");
}
void main(){
int key;
char a[100],b[100];
printf("enter the text");
gets(a);
printf("enter the key value\n");
scanf("%d",&key);
newkey(a,b,key);
encrypt(a,b);
decrypt(a,b);
}