-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.c
71 lines (71 loc) · 869 Bytes
/
product.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
70
71
#include<stdio.h>
#include<string.h>
#define N 4
void encrypt(char *a,int key[N])
{
int l=strlen(a),i;
for(i=0;i<l/2;i++)
{
a[i]=a[i]^key[i];
}
}
void decrypt(char *a,int key[N])
{
int l=strlen(a),i;
for(i=0;i<l/2;i++)
{
a[i]=a[i]^key[i];
}
}
void swap(char *a)
{
int i;
char temp;
for(i=0;i<N;i++)
{
temp=a[i];
a[i]=a[i+4];
a[i+4]=temp;
}
}
void main()
{
srand(time(0));
int i,key1[10],key2[10];
char a[100];
printf("enter plain text\n");
gets(a);
for(i=0;i<4;i++)
{
key1[i]=rand()%10;
}
for(i=0;i<N;i++)
{
printf("%d",key1[i]);
}
printf("\n");
encrypt(a,key1);
printf("%s\n",a);
swap(a);
printf("%s",a);
printf("\n");
for(i=0;i<4;i++)
{
key2[i]=rand()%10;
}
for(i=0;i<N;i++)
{
printf("%d",key2[i]);
}
printf("\n");
encrypt(a,key2);
printf("%s",a);
printf("\n");
decrypt(a,key2);
printf("%s",a);
printf("\n");
swap(a);
decrypt(a,key1);
printf("%s",a);
printf("\n");
}