Pizzino (plural: pizzini) is an Italian language word derived from Sicilian language equivalent pizzinu. Despite it generically meaning "small piece of paper", the word is now widely used to refer to small slips of paper that the Sicilian Mafia uses for high-level communications. Sicilian Mafia boss Bernardo Provenzano is among those best known for using pizzini, most notably in his instruction that Messina Denaro become his successor. The pizzini of other mafioso have significantly aided police investigations about the Sicilian Mafia.
Provenzano hid the pizzini containing his instructions at an old sheep farm under rocks or under the ground. The were immediately destructed after reading. Provencano's pizzini also used a code in which letters replaced by numbers indicating their position in the alphabet (A=1, B=2, …). Each of these number was than incremented by three. The numbers thus obtains for each of the letters in a word, were simply concatenated to and up with a large number. This mia might become 16124, because \[\mbox{m} = 13 + 3 = 16,\ \mbox{i} = 9 + 3 = 12 \mbox{ en a} = 1 + 3 = 4\] Note that the alphabet used is the Italian alphabet, which has a slightly different order and number of characters than the Latin alphabet:
ABCDEFGHILMNOPQRSTUVZ
All in all, this was a very simple and old code (tracing back to Julius Caesar wartime communications), with the only point of difficulty being the initial confusion of the ambiguous role of the various digits as independent or part of two-digit numbers. For example, one reported note by Provenzano read
I met 512151522 191212154 and we agreed that we will see each other after the holidays…
This name was decoded as Binnu Riina. Bruce Schneider — an American cryptography expert — was quoted in Discovery Channel News saying
Looks like kindergarten cryptography to me. It will keep your kid sister out, but it won't keep the police out. But what do you expect from someone who is computer illiterate?
Italian police got a chance to read many pizzini when close associates of Provenzano turned informant. Once in possession of enough pizzini, police were able to break the code quickly. A biographer of Provenzano also reports that Provenzano used a more complicated code — yet to be deciphered — which referenced selected words that Provenzano had underlined in his copy of the Bible.
In this assignment we ask you to encode words as positive integers, using an encryption scheme inspired by the code Provenzano used to write his pizzini. In doing you, you proceed as follows.
Write a funtion encodeLetter that takes three arguments: i) a single letter (string), ii) an integer $$n \in \mathbb{N}$$, and iii) a string of letters. The function must return an integer that is computed as the sum of $$n$$ and the position of the given letter (first argument) in the given string of letters (third argument). The positions of the letters in the third argument are indexed starting from one (the first letter is at position 1, the second letter at position 2, …).
Write a function encodeWord that takes three arguments: i) a word (string), ii) an integer $$n \in \mathbb{N}$$, and iii) a string of letters. The function must return an integer that is constructed by chaining all digits of all numbers that are obtained by converting the individual letters of the given word using the function encodeLetter.
In both functions, the third argument represents a given alphabet, in which you may assume that each character occurs only once. In addition you may assume in both cases that all characters of the string passed as the first argument occur in the given alphabet. Both function should make no distinction between uppercase and lowercase letters.
>>> italian = 'ABCDEFGHILMNOPQRSTUVZ'
>>> encodeLetter('M', 3, italian)
14
>>> encodeWord('MIA', 3, italian)
14124
>>> encodeWord('Binnu', 3, italian)
512151522
>>> encodeWord('Riina', 3, italian)
191212154
>>> latin = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> encodeLetter('M', 3, latin)
16
>>> encodeWord('MIA', 3, latin)
16124
>>> encodeWord('Binnu', 3, latin)
512171724
>>> encodeWord('Riina', 3, latin)
211212174