Let’s understand vernam cipher algorithm for encryption and decryption of plain text and implement the vernam cipher python program using functions, for and while loops.

#### What is Vernam Cipher Algorithm?

The vernam cipher algorithm was developed by **Gilbert Vernam** at AT&T in 1917. It is basically an encryption and decryption algorithm. It is one of the best and unbreakable cryptosystems.

Let us also look at what is cipher exactly. A cipher is a way of encryption a** text-based format**. To add to it, a stream cipher is a cipher which encrypts variable length text or message.

**Vernam Cipher Definition**

The Vernam Cipher Algorithm is a stream cipher, which is symmetrical and, the plaintext is combined with a random stream of data of the same length using the boolean XOR function.

The boolean XOR function is also known as boolean exclusive OR function. The vernam cipher algorithm is also known as **One – Time Pad**.

The vernam cipher algorithm in python enlisted here is really strong in terms of hacks or loopholes just because the algorithm itself is very strong.

**Must Read: Caesar Cipher Encryption Algorithm C Program**

Gilbert Vernam proposed a bit-wise exclusive OR of the stream with a random zero-one stream which is shared by the recipient and the sender.

#### Vernam Cipher Example

Enter a Text: CodingAlpha.com

Vernam Cipher Encrypted Text: ” 8^Q\Y

Vernam Cipher Decrypted Text: CodingAlpha.com

#### Advantages

1. This algorithm does not offer any chance of leaking the key or the original plain text entered by the user.

2. It is really hard to break into the system. Only guesswork can help an attacker, which is very rare.

#### Disadvantages

There’s one disadvantage of vernam cipher algorithm which is that the encryption key used is too large than usual public and private keys.

**Note:** This Python code for Vernam Cipher Algorithm is developed using IDLE Python 3.6 32-bit version on Microsoft Windows 10 operating system.

#### Python Program For Vernam Cipher Program For Encryption and Decryption

def VernamCipherFunction(text, key): result = ""; ptr = 0; for char in text: result = result + chr(ord(char) ^ ord(key[ptr])); ptr = ptr + 1; if ptr == len(key): ptr = 0; return result encryption_key = "abcdexyzmnop234"; while True: input_text = input("\nEnter Text To Encrypt:\t"); encryption = VernamCipherFunction(input_text, encryption_key); print("\nEncrypted Vernam Cipher Text:\t" + encryption); decryption = VernamCipherFunction(encryption, encryption_key); print("\nDecrypted Vernam Cipher Text:\t" + decryption);

#### Output

Let’s discuss more on vernam cipher python program in the comment section below if you have any compilation errors and any doubts about the same. For more information on Simpson’s integration methods, check **Wikipedia**.

Thank you so much for explaining the vernam cipher algorithm so beautifully.

RSA Encryption, DES and so many other encryption algorithms are there. Which one is the best?

THank you so much! FInally I got a working code.

Perfect! Thanks!