The reflection of letter $$\alpha$$ at distance $$n \in \mathbb{N}$$ is formed by the letter pair $$\alpha_{-n}\,\alpha_{+n}$$. The two letters of this reflection are determined by putting the alphabet clockwise around a circle, such that letter Z is followed by letter A.
The letter $$\alpha_{-n}$$ is then obtained by jumping $$n$$ steps counterclockwise in the alphabet around the circle from letter $$\alpha$$. The letter $$\alpha_{+n}$$ is obtained by jumping $$n$$ steps clockwise in the alphabet around the circle from letter $$\alpha$$. This way, the letters $$\alpha_{-n}$$ and $$\alpha_{+n}$$ are each other's reflection relative to letter $$\alpha$$. For example, the letter pair OC is the reflection of letter V (orange) at distance $$n = 7$$, because letter O is at 7 steps counterclockwise from letter V (blue) and letter C is at 7 steps clockwise from letter V (green).
The Narcissus cipher encodes a message by replacing each letter with its reflection at distance $$n \in \mathbb{N}$$. The letters of the first word of the message are encoded with distance $$n=1$$, the letters of the second word with distance $$n=2$$, the letters of the third word with distance $$n=3$$, and so on. The words of the message consist of the longest possible succession of letters. Two words are therefore always separated by one or more characters that are no letters. A character that is not a letter simply remains in place upon encoding. An uppercase letter is encoded as a pair of uppercase letters, and a lowercase letter as a pair of lowercase letters. The message
One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Eleven, Twelve, Thirteen, Fourteen, Fifteen!
is for example encoded as
NPmodf, RVuymq, QWekoubhbh, BJksqynv, AKdnqazj, MYcord, LZxlocxlgu, WMaqyozplb, EWzrewvn, JDuodx, TPawtpkgtpcy, HFkisqzxjhsq, GGuuvveeggrrrraa, RTacgidffhqsqszb, QUtxqueiptptyc!
where the word One is encoded with distance $$n=1$$ as NPmodf, the word Two with distance $$n=2$$ as RVuymq, the word Three with distance $$n=3$$ as QWekoubhbh, ..., and the word Fifteen with distance $$n=15$$ as QUtxqueiptptyc.
Write a function jump that takes two arguments: i) a character $$\alpha$$ and ii) an integer $$n \in \mathbb{Z}$$ (int). If $$\alpha$$ is not a string (str) that consists of a single letter, an AssertionError must be raised with the message invalid letter: $$\alpha$$. Otherwise, the letter $$\alpha_n$$ (str) must be returned. If $$\alpha$$ is an uppercase letter, the function must return an uppercase letter. If $$\alpha$$ is a lowercase letter, the function must return a lowercase letter.
Write a function reflection that takes two arguments: i) a character $$\alpha$$ and ii) an integer $$n \in \mathbb{N}$$ (int). If $$\alpha$$ is not a string (str) that consists of a single letter, an AssertionError must be raised with the message invalid letter: $$\alpha$$. Otherwise, the function must return the letter pair (str) that encodes the letter $$\alpha$$ according to the Narcissus cipher with distance $$n$$.
Write a function fixation that takes two arguments: i) a letter pair $$p$$ and ii) an integer $$n \in \mathbb{N}$$ (int). The function must raise an AssertionError with message invalid pair: $$p$$ if the first argument $$p$$ is not a string (str) that consists of two uppercase letters or two lowercase letters, such that you jump clockwise from the first letter of $$p$$ to the second letter of $$p$$ in $$2n$$ steps. Otherwise, the function must return the letter (str) that is encoded as letter pair $$p$$ according to the Narcissus cipher with distance $$n$$.
Write a function encode that takes a plaintext1 (str) and returns the corresponding ciphertext2 (str) according to the Narcissus cipher.
Write a function decode that takes a ciphertext3 that is supposed to be encoded according to the Narcissus cipher, and returns the corresponding plaintext4 (str). If the given ciphertext could not have resulted from encoding a plaintext according to the Narcissus cipher, the function must raise an AssertionError with message invalid pair: $$p$$ when the first invalid pair $$p$$ is encountered.
>>> jump('V', 7)
'C'
>>> jump('v', -7)
'o'
>>> jump('!', 13)
Traceback (most recent call last):
AssertionError: invalid letter: !
>>> reflection('V', 1)
'UW'
>>> reflection('v', 7)
'oc'
>>> reflection('!', 13)
Traceback (most recent call last):
AssertionError: invalid letter: !
>>> fixation('UW', 1)
'V'
>>> fixation('oc', 7)
'v'
>>> fixation('cm', 4)
Traceback (most recent call last):
AssertionError: invalid pair: cm
>>> encode('One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Eleven, Twelve, Thirteen, Fourteen, Fifteen!')
'NPmodf, RVuymq, QWekoubhbh, BJksqynv, AKdnqazj, MYcord, LZxlocxlgu, WMaqyozplb, EWzrewvn, JDuodx, TPawtpkgtpcy, HFkisqzxjhsq, GGuuvveeggrrrraa, RTacgidffhqsqszb, QUtxqueiptptyc!'
>>> encode('And Now for Something Completely Different')
'ZBmoce LPmquy cilrou OWksiqaipxdlemjrck XHjthrkugqzjoyzjgqtd XJcozlzlyklxykhtnz'
>>> decode('NPmodf, RVuymq, QWekoubhbh, BJksqynv, AKdnqazj, MYcord, LZxlocxlgu, WMaqyozplb, EWzrewvn, JDuodx, TPawtpkgtpcy, HFkisqzxjhsq, GGuuvveeggrrrraa, RTacgidffhqsqszb, QUtxqueiptptyc!')
'One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Eleven, Twelve, Thirteen, Fourteen, Fifteen!'
>>> decode('ZBmoce LPmquy cilrou OWksiqaipxdlemjrcm XHjthrkugqzjoyzjgqtd XJcozlzlyklxykhtnz')
Traceback (most recent call last):
AssertionError: invalid pair: cm
Nárkissos (Ancient Greek: Νάρκισσος) or Narcissus (Latin) is a character from Greek mythology. He was a son of the river god Cephissus5 and the nymph Liriope6. The most popular account of Narcissus is by Ovid7, who passed on the Greek myth as a poem in Latin (Metamorphoses 3.341-510). Ovid's version tells the story from the metamorphosis of the nymph Echo to the metamorphosis of Narcissus.
Narcissus was a hunter from Thespiae8 in Boeotia9 who was known for his beauty. He rejected all romantic advances, eventually falling in love with his own reflection in a pool of water, staring at it for the remainder of his life. After he died, in his place sprouted a flower bearing his name.
The character of Narcissus is the origin of the term narcissism10, a fixation with oneself.