Friday 7 February 2014

Types of Cipher

Codes, Ciphers, Encryption and Cryptography

Cryptography is the discipline of using codes and ciphers to encrypt a message and make it unreadable unless the recipient knows the secret to decrypt it. Encryption has been used for many thousands of years. The following codes and ciphers can be learned and used to encrypt and decrypt messages by hand.





Monoalphabetic Ciphers

A monoalphabetic cipher uses the same substitution across the entire message. For example, if you know that the letter A is enciphered as the letter K, this will hold true for the entire message. These types of messages can be cracked by using frequency analysis, educated guesses or trial and error.

Polyalphabetic Ciphers
In a polyalphabetic cipher, the substitution may change throughout the message. In other words, the letter A may be encoded as the letter K for part of the message, but later on it might be encoded as the letter W.

Polygraphic Ciphers
Instead of substituting one letter for another letter, a polygraphic cipher performs substitutions with two or more groups of letters. This has the advantage of masking the frequency distribution of letters, which makes frequency analysis attackes much more difficult.

Transposition Ciphers

Unlike substitution ciphers that replace letters with other letters, a transposition cipher keeps the letters the same, but rearranges their order according to a specific algorithm.

Caesar Cipher

A Caesar cipher is one of the simplest (and easiest cracked) encryption methods. It is a Substitution Cipher that involves replacing each letter of the secret message with a different letter of the alphabet which is a fixed number of positions further in the alphabet.
Because each letter in the message has a direct translation to another letter, frequency analysis can be used to decipher the message. For example, the letter E is the most commonly used letter in the English language. Thus, if the most common letter in a secret message is K, it is likely that K represents E. Additionally, common word endings such as ING, LY, and ES also give clues.
A brute-force approach of trying all 25 possible combinations would also work to decipher the message.
Example
In this example, each letter in the plaintext message has been shifted 3 letters down in the alphabet.
Plaintext: This is a secret message
Ciphertext: wklv lv d vhfuhw phvvdjh

Atbash Cipher

The Atbash cipher is a very specific case of a substitution cipher where the letters of the alphabet are reversed. In otherwords, all As are replaced with Zs, all Bs are replaced with Ys, and so on.
Because reversing the alphabet twice will get you actual alphabet, you can encipher and decipher a message using the exact same algorithm.
Example
Plaintext: This is a secret message
Ciphertext: Gsrh rh z hvxivg nvhhztv

Keyword Cipher

The Keyword cipher is identical to the Caesar Cipher with the exception that the substitution alphabet used can be represented with a keyword.
To create a substitution alphabet from a keyword, you first write down the alphabet. Below this you write down the keyword (omitting duplicate letters) followed by the remaining unused letters of the alphabet.
ABCDEFGHIJKLMNOPQRSTUVWXYZ
KEYWORDABCFGHIJLMNPQSTUVXZ
To encipher a plaintext message, you convert all letters from the top row to their correspondng letter on the bottom row (A to K, B to E, etc).
These types of simple substitution ciphers can be easily cracked by using frequency analysis and some educated guessing.


Pigpen / Masonic Cipher

