Playfair

The playfair is a digraph substitution cypher using a key to encrypt messages. In order to encrypt, the letters of the key are placed on a 5x5 square, dropping any duplicate letters and padding with the letters of the alphabet to complete the square.

Encryption follows the rules of the plaintext:

Taking the key as good day, the $5 \times 5$ square becomes:

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

Encrypting the message: live long and prosper ( LI VE LO NG AN DP RO SP ER ):

H I J K L

so slide and wrap to HJ:

H I -> J K L ->
    E F
    J K
    P Q
    U V

so take the opposite corners, first letter is V so we obtain UF:

    E -> F
    J    K
    P    Q
    U <- V
  O  -> Y
  C     G
  I <-  L

so we obtain IY.

  C <-  G
  I     L
  N  -> R

so we obtain RC.

  O <- A
  C    F
  I    K
  N -> Q

so we obtain OQ.

    D
    |
    E
    J
    P
    |
    U

so we obtain EU.

  O  -> Y
  C     G
  I     L
  N <-  R

so we obtain NY.



M  <- P 
S ->  U

so we obtain UM.

    E -> G
    J    L
    P <- R

so we obtain GP.

Thus, the final cyphertext reads: HJ UF IY RC OQ EU NY UM GP.

To decrypt, perform the inverse operation of the last three rules and drop any extra "X" or "Q" that do not make sense in the final message.