anitsh / til

Today I Learn (til) - Github `Issues` used as daily learning management system for taking notes and storing resource links.
https://anitshrestha.com.np
MIT License
78 stars 11 forks source link

Cipher #107

Open anitsh opened 4 years ago

anitsh commented 4 years ago

Resources:

anitsh commented 4 years ago

In cryptography, a cipher (or cypher) is an algorithm for performing encryption or decryption—a series of well-defined steps that can be followed as a procedure. An alternative, less common term is encipherment. To encipher or encode is to convert information into cipher or code. In common parlance, "cipher" is synonymous with "code", as they are both a set of steps that encrypt a message; however, the concepts are distinct in cryptography, especially classical cryptography.

Codes generally substitute different length strings of character in the output, while ciphers generally substitute the same number of characters as are input. There are exceptions and some cipher systems may use slightly more, or fewer, characters when output versus the number that were input.

In the word of digital fraud, to prevent our data many techniques are used to keep our data safe from hackers or any third party. In this article, we are going to discuss the types of cipher. Before that lets first see the meaning. Plain text is the message or data that can be readable by the sender, receiver or any third party. When the plain text is modified by using some algorithms or techniques, the resulting data or message is called ciphertext. In short, converting plain text i.e. readable text into non-readable text is called ciphertext.

anitsh commented 4 years ago

Types of Cipher

Caesar Cipher

In Caesar cipher, the set of characters of plain text is replaced by any other character, symbols or numbers. It is a very weak technique of hiding text. In Caesar’s cipher, each alphabet in the message is replaced by three places down. Let’s see one example. The plain text is EDUCBA. As a Caesar cipher, each alphabet is replaced by three-place down, so E will replace by H, D will replace by G, U will replace by X, C will replace by F, B will replace by E and A will replace by D. So here the plain text is EDUCBA and ciphertext Is HGXFED.

Caesar cipher algorithm is as follows:

Read each alphabet of plain text
Replace each alphabet by 3 places down.
Repeat the process for all alphabet in the plain text.

A Modified Version of Caesar Cipher: This cipher works the same as Caesar cipher, the only difference is – in Caesar cipher, each alphabet is replaced by three-place down wherein a modified version of Caesar cipher, the number is decided by a user to replace the alphabet and this number will be constant. For example, EDUCBA and number for the replacement are 1, so E will replace by F, D will replace by E, U will replace by V, C will replace by D, B will replace by C and A will replace by B. So here the plain text is EDUCBA and ciphertext Is FEVDCB.

A modified version of the Caesar cipher algorithm is as follows Read each alphabet of plain text Take the number for replacement Replace each alphabet by specified number down. Repeat the process for all alphabet in the plain text.

Monoalphabetic Cipher

As Caesar cipher and a modified version of Caesar cipher is easy to break, monoalphabetic cipher comes into the picture. In monoalphabetic, each alphabet in plain text can be replaced by any other alphabet except the original alphabet. That is A can be replaced by any other alphabet from B to Z. B can be replaced by A or C to Z. C can be replaced by A, B, and D to z, etc. Mono alphabetic cipher causes difficulty to crack the message as there are random substitutions and a large number of permutation and combination are available.

Homophonic Substitution Cipher

A homophonic substitution cipher is similar to monoalphabetic cipher the only difference is in monoalphabetic we replace the alphabet by any other random alphabet except the original alphabet wherein homophonic substitution cipher, the alphabet is replaced by fixed alphabet or set of alphabet. The substitution alphabet is replaced with te fixed. For example, replace A with x, E with B, S with A, etc. or replace A with E, x or L, B with T, A, Z, etc.

Polygram Substitution Cipher

In polygram substation cipher, rather than replacing each alphabet with another, the Block of alphabets is replaced with another block of alphabets. Replace EDUCBA with XYQLAB. In this case, EDUCBA will replace with XYQLAB, but EDU can be replaced with another set of the block, let’s assume EDU will replace with LOD. In this type of ciphers, the replacement of plain text is done through the block by block rather than character by character.

Polyalphabetic Substitution Cipher

Polyalphabetic Cipher is also known as Vigenere Cipher which is invented by Leon Battista Alberti. In Polyalphabetic Substitution Cipher is a method of encrypting alphabetic texts. It uses multiple substitution alphabets for encryption. Vigener square or Vigenere table is used to encrypt the text. The table contains 26 alphabets written in different rows each alphabet being cyclically shifted to the left in accordance with the previous alphabet, equivalent to the 26 possible Caesar Ciphers. The cipher uses a different alphabet from one of the rows at various points in the encryption process.

Let’s consider Original text is Educba and the keyword is Apple. For the encryption process, The first letter of the original text, E is paired with A, the first letter of the key. So use row E and column A of the Vigenère square, which is E. Similarly, for the second letter of the original text, the second letter of the key is used, the letter at row d and column p is s. The rest of the original text is enciphered in the same way. The final encryption of Educba is Esjnfa.

Playfair Cipher

Playfair cipher is also called as Playfair square. It is a cryptographic technique that is used o encrypt the data. Playfair cipher process is as follows: Creation and population of the matrix. Encryption process. Let’s discussed the above-mentioned steps in detail manner creation and population of the matrix. It uses 5 * 5 matrix to store the keyword or the key which is used for encryption and decryption process. This step is working as follows Enter the keyword in the matrix in a row-wise manner i.e from left to right and top to bottom. Skip the duplicate words in the keyword. Fill the remaining spaces with the rest of the alphabets (A – Z) that were not a part of the keyword.

Note: while doing so combine I and J in the same cell of the table. i.e. If I or J is present in the keyword, discard both I and J while filling the remaining space encryption process. The encryption process works as follows: Break the alphabets into the groups (each group must contain two values). The encryption processes will be performed on these groups. If both alphabets in the group are the same, add x after the first alphabet. If both the alphabet in the group are present in the same row of the matrix, replace them with the alphabets to their immediate right respectively. If the original group is on the right side of the row then wrapping around to the left side of the row happens. If both the alphabet in the group are present in the same column replace them with the alphabets immediate with below respectively. If the original group is on the bottom side of the row then wrapping around to the top side of the row happens. If both the alphabet in the group are not in the same row or column, replace them with the alphabets in the same row immediately but at the other pair of corners of the rectangle which is defined by the original group.

Hill Cipher

Hill cipher works on the multiple alphabets at the same time. Hill cipher works as follows: Assign the number to each alphabet in the plain text. A = 0, B= 1….z = 25 Organize the plain text message as a matrix of numbers base on the above step that is in number format. The resultant matrix is called a plain text matrix. Multiply the plain text matrix with a randomly chosen key. Note that the key matrix must be the size of n*n where n stands for the number of rows in a plain text matrix. Multiply both the matrix i.e. step 2 and step 3. Calculate the mod 26 value of the above matrix i.e. matrix results in step 4. Now translate the numbers to alphabets i.e. 0 =A, 1 =B, etc. The result of step 6 becomes our ciphertext.