# Porta Cipher Encrypt & Decrypt

## Porta Cipher :

Porta cipher is a polyalphabetical cipher which was created by an Italian physicist named Giovanni Battista Della Porta, back in 1563. This cipher was the first one to use multiple alphabets and change it for each letter to encrypt. This makes the Porta cipher really secure in comparison to other ciphers. The Porta cipher was used for three centuries (up to the 19th century).
The cipher principle is simple, but secure. Each couple of letter in the alphabet has its own alphabet. Since there is 13 couples of letters in the latin alphabet, there is also 13 alphabets (AB, CD, EF, GH, IJ, KL, MN, OP, QR, ST, UV, WX, YZ). As you can see in the table, these alphabets are easy to make from scratch. But Porta himself said that it would be more secure to use random alphabets, and carry them to decipher crypted texts. For the sake of simplicity here, we'll use the "normal" alphabets. When you want to encrypt a text, using a key, you check the corresponding letter in the alphabet corresponding to the actual key letter. As this is hard to explain with words, here's an example :

AB
 a b c d e f g h i j k l m n o p q r s t u v w x y z
CD
 a b c d e f g h i j k l m z n o p q r s t u v w x y
EF
 a b c d e f g h i j k l m y z n o p q r s t u v w x
GH
 a b c d e f g h i j k l m x y z n o p q r s t u v w
IJ
 a b c d e f g h i j k l m w x y z n o p q r s t u v
KL
 a b c d e f g h i j k l m v w x y z n o p q r s t u
MN
 a b c d e f g h i j k l m u v w x y z n o p q r s t
OP
 a b c d e f g h i j k l m t u v w x y z n o p q r s
QR
 a b c d e f g h i j k l m s t u v w x y z n o p q r
ST
 a b c d e f g h i j k l m r s t u v w x y z n o p q
UV
 a b c d e f g h i j k l m q r s t u v w x y z n o p
WX
 a b c d e f g h i j k l m p q r s t u v w x y z n o
YZ
 a b c d e f g h i j k l m o p q r s t u v w x y z n
For fully understanding Porta cipher, let's see the example above. We want to encrypt the sequence "Porta cipher" using the key "key":

 C h i f f r e d e P o r t a c l e c l e c l e c l e c l o p t r n g q y p d g g h v

hddly qqevzg As you can see, we reapeat the key as many as it's necessary to match the text length. Then we look for each letter to encrypt, its counterpart in the alphabet indicated by the key letter we are using. For instance to encrypt the first letter, "p", with the key letter "k", we look into the "KL" alphabet and we see that the counterpart to "p" is "h". For the letter "o", we check in the alphabet "EF" and we see that the encrypted letter for "o" is "d", and so on.
To decrypt Porta cipher, you just have to reverse this process. It usually needs the encryption key and the alphabets that were used. The Porta cipher remained secure until the Cryptologist Kasiski managed to break it back in 1863. He just used a simple frequency analysis after he founds the key length (thanks to Friedman test). However it is admitted that Porta cipher is still secure if the key length is long enough and if the encrypted text isn't too long (to avoid easy frequency analysis). It is possible to recognize a Porta encrypted cipher by analyzing its index of coincidence. since Porta cipher use several alphabets, its index will obviously be low.

﻿