The pigpen cipher (sometimes called the masonic cipher or Freemason's cipher) is a simple substitution cipher exchanging letters for symbols based on a grid. The scheme was developed and used by the Freemasons in the early 1700s for record-keeping and correspondence. The example key shows one way the letters can be assigned to the grid.
Masonic Cipher Example

Polybius Square


A Polybius Square is a table that allows someone to translate letters into numbers. To give a small level of encryption, this table can be randomized and shared with the recipient. In order to fit the 26 letters of the alphabet into the 25 spots created by the table, the letters i and j are usually combined.
12345
1ABCDE
2FGHIK
3LMNOP
4QRSTU
5VWXYZ
To encipher a message you replace each letter with the row and column in which it appears. For example, D would be replaced with 14.
To decipher a message you find the letter that intersects the specified row and column.
Example:
Plaintext: This is a secret message
Ciphertext: 44232443  2443  11  431513421544  32154343112215 
 
 
 
 
 
 
 

Vigenère Cipher

In a Caesar Cipher, each letter of the alphabet is shifted along some number of places; for example, in a Caesar cipher of shift 3, A would become D, B would become E and so on. The Vigenere cipher consists of using several Caesar ciphers in sequence with different shift values.
Vigenere code chart To encipher, a table of alphabets can be used, termed a tabula recta, Vigenère square, or Vigenère table. It consists of the alphabet written out 26 times in different rows, each alphabet shifted cyclically to the left compared to the previous alphabet, corresponding to the 26 possible Caesar ciphers. At different points in the encryption process, the cipher uses a different alphabet from one of the rows. The alphabet used at each point depends on a repeating keyword.
For example, suppose that the plaintext to be encrypted is:
ATTACKATDAWN The person sending the message chooses a keyword and repeats it until it matches the length of the plaintext, for example, the keyword "LEMON":
LEMONLEMONLE Each letter is encoded by finding the intersection in the grid between the plaintext letter and keyword letter. For example, the first letter of the plaintext, A, is enciphered using the alphabet in row L, which is the first letter of the key. This is done by looking at the letter in row L and column A of the Vigenere square, namely L. Similarly, for the second letter of the plaintext, the second letter of the key is used; the letter at row E and column T is X. The rest of the plaintext is enciphered in a similar fashion:
Plaintext: ATTACKATDAWN Key: LEMONLEMONLE Ciphertext: LXFOPVEFRNHR Decryption is performed by finding the position of the ciphertext letter in a row of the table, and then taking the label of the column in which it appears as the plaintext. For example, in row L, the ciphertext L appears in column A, which taken as the first plaintext letter. The second letter is decrypted by looking up X in row E of the table; it appears in column T, which is taken as the plaintext letter.

Beaufort Cipher

To encrypt a plaintext message using the Vigenère Cipher, one locates the row with the first letter to be encrypted, and the column with the first letter of the keyword. The ciphertext letter is located at the intersection of the row and column. This continues for the entire length of the message.
Running key code chart A Beaufort cipher uses the same alphabet table as the Vigenère cipher, but with a different algorithm. To encode a letter you find the letter in the top row. Then trace down until you find the keyletter. Then trace over to the left most column to find the enciphered letter. To decipher a letter, you find the letter in the left column, trace over to the keyletter and then trace up to find the deciphered letter.
Some people find this easier to do than finding the intersection of a row and column.

 
 
 
 
 
 
 
 
 

Running key code chart Autokey Cipher

To encrypt a plaintext message using the Vigenère Cipher, one locates the row with the first letter to be encrypted, and the column with the first letter of the keyword. The ciphertext letter is located at the intersection of the row and column. This continues for the entire length of the message.
An Autokey cipher is identical to the Vigenère cipher with the exception that instead of creating a keyword by repeating one word over and over, the keyword is constructed by appending the keyword to the beginning of the actual plaintext message.
For example, if your plain text message was:
This is a secret message And your keyword was "zebra", then your actual keyword would be:
zebrathisisasecretmessage Enciphering and deciphering the message is performed using the exact same method as the Vigenère Cipher.

  

Running Key Cipher

To encrypt a plaintext message using the Vigenère Cipher, one locates the row with the first letter to be encrypted, and the column with the first letter of the keyword. The ciphertext letter is located at the intersection of the row and column. This continues for the entire length of the message.
In a Running Key cipher, the keyword is the text of a predetermined book or passage. For example, if the chossed book was "A Tale of Two Cities" by Charles Dickens, then the keyword would be
It was the best of times, it was the worst of times... Enciphering and deciphering the message is performed using the exact same method as the Vigenère Cipher.
If the predetermined passage is a string of random letters that is only used once and then discarded, this is similar to a One-time Pad.
Running key code chart



Rail Fence

In the rail fence cipher, the plaintext is written downwards on successive "rails" of an imaginary fence, starting a new column when the bottom is reached. The message is then read off in rows. For example, if we have 3 rails and a message of "This is a secret message", you would write out:
T S A C T S G
H I S R M S E
I S E E E A J
The last J is just a random letter to fill in the space. The secret message is then condensed and regrouped.
TSACT SGHIS RMSEI SEEEA JGURL
To decipher a message you must know the number of rails that were used to encipher it. You then break up the letters into equal groups for each rail. For example, if you are using 3 rails, you would break the secret message into 3 equal groups. Now you stack the groups on top of each other and read off the message vertically. If you get gibberish, then there are probably some extra letters tacked on the end of the message that are throwing off the grouping. Try removing one letter from the end and try again.



Route Cipher

A Route Cipher is very similar to a Rail Fence cipher with one exception. You still write the message vertically in columns, but instead of reading off the secret message horizontally, you read it off using a predetermined pattern. For example, lets use a spiral pattern for this one:
T S A C T S G
H I S R M S E
I S E E E A J
The last J is just a random letter to fill in the space. If we are using a clockwise spiral to read off the message, then it becomes:
TSACTSGEJAEEESIHISRMSE
A more complex pattern could be, "every other letter going backwards to the front and then every other letter going forwards to the end again", which would give you a secret message of:
JEEISRIGTATSCSHSMESEA
The complex pattern makes this algorithm difficult to decipher unless you know the key.


Columnar Transposition

In a columnar transposition, the message is written out in rows of a fixed length. The message is then read out by column by column, where the columns are chosen in some scrambled order. The number of columns and the order in which they are chosen is defined by a keyword. For example, the word ZEBRAS is 6 letters long. Therefore, there are 6 columns that will be read of in the following order: 6 3 2 4 1 5. The order is chosen by the alphabetical order of the letters in the keyword.
Regular Case
In a regular columnar transposition cipher, the empty spaces are filled with random letters. For example, suppose we use the keyword ZEBRAS and the message WE ARE DISCOVERED FLEE AT ONCE. Our grid would look like this:
Z E B R A S
6 3 2 4 1 5
- - - - - -
W E A R E D 
I S C O V E 
R E D F L E 
E A T O N C 
E Q K J E U 
The six columns are now written out in the scrambled order defined by the keyword:
EVLNE ACDTK ESEAQ ROFOJ DEECU WIREE
Irregular Case
In the irregular case, the empty letters are not filled in with random letters:
Z E B R A S
6 3 2 4 1 5
- - - - - -
W E A R E D 
I S C O V E 
R E D F L E 
E A T O N C 
E 
This results in the following (shorter) ciphertext:
EVLNA CDTES EAROF ODEEC WIREE
To decipher it, the recipient has to work out the column lengths by dividing the message length by the key length. This step is slightly more difficult if the irregular case is used. After determining the number of columns, the message can be written in columns and rearranged back into the plaintext message.
Double Column Transposition
To make the message even more difficult to decipher, you can take the ciphertext produced by this algorithm and run it through the encryption again using a different keyword. This transposes the columns twice and makes the message extremely difficult to decipher.


Playfair Cipher

The Playfair cipher encrypts pairs of letters (digraphs), instead of single letters. This is significantly harder to break since the frequency analysis used for simple substitution ciphers is considerably more difficult.
Memorization of the keyword and 4 simple rules is all that is required to create the 5 by 5 table and use the cipher.
K E Y W O
R D A B C
F G H I J
L M N P S
T U V X Z
The Playfair cipher uses a 5 by 5 table containing a key word or phrase. To generate the table, one would first fill in the spaces of the table with the letters of the keyword (dropping any duplicate letters), then fill the remaining spaces with the rest of the letters of the alphabet in order (to reduce the alphabet to fit you can either omit "Q" or replace "J" with "I"). In the example to the right, the keyword is "keyword".
To encrypt a message, one would break the message into groups of 2 letters. If there is a dangling letter at the end, we add an X. For example. "Secret Message" becomes "SE CR ET ME SS AG EX". We now take each group and find them out on the table. Noticing the location of the two letters in the table, we apply the following rules, in order.
  1. If both letters are the same, add an X between them. Encrypt the new pair, re-pair the remining letters and continue.
  2. If the letters appear on the same row of your table, replace them with the letters to their immediate right respectively, wrapping around to the left side of the row if necessary. For example, using the table above, the letter pair GJ would be encoded as HF.
  3. If the letters appear on the same column of your table, replace them with the letters immediately below, wrapping around to the top if necessary. For example, using the table above, the letter pair MD would be encoded as UG.
  4. If the letters are on different rows and columns, replace them with the letters on the same row respectively but at the other pair of corners of the rectangle defined by the original pair. The order is important - the first letter of the pair should be replaced first. For example, using the table above, the letter pair EB would be encoded as WD.
To decipher, ignore rule 1. In rules 2 and 3 shift up and left instead of down and right. Rule 4 remains the same. Once you are done, drop any extra Xs that don't make sense in the final message and locate any missing Qs or any Is that should be Js.


Bifid Cipher

The Bifid Cipher uses a Polybius Square to encipher a message in a way that makes it fairly difficult to decipher without knowing the secret. This is because each letter in the ciphertext message is dependent upon two letters from the plaintext message. As a result, frequency analysis of letters becomes much more difficult.
12345
1ABCDE
2FGHIK
3LMNOP
4QRSTU
5VWXYZ
The first step is to use the Polybius Square to convert the letters into numbers. We will be writing the numbers vertically below the message.
secret message
411414 3144121
353254 2533125
The numbers are now read off horizontally and grouped into pairs.
41 14 14 31 44 12 13 53 25 42 53 31 25
The Polybius Square is used again to convert the numbers back into letters which gives us our ciphertext.
qddltbcxkrxlk
Since the first letter in the plaintext is encoded into the first and middle letters of the ciphertext, the recipient of the message must have the entire message before they can decode it. This means that if part of the ciphertext is discovered by a third party, it is unlikely that they will be able to crack it.
To decipher a Bifid encrypted message, you first convert each letter into its corresponding number via the Polybius Square. Now, divide the long string of numbers into two equal rows. The digit in the top row and the digit in the bottom row will together reference the decoded letter in the Polybius Square.
The Bifid Cipher can be taken into three dimensions to slightly increase the security of the message. This new cipher is called the Trifid Cipher.


Trifid Cipher

The Trifid Cipher is the Bifid Cipher taken to one more dimension. Instead of using a 5x5 Polybius Square, you use a 3x3x3 cube. Otherwise everything else remains the same. As with the Bifid Cipher, the cube can be mixed to add an extra layer of protection, but for these examples we not be using a mixed alphabet cube.
Layer 1
123
1ABC
2DEF
3GHI
Layer 2
123
1JKL
2MNO
3PQR
Layer 3
123
1STU
2VWX
3YZ.
The first step is to use the cube to convert the letters into numbers. We will be writing the numbers vertically below the message in the order of Layer, Column, Row.
secret message
311213 2133111
123322 1211112
121321 2211132
The numbers are now read off horizontally and grouped into triplets.
311 213 213 311 112 332 212 111 121 213 212 211 132
The cube is used again to convert the numbers back into letters which gives us our ciphertext.
sppsdxmabpmjf
To decipher a Trifid encrypted message, you first convert each letter into its corresponding number via the cube. Now, divide the long string of numbers into three equal rows. Now, read off each column and use the cube to convert the three numbers into the plaintext letter.

Four-square Cipher

The four-square cipher encrypts pairs of letters (digraphs) and is thus less susceptible to frequency analysis attacks.
The four-square cipher uses four 5 by 5 matrices arranged in a square. Each of the 5 by 5 matrices contains the letters of the alphabet (usually omitting "Q" or putting both "I" and "J" in the same location to reduce the alphabet to fit). In general, the upper-left and lower-right matrices are the "plaintext squares" and each contain a standard alphabet. The upper-right and lower-left squares are the "ciphertext squares" and contain a mixed alphabetic sequence.
a b c d e   E X A M P
f g h i j   L B C D F
k l m n o   G H I J K
p r s t u   N O R S T
v w x y z   U V W Y Z
 
K E Y W O   a b c d e
R D A B C   f g h i j
F G H I J   k l m n o
L M N P S   p r s t u
T U V X Z   v w x y z
To generate the ciphertext squares, one would first fill in the spaces in the matrix with the letters of a keyword or phrase (dropping any duplicate letters), then fill the remaining spaces with the rest of the letters of the alphabet in order. The four-square algorithm allows for two separate keys, one for each of the two ciphertext matrices. In the example to the right, "EXAMPLE" and "KEYWORD" have been used as keywords.
To encrypt a message you would first split the message into digraphs. "This is a secret message" would become:
TH IS IS AS EC RE TM ES SA GE
a b c d e   E X A M P
f g h i j   L B C D F
k l m n o   G H I J K
p r s t u   N O R S T
v w x y z   U V W Y Z
 
K E Y W O   a b c d e
R D A B C   f g h i j
F G H I J   k l m n o
L M N P S   p r s t u
T U V X Z   v w x y z
Once that was complete, you would take the first pair of letters and find the first letter in the upper left square and the second letter in the lower right square. In this example we are enciphering TH, so we locate T and H in the grid below (see blue characters). Now, we find the intersections of the rows and columns of the plain text letters. In this example, they have been highlighted in red (R and B). These new letters are the enciphered digraph (RB).
You continue enciphering digraphs in this way until you reach the end of the message. To continue our example, "This is a secret message" would be enciphered as:
RB CP CP AL AO TE RI AS NY FE

Source:wikipedia






No comments:

Post a Comment