• Mission idea - "Look and say" int sequence cipher

Hi, all,

I've been working on an encryption cipher based on the "Look and say integer sequence" (see link).


The basic idea behind the Look and say sequence is this:

To generate a member of the sequence from the previous member, read off the digits of the previous member, counting the number of digits in groups of the same digit. For example:

1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read off as "one 2, then one 1" or 1211.

My "Look and Say" cipher therefore works by converting a string of letters into a series of numbers which are then sequenced as above. The resulting number is then converted back to letters, so for example the plain-text word "Hello" is encoded as the cipher-text "rokjlkjlkjo".

The only tricky part is that when we originally convert the 26 letters of the alphabet into numbers we have to turn "j' (for example), which is the 10th letter, into the number 100 (ie 10 + 0). The same holds, for example, for "v", which becomes 202 (ie 20+2), being the 22nd letter of the alphabet. This is what makes decoding encrypted messages possible.

Note that if numbers (0-9) are included in the original plain-text message they are converted to the uppercase letters QWERTYUIOP (the top line of a computer keyboard). This is also what makes decoding encrypted messages possible.

The test cases would look like below (or see attachment):

if name == 'main':
assert looksay_encode("Hello") == 'rokjlkjlkjo', "encode Hello"
assert looksay_decrypt("rokjlkjlkjo") == 'hello', "decode Hello"
assert looksay_encode("We attack at 9:00pm") == "ljmokltltkmkjultPQQkjpkjm", "encode attack"
assert looksay_decrypt("ljmokltltkmkjultPQQkjpkjm") == 'weattackat900pm', "decode attack"
assert looksay_encode("I see you are having the pork knuckle") == 'skjsyljokjoljukjrorkljlskjnqltrokjpkjokjrkjujujnljkmkjujlo', "encode I see you are having the pork knuckle"
assert looksay_decrypt("skjsyljokjoljukjrorkljlskjnqltrokjpkjokjrkjujujnljkmkjujlo") == 'iseeyouarehavingtheporkknuckle', "decode pork knuckle"
assert looksay_encode("1, 11, 21, 1211, 111221") == 'WWWEWWEWWWWWEEW', "encode look and say int sequence"
assert looksay_decrypt("WWWEWWEWWWWWEEW") == '111211211111221', "decode look and say int sequence"