Internet Problem Solving Contest

Problem L – Lame crypto

Bob wants to draw tons of .png images (http://www.w3.org/TR/PNG/) and send them to Alice. He does not want anyone else to see those pictures. Therefore, he designed the Super Secret Protocol (SSP) and he uses it to communicate with Alice.

Eve wants to destroy their relationship. She bribed their internet providers to slow down their internet so that she could get access to their communication. Now, every message between Bob and Alice travels so slow that Eve can hold it for up to several hours. She has also drawn an evil image, which she wants to deliver to Alice in Bob’s name. Then Alice will break up with Bob for sure (well, with 95 percent confidence).

Unfortunately (for Eve), Eve knows exactly nothing about cryptography. Therefore, she hired IPSC organizers to take care of it. And as they were just preparing this contest, they decided to kill two birds with one stone – and let you do the dirty work for them. The evil images (one for each subproblem, see below) are provided in the respective input files.

SSP protocol specification

Alice has a secret key KA, Bob has a secret key KB. When Bob wants to send a message M of length n to Alice, the following happens:

1. Bob chooses some (contiguous) subsequence KB of size n of key KB. He sends M KB to Alice.
2. Alice receives message C = M KB. She chooses some (contiguous) subsequence KA of size n of her key KA and sends C KA to Bob.
3. Bob receives message D, sends her back D KB.
4. Alice receives E = D KB. Since is commutative, A A = 0 and A 0 = A, we know that E = M KA. Hence Alice can now compute M as E KA.

Notes: is bitwise xor. Bob needs exactly six minutes to draw an image. Therefore he will always start sending the next image six minutes after Alice receives the previous one.

Problem specification

Your task is to monitor the messages sent between Alice and Bob and to change some of the messages in such a way that Alice will get the evil image.

In the easy subproblem, you can change any message you want. However, in the hard subproblem, you can only change the messages that go from Alice to Bob.

Note that the hard subproblem uses different secret keys and other messages than the easy subproblem. The protocol remains the same.

Input/output specification

Messages are in binary format, each one has exactly 10000 bytes. The most recently sent message in on the top of the list. If you want to change this message, submit (using the standard submission interface) a binary file containing the new message. If you just wish to deliver it in its original state, submit a text file containing one line with a single word: “forward”.

Valid submissions during the protocol are not counted as incorrect – you will not receive penalty minutes for these submissions.

In the hard subproblem you can only change one message from the protocol, the other ones will be forwarded to their recipient automatically.

In both subproblems, the time between any two submissions in different instances of the protocol has to be at least 6 minutes. In other words, you may not try to submit anything while Bob is drawing the next picture. Submissions that violate this rule will be judged as wrong answers; upon solving the task you will receive penalty minutes for these submissions.

The replaced message always has to have the same size as the original message (otherwise you will get an wrong answer).

At the end of the protocol, if Alice received anything other than the evil image, you will also get a wrong answer. If Alice receives the evil image, you solved the subproblem.

The evil image and all messages sent by Alice or Bob have exactly 10000 bytes. All images are valid PNG images. Alice and Bob have keys of size 50000 bytes.

Past communication between Alice and Bob

The following is a static example of a page the teams saw during the contest. The page contains a list of messages sent between Alice and Bob, along with the modifications already made by the contestants.

• 2011-06-05 15:11:28: Message #28 (Waiting for your action.)
• 2011-06-05 15:11:28: Message #27 (This message was forwarded.)
• 2011-06-05 15:05:28: Message #26 (This message was forwarded.)
• 2011-06-05 15:02:40: Message #25 (You changed this message. The original message is here.)
• 2011-06-05 15:02:40: Message #24 (This message was forwarded.)
• 2011-06-05 14:56:40: Message #23 (This message was forwarded.)
• 2011-06-05 14:54:13: Message #22 (This message was forwarded.)
• 2011-06-05 14:54:13: Message #21 (This message was forwarded.)
• 2011-06-05 14:48:13: Message #20 (This message was forwarded.)
• 2011-06-05 14:46:39: Message #19 (This message was forwarded.)
• 2011-06-05 14:46:39: Message #18 (This message was forwarded.)
• 2011-06-05 14:40:39: Message #17 (This message was forwarded.)
• 2011-06-05 14:38:18: Message #16 (This message was forwarded.)
• 2011-06-05 14:38:18: Message #15 (This message was forwarded.)
• 2011-06-05 14:32:18: Message #14 (This message was forwarded.)
• 2011-06-05 14:31:46: Message #13 (This message was forwarded.)
• 2011-06-05 14:31:46: Message #12 (This message was forwarded.)
• 2011-06-05 14:25:46: Message #11 (This message was forwarded.)
• 2011-06-05 14:23:17: Message #10 (This message was forwarded.)
• 2011-06-05 14:23:17: Message #9 (This message was forwarded.)
• 2011-06-05 14:17:17: Message #8 (This message was forwarded.)
• 2011-06-05 14:15:34: Message #7 (This message was forwarded.)
• 2011-06-05 14:15:34: Message #6 (This message was forwarded.)
• 2011-06-05 14:09:34: Message #5 (This message was forwarded.)
• 2011-06-05 14:09:22: Message #4 (This message was forwarded.)
• 2011-06-05 14:09:22: Message #3 (This message was forwarded.)
• 2011-06-05 14:03:22: Message #2 (This message was forwarded.)
• 2011-06-05 11:25:40: Message #1 (This message was forwarded.)
• 2011-06-05 11:25:40: Message #0 (This message was forwarded.)