## Algorithms and Cryptography

Algorithms and Cryptography are First things; before I proceed and start boasting about myself and convert this blog into a boring one side conversation, lets first understand what Algorithms are and how are they related to Cryptography.

### Algorithms

For those of you who think Algorithms is only connected to computer science, you are wrong. An algorithm is a method or a formula for solving a problem. And when I say problem, it can be any type of problem, may it be Math, Science formulas or even computer-based. Let me give you a simple

**Example:**

(A+b)^{2} = a^{2} +2ab + b^{2}

**Or it can be like:**

Accrued Amount = Principal (1 + R.O.I*100*time)

Yes! Everything that is a formula can be taken as an Algorithm. An algorithm is a set of rules for solving a problem, which, if done properly, will give a correct answer each time. Algorithms generally involve repeating a series of steps over and over, as in the borrowing and carrying algorithms and in the long multiplication and division algorithms. Algorithms include a variety of addition, subtraction, multiplication and division.

But before you start thinking that I am taking some kind of Math lecture here, let me tell you that I am not. I am here to talking about Algorithms and Cryptography related to Computer Science. But before I proceed with that, let me give you some examples of simple algorithms to get started with.

These examples are for pure noobs who have never done any kind of algorithmic stuff in their entire life. So, if you think you are smart enough, you can skip to the next section of Cryptography, where I would be again introducing some basics before moving on to the next level.

So, here are a few examples of Addition Algorithms, which will get you started for now and give an idea as to how algorithms are. Letâ€™s start with basic Math:

#### Left to Right Addition Algorithms

Starting at the left, add column-by-column, and adjust the result.

For some people, this process becomes so automatic that they start at the left and write the answer column by column, adjusting as they go without writing any in-between steps. If asked to explain, they say something like this:

200 plus 400 is 600, but (looking at the next column) I need to adjust that, so write 7. Then, 60 and 80 is 140, but that needs adjusting, so write 5. Now, 8 and 3 is 11, no more to do, write 1. This technique easily develops from experiences with manipulatives, such as base-10 blocks and money, and exchange or trading games, and is consistent with the left-to-right patterns learned for reading and writing.

Now some people may go all over nuts when reading about this. So, you may need to Google this stuff out to get an exact idea as to what is exactly happening over here.

### Cryptography for Algorithms and Cryptography

Cryptography is the art of writing codes in a non-human readable manner. It is a method of storing and transmitting data in a particular form so that only those for whom it is intended can read and process it. You can say that Cryptography is a close cousin to the disciplines of cryptology and cryptanalysis.

Cryptography includes techniques such as microdots, merging words with images, and other ways to hide information in storageÂ or transit. However, in today’s computer-centric world, cryptography is most often associated with scrambling plaintext (ordinary text, sometimes referred to as cleartext) into ciphertext (a process called encryption), then back again (known as decryption). Individuals who practice this field are known as cryptographers.

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

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.

**1. Ceaser Cipher**

A Caesar cipher is one of the simplest (and easiest cracked) encryption methods. A Substitution Cypher 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 directly translates 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.

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

**2. Atbash Cipher**

The Atbash cipher is a particular case of a substitution cipher where the alphabet letters are reversed. In other words, all as are replaced with Zs, all Bs are replaced with Ys, and so on.

Because reversing the alphabet twice will get you the 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

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 alphabet’s remaining unused letters.

*ABCDEFGHIJKLMNOPQRSTUVWXYZ*

*KEYWORDABCFGHIJLMNPQSTUVXZ*

To encipher a plaintext message, you convert all letters from the top row to their corresponding letter on the bottom row (A to K, B to E, etc.).

Using frequency analysis and some educated guessing can easily crack these types of simple substitution ciphers.

**4. 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.

#### 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.

**Recommended courses**

- Training on XML
- CCNA Exam Training Course
- Complete UNIX & Linux OS Training
- HTML 5 Training Bundle

**1. Vigenere Cipher**

In a Caesar Cipher, each letter of the alphabet is shifted along with 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.

To encipher, a table of alphabets can be used, termed tabula recta, Vigenere square, or Vigenere 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

Finding the ciphertext letter’s position in a row of the table and then taking the label of the column in which it appears as the plaintext perform decryption. For example, in row L, the ciphertext L appears in column A, which taken as the first plaintext letter. Looking up X in row E of the table decrypts the second letter; it appears in column T, which is taken as the plaintext letter.

A Gronsfeld cipher is identical to the Vigenere cipher with the exception that only 10 rows are used, which allows the keyword to be a number instead of a word.

### Steganography for Algorithms and Cryptography

Steganography is actually the science of hiding information from people who would snoop on you. The difference between this and encryption is that the would-be snoopers may not be able to tell there’s any hidden information in the first place.

As an example, picture files typically have a lot of unused space in them. This space could be used to send hidden messages. If you do encryption research, you may see the term steganography used on occasion. However, it is not true encryption (though it can still be quite effective), and as such, I only mention it here for completeness.

So, basically, if you want to start practising cryptology, the best way to get started would be to start solving algorithms and Ciphertext along with Steganography. Even though Steganography may seem easy and it is not true encryption, it is still one of the most used encryption when it comes to basics and when you need to code something in very little time and in the best way possible.

### Recommended Articles

Here are some articles that will help you to get more detail about Algorithms and Cryptography, so just go through the link.

- Data Structures And Algorithms Interview Questions
- Algorithm Interview Questions
- learning Algorithms
- Data Structures and Algorithms

Â Â 600+ Online CoursesÂ |Â Â 3000+ Hours |Â Â Verifiable Certificates |Â Â Lifetime Access

4.6

View Course

Related Courses