The Kāmasūtra1 is a text written in the 4th century AD by the Brahim scholar Vātsyāyana2, but based on manuscripts dating back to the 4th century BC. Chapter 3 of Part I recommends that women should study 64 arts, including cooking, dressing, massage and the preparation of perfumes. The list also includes some less obvious arts, including conjuring, chess, bookbinding and carpentry.

kamasutra
A Kāmasūtra manuscript page preserved in the vaults of the Raghunatha Hindu temple in Jammu & Kashmir.

Number 44 on the list is mlecchita vikalpa3, which has been translated into English as "the art of understanding writing in cypher, and the writing of words in a peculiar way". It is one of the earliest descriptions of encryption by substitution and is advocated in order to help women conceal the details of their liaisons. One of the recommended techniques involves randomly pairing letters of the alphabet, and then substituting each letter in the original message with its partner.

Assignment

The Kāmasūtra cipher uses a key $$(k_1, k_2)$$ where the 26 letters of the alphabet are randomly distributed across two 13-character strings $$k_1$$ and $$k_2$$ (str), for example THEQUICKBROWN and FXJMPSVLAZYDG. If we write both parts of the key underneath each other in a table

T H E Q U I C K B R O W N
F X J M P S V L A Z Y D G

we get a substitution cipher that substitutes the letter T for the letter F, the letter F for letter T, the letter H for the letter X, the letter X for the letter H, and so forth. When encoding a message, uppercase letters are substituted by their corresponding uppercase letter and lowercase letters are substituted by their corresponding lowercase letter. All characters from the original message that aren't letters, are copied unchanged into the encoded message. Your task:

You may assume that the strings $$k_1$$ and $$k_2$$ that are passed to the functions encode_character, encode and decode form a valid key $$(k_1, k_2)$$ for the Kāmasūtra cipher, without the need to check this explicitly.

Example

>>> iskey('THEQUICKBROWN', 'FXJMPSVLAZYDG')
True
>>> iskey('ABCDEFGHIJKLM', 'NOPQRSTUVW???')
False
>>> iskey('ABCDEFGHIJKLM', 'NOPQRSTUVW')
False

>>> encode_character('Q', 'THEQUICKBROWN', 'FXJMPSVLAZYDG')
'M'
>>> encode_character('v', 'THEQUICKBROWN', 'FXJMPSVLAZYDG')
'c'
>>> encode_character('?', 'THEQUICKBROWN', 'FXJMPSVLAZYDG')
'?'

>>> encode('A person who does nothing will enjoy no happiness.', 'THEQUICKBROWN', 'FXJMPSVLAZYDG')
'B ujziyg dxy wyji gyfxsgn dskk jgeyo gy xbuusgjii.'

>>> decode('B ujziyg dxy wyji gyfxsgn dskk jgeyo gy xbuusgjii.', 'THEQUICKBROWN', 'FXJMPSVLAZYDG')
'A person who does nothing will enjoy no happiness.'