-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCipher
More file actions
71 lines (56 loc) · 1.15 KB
/
Copy pathCipher
File metadata and controls
71 lines (56 loc) · 1.15 KB
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>
#include <math.h>
#include <stdlib.h>
int main() {
int N,K,i,j,k;
scanf("%d %d",&N,&K);
char a[N+K];
int b[N],c[N+K];
// printf("%d %d\n",N,K);
for(i=1;i<=N+K;i++)
scanf("%c",&a[i]);
for(i=2,k=0;a[i]!='\0';i++){
// printf("a%c ",a[i]);
if(a[i]=='0')
c[k++]=0;
else
c[k++]=1;
}
//for(i=0;i<N+K-1;i++)
// printf("%d",c[i]);
b[0]=c[0];
for(i=1;i<K;i++)
{
b[i]=(c[i]^c[i-1]);
}
for(i=K;i<N;i++)
b[i]=c[i]^c[i-1]^b[i-K]; //b[i] will become 1001010
//printf("\n");
for(i=0;i<N;i++)
printf("%d",b[i]);
return 0;
}
ex.
1 0 0 1 0 1 0
1 0 0 1 0 1 0
1 0 0 1 0 1 0
1 0 0 1 0 1 0
_____________________
1 1 1 0 1 0 0 1 1 0
b[0]=c[0]=1
here in the firt loop till K(XOR of c[i-1] and c[i])
b[1]=0
b[2]=0
b[3]=1
now in the second loop from K
1. XOR of c[i-1] and c[i] will give
b[4]=1
b[5]=1
b[6]=0
2. now we Xor it with b[i] i<K-1
i.e b[0]=1
b[1]=0
b[2]=0
so b[4] to b[6] becomes 110 xor 100 =010
so final b becomes 1001010