-
Notifications
You must be signed in to change notification settings - Fork 2
/
cipher.cpp
59 lines (45 loc) · 972 Bytes
/
cipher.cpp
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 <cstdio>
#include <iostream>
#include <string>
using namespace std;
string message;
int length, cycles;
string decrypt;
const int MAXL = 24;
int oneBit[MAXL];
/*void print(){
for(int x = length-1;x>=0;x--){
if(decrypt&(1<<x)) cout << 1;
else cout << 0;
}
cout << endl;
}
int convert(string in){
int ret = 0;
for(int x = 0;x<in.length();x++){
if(in[in.length()-1-x]=='1') ret += (1<<x);
}
return ret;
}
void setup(){
oneBit[0] = 1;
for(int x = 1;x<MAXL;x++) oneBit[x] = (oneBit[x-1] << 1);
}*/
int main(){
cin >> length >> cycles >> message;
decrypt = message[0];
//print();
bool curDigit = (decrypt[0] == '1');
for(int x = 1;x<length;x++){
//if(decrypt[x-1]=='1') curDigit = !curDigit;
if(x-cycles>=0&&decrypt[x-cycles]=='1') curDigit = !curDigit;
bool nextDigit = (message[x]=='1');
if(curDigit!=nextDigit){
decrypt+='1';
curDigit = !curDigit;
}
else decrypt+='0';
//print();
}
cout << decrypt << endl;
}