James Leeson (1756–1794) is buried in New York's Trinity Church Cemetery. His tombstone bears a curious inscription. It remained a local puzzle until 1889, when the Trinity Record discovered that it is reads as REMEMBER DEATH encoded in pigpen cipher.
The pigpen cipher (sometimes referred to as the masonic cipher or Freemason's cipher) is a geometric simple substitution cipher that exchanges letters for symbols which are fragments of a grid. The exact origin of the cipher is uncertain, but records of this system have been found which go back to at least the 18th century. Variations of this cipher were used by both the Rosicrucian brotherhood and the Freemasons, though the latter used it so often that the system is frequently called the Freemason's cipher. They began using it in the early 18th century to keep their records of history and rites private, and for correspondence between lodge leaders.
The oldest known version is from Heinrich Cornelius Agrippa von Nettesheim who explains the method in his De occulta philosophia published in 1533. This work was reused in 1586 by Blaise de Vigenère in his treatise about cryptography. There are many possible variations, but any trained crypto-analyst will usually have no trouble deciphering the encoded messages.
Your task is to decode a given word according to the pigpen cipher that makes use of the following key.
This is done by substituting each letter of the word by its symbolic representation in the pigpen cipher. This representation forms a $$3 \times 3$$ grid of characters. The middle character of the symbolic representation indicates what grid of the key contains the letter: a space represents the left grid, a dot (.) the middle grid, and a colon (:) the grid to the right. In addition, lines must be drawn to the left, right, top and bottom according to the position of the letter in the grid. As an example, the symbolic representation of all letters in the middle grid are depicted below.
| | | | --+ +-+ +-- --+ +-+ +--
.| |.| |. .| |.| |. .| |.| |.
--+ +-+ +-- --+ +-+ +-- | | | |
J K L M N O P Q R
Note that fragments of a horizontal line are thus represented by a dash (-) and fragments of a vertical line by a pipe symbol (|). Corner points of the symbolic representation where two lines meet are represented by a plus sign (+). Your task:
Write a function pigpenletter that takes a single letter as an argument. The function must return a string containing three lines of three characters. These characters form the symbolic representation of the given letter in pigpen notation. Make sure that the number of conditions that need to be tested is kept to the absolute minimum when determining the representation of the given letter in pigpen notation. You definitely have to avoid programming constructs of the form: if the letter is A then its symbolic representation is the following, else if the letter is B then its symbolic representation is the following, …
Use the function pigpenletter to write a function pigpen. The function takes a string that only contains letters and must return a string that consists of three lines that contain the symbolic representation of the given word in pigpen notation. This is done by separating the symbolic representations of the individual letters with a single column containing three spaces.
Both functions must handle the given string in a case insensitive way.
>>> print(pigpenletter('A'))
|
|
--+
>>> print(pigpenletter('m'))
--+
.|
--+
>>> print(pigpenletter('U'))
|
|:
+--
>>> print(pigpen('python'))
--+ --+ | | +-+ +-- +-+
.| :| |:| | | |. |.|
| | +-+ | | +-- +-+
>>> print(pigpen('Rosenkreutz'))
+-- +-- | +-+ +-+ | | +-- +-+ | | | +-+
|. |. :| | | |.| |.| |. | | |: |:| |:|
| +-- --+ +-+ +-+ +-+ | +-+ +-- +-+ | |