# Vernam Cipher in Cryptography

**Vernam Cipher** is a method of encrypting alphabetic text. It is one of the Substitution techniques for converting plain text into cipher text. In this mechanism we assign a number to each character of the Plain-Text, like (a = 0, b = 1, c = 2, … z = 25).

**Method to take key: **In the Vernam cipher algorithm, we take a key to encrypt the plain text whose length should be equal to the length of the plain text.

**Encryption Algorithm:**

- Assign a number to each character of the plain-text and the key according to alphabetical order.
- Bitwise XOR both the number (Corresponding plain-text character number and Key character number).
- Subtract the number from 26 if the resulting number is greater than or equal to 26, if it isn’t then leave it.

**Example 1:**

Plain-Text:O A KKey:S O N

O ==>14 =0 1 1 1 0S ==>18 = 1 0 0 1 0Bitwise XOR Result: 1 1 1 0 0 = 28

Since the resulting number is greater than 26, subtract 26 from it. Then convert the Cipher-Text character number to the Cipher-Text character.

28 - 26 = 2 ==> CCIPHER-TEXT: C

Similarly, do the same for the other corresponding characters,

PT:O A KNO:14 00 10KEY:S O NNO:18 14 13

New Cipher-Text is after getting the corresponding character from the resulting number.

CT-NO:02 14 07CT:C O F

**Example 2:**

Plain-Text:RAMSWARUPKKey:RANCHOBABA

Now according to our encryption algorithm, we assign a number to each character of our plain text and key.

PT:R A M S W A R U P KNO:17 0 12 18 22 0 17 20 15 10KEY:R A N C H O B A B ANO:17 0 13 2 7 14 1 0 1 0

Now Bitwise XOR the number of Plain-Text and Key and after doing the XOR operation and subtraction operation (if required), we will get the corresponding Cipher-Text character number.

CT-NO:0 0 1 16 17 14 16 20 14 10

Since there are no numbers that are greater than or equal to 26 we do not have to subtract 26 from any of them.

New Cipher-Text is after getting the corresponding character from the number.

CIPHER-TEXT:A A B Q R O Q U O K

Note:For theDecryptionapply the just reverse process of encryption.