Now we have to decode the message. We know that . The first digit in so our output string is going to start with . The next two digits are also , so they must have been XORed with . We know the first digit of our shifted string is a as well. Since the digit of is , we XOR that with our and now know there is a in the position of the original string. Continue with that logic until the end.
Then the encoded message and the key are sent to Daniel.
Jack is using this encoding algorithm and asks Daniel to implement a decoding algorithm.
Can you help Daniel implement this?
Complete the cipher function in the editor below. It should return the decoded string.
cipher has the following parameter(s):
k: an integer that represents the number of times the string is shifted
s: an encoded string of binary digits
The first line contains two integers and , the length of the original decoded string and the number of shifts.
The second line contains the encoded string consisting of ones and zeros.
It is guaranteed that is valid.
Return the decoded message of length , consisting of ones and zeros.