A pseudonym or alias is a name adopted by a person for a particular purpose, which differs from his or her true name. A pseudonym may be used by social activists or politicians for political purposes or by others for religious purposes. It may be a soldier's nom de guerre or an author's nom de plume. It may be a performer's stage name or an alias used by visual artists, athletes, fashion designers, or criminals. Pseudonyms are occasionally used in fiction such as by superheroes or other fictional characters.

For example, what are the more familiar pseudonyms of the following people?

  1. Georgios Kyriacos Panayiotou

  2. Margaretha Geertruida Zelle MacLeod

  3. Ioseb Vissarionovich Dzhugashvili

  4. Cassius Marcellus Clay Jr.

  5. Choo Yeang Keat

Assignment

A pseudonym is often used to mask the identity of a person. However, we can also use a (secret) keyword to make the real name of the person unrecognizable.

For example, suppose we use GEORGEMICHAEL as a keyword to mix the letters of the alphabet in the following way. First we write down the letters of the keyword, where letters that occur more than once are only written upon their first occurrence (indicated in green below). Then we write down all remaining letters in the order in which they appear in the alphabet (indicated in orange below).

alphabet

This creates a permutation of the letters of the alphabet that can be used to decode messages. Each occurrence of the first letter in the alphabet is replaced by the first letter in the permutation, the second letter in the alphabet by the second letter of the permutation, and so on.

encode alphabet

Below you can see for example how the message GEORGIOSKYRIACOSPANAYIOTOU is encoded into CMKQCAKSBYQAGOKSNGJGYAKTKU using GEORGEMICHAEL as a keyword.

encode message

When decoding, the roles of the alphabet and the permutation are reversed: the first letter in the permutation is replaced by the first letter in the alphabet, the second letter in the permutation by the second letter in the alphabet, and so on.

decode alphabet

Your task:

Example

>>> permutation('George Michael')
'GEORMICHALBDFJKNPQSTUVWXYZ'
>>> permutation('Mata Hari')
'MATHRIBCDEFGJKLNOPQSUVWXYZ'
>>> permutation('Joseph Stalin')
'JOSEPHTALINBCDFGKMQRUVWXYZ'
>>> permutation('Muhammad Ali')
'MUHADLIBCEFGJKNOPQRSTVWXYZ'
>>> permutation('Jimmy Choo')
'JIMYCHOABDEFGKLNPQRSTUVWXZ'

>>> encode('Georgios Kyriacos Panayiotou', 'George Michael')
'Cmkqcaks Byqagoks Ngjgyaktku'
>>> encode('Margaretha Geertruida Zelle MacLeod', 'Mata Hari')
'Jmpbmprscm Brrpspudhm Zrggr JmtGrlh'
>>> encode('Ioseb Vissarionovich Dzhugashvili', 'Joseph Stalin')
'Lfqpo Vlqqjmlfdfvlsa Ezautjqavlbl'
>>> encode('Cassius Marcellus Clay Jr.', 'Muhammad Ali')
'Hmrrctr Jmqhdggtr Hgmy Eq.'
>>> encode('Choo Yeang Keat', 'Jimmy Choo')
'Mall Xcjko Ecjs'

>>> decode('Cmkqcaks Byqagoks Ngjgyaktku', 'George Michael')
'Georgios Kyriacos Panayiotou'
>>> decode('Jmpbmprscm Brrpspudhm Zrggr JmtGrlh', 'Mata Hari')
'Margaretha Geertruida Zelle MacLeod'
>>> decode('Lfqpo Vlqqjmlfdfvlsa Ezautjqavlbl', 'Joseph Stalin')
'Ioseb Vissarionovich Dzhugashvili'
>>> decode('Hmrrctr Jmqhdggtr Hgmy Eq.', 'Muhammad Ali')
'Cassius Marcellus Clay Jr.'
>>> decode('Mall Xcjko Ecjs', 'Jimmy Choo')
'Choo Yeang Keat'

Epilogue

Some of the busiest people in show business don't exist:

  • The name George Spelvin is traditionally used in American theater programs when an actor's name would otherwise appear twice.

  • In the London theater, Walter Plinge gets the credit when a part has not been cast.

  • On BBC television dramas in the 1970s, David Agnew was credited when contractual reasons prevented a writer's name from being used.

  • When a Hollywood director no longer wants credit for a film, the name Alan Smithee is used.

That last one is such an open secret — "Smithee" even directed a Whitney Houston video — that the Directors Guild of America finally abandoned it in favor of random pseudonyms, starting with the 2000 James Spader bomb Supernova, directed by "Thomas Lee" (Walter Hill).