- 26,952
- Follow
- +1,026
- 3,065

Why **encryption**?maybe some of readers think that this is not hacking practice or something that can not learning by doing. I can say that learn about **cryptography **is also fun and interesting. Maybe after you read the rest of this post you can find another algorithms for **encryption**….why not? or maybe break some ciphertext ๐

In this tutorial we will learn about classic **cryptography** **Playfair Cipher**. Maybe some of you already know about this tutorial, so you can use this to refresh again your mind.

**Playfair Cipher** founded by Sir Charles Wheatstone in 1854 also known as Polygraphic System using matrix 5 x 5. The **Playfair **is a primitive block cipher. Any new personal computer today can break a message encoded with it in a matter of seconds, even some skilled cryptogrophists and puzzle experts can even break it with nothing more than pen and paper. (maybe you who read this are one of them? ๐ )

1. Let say I have a message want to encrypt : “**MEET PRIME MINISTER AFTER DINNER TOMORROW AT POOLSIDE IMPORTANT**” with **encryption** key(this key is private) : “**SECRET AMENDMENT**”

2. The first step, you should prepare the plaintext. All letters should written in uppercase, in pairs, and without punctuation. All **J** are replaced with** I**. This particular example contains no **J,** if there are an odd number of letters, an extra letter chosen by the person writing the cipher is added to the end.

**ME ET PR ****IM** **EM** IN IS **TE** **RA** **FT** **ER** DI NN **ER**
TO MO RR OW AT PO OL SI **DE** **IM** **PO** **RT** AN T

2. Double letters(if they occur in a pair)must be divided by an X or a Z. For example, **DINNER** in this example becomes DINXNER. If there are an odd number of letters, an extra letter chosen by the person writing the cipher is added to the end. Now the plaintext becomes :

**ME ET PR ****IM** **EM** IN IS **TE** **RA** **FT** **ER** DI NX NE **RT**
OM OR RO WA TP OX OL SI **DE** **IM** PO **RT** AN TX

3. Preparing the Key

The alphabet square is a five-by-five (5 x 5) grid. The key phrase is first written without repeating any letters. The remaining letters of the alphabet are filled in in order:

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

4. Encryption

Any pair of letters must both be in the same row, in the same column, or in different rows and columns; no other combinations are possible.

Each letter in a pair that is on the same row is replaced by the letter to the right. The letter to the right of the rightmost letter is the first letter in the same row it “wraps” around without going to the next line. With this key, **PR** becomes QC; IN becomes HD; IS becomes FR, and so on(see picture below).

If two letters fall in a same row, slide one character to the RIGHT, for example **ET** becomes CS, and **TE** becomes SC.

If two letters fall in same column, slide one character to the BOTTOM, for example ME becomes GM, and **EM** becomes MG.

5. Finally, remove the spaces:

**GMCSQCGDMGHDFRSCSDKSCTIQHCMCTSWGQEEQVMCUPWPORFMRGDQPTSMDCZ
**

1. To decrypt the message, simply reverse the entire process. Break the ciphertext into pairs of letters:

**GM CS QC GD MG
HD FR SC SD KS
CT IQ HC MC TS
WG QE EQ VM CU
PW ****PO** RF MR GD
QP TS MD CZ

2. Write down the alphabet square with the key:

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

3. Transform the pairs of letters in the opposite direction from that used for **encryption**:

**ME ET PR ****IM** **EM** IN IS **TE** **RA** **FT** **ER** DI NX NE **RT**
OM OR RO WA TP OX OL SI **DE** **IM** PO **RT** AN TX

4. This message is now readable, although removing the extra spaces and substitutions for double letters makes it more readable:

**MEET PRIME MINISTER AFTER DINNER TOMORROW AT POOLSIDE IMPORTANT**

Hope you enjoy it! ๐