Something horrible must have gone wrong in that last mission. As you wake in a holding cell, you realize that youre in the clutches of Professor Booleans numerous but relatively incompetent minions! Time to plan another escape.
Lucky for you nobody is around (do these security minions just sleep all the time?), so you have a chance to examine your cell. Looking around, you see no signs of surveillance (ha, they must underestimate you already) and the only thing keeping you contained is an electronic door lock. Should be easy enough.
You and Beta Rabbit worked together to exfiltrate some of Professor Booleans security information in anticipation of a moment just like this one. Time to put it to the test.
If memory serves, this locking mechanism relies on a horribly bad cryptographic hash, and you should be able to break it with some rudimentary calculations.
To open these doors, you will need to reverse engineer the hash function it is using. You already managed to steal the details of the algorithm used, and with some quiet observation of the guards you find out the results of the hash (the digest). Now to break it.
The function takes a 16 byte input and gives a 16 byte output. It uses
*), bit-wise exclusive OR (XOR) and modulo (%) to calculate
an element of the digest based on elements of the input message:
digest [i] = ( (129 * message[i]) XOR message[i-1]) % 256
For the first element, the value of message[-1] is 0.
For example, if message - 1 and message = 129, then: For digest: 129*message = 129 129 XOR message[-1] = 129 129 % 256 = 129 Thus digest = 129.
For digest: 129*message = 16641 16641 XOR message = 16640 16640 % 256 = 0 Thus digest = 0.
Write a function answer(digest) that takes an array of 16 integers and returns another array of 16 that correspond to the unique message that created this digest. Since each value is a single byte, the values are 0 to 255 for both message and digest.
Back to Foobar challenges