Company: Goldman sachs_9aug
Difficulty: medium
Secure my conversations Problem Description Persons A and B protect their conversation with a simple encryption system. Every message is encoded by the sender and decoded by the receiver using a shared private key: a positive number, written as a string of digits. Encoding (operation 1 ). Walk through the message and the key together. The i -th character of the message is written out d times, where d is the i -th digit of the key. As soon as either the message or the key runs out, stop; every message character that was not reached is copied to the output unchanged. Decoding (operation 2 ) reverses encoding. Walk through the key one digit at a time. For a digit d , the next d characters of the encoded message form one block, which must consist of the same character repeated d times; that character is written to the output once. As soon as either the encoded message or the key runs out, stop; every encoded character that was not reached is copied to the output unchanged. Implement secure