Python Software Development

Vigenere Cipher in Python

Vigenere Cipher in Python

Introduction

In cryptography, the Vigenère Cipher is a crucial encryption-decryption technique. The Vigenère Cipher is fundamentally like the Caesar Cipher but significantly more sophisticated. It is used to encrypt plain text messages and decrypt cipher text messages. Here, the original plaintext structure is largely concealed in the cipher text by using numerous monoalphabetic substitution ciphers rather than just one. For each plaintext symbol to be encrypted, the code key defines a precise substitution that must be utilized.

The vigenère cipher algorithm method is used to secure data in the form of digital images, particularly for the corporate logo. It is one of the methods of the science of cryptography that ensures the order logos or digital images are secure while transmission over the Internet.

The Vigenère Cipher is performed as follows:

The Vigenère table is used to encrypt the source text. The best way to create a Vigenère table:

•   The Vigenère table is created with the alphabets written in a row- and column-wise formats.

•    The table cells have been filled with alphabets.

•     Each letter is spelled out 26 times in a distinct row, shifting cyclically to the left from the alphabet before it.

For example, let our plain text be “vigenere cipher”, and the key is “python”.

Encryption

To induce a new key, the given key is repeated circularly, as long as the length of the plain text does not equal the new key.

V

I

G

E

N

E

R

E

C

I

P

H

E

R

P

Y

T

H

O

N

P

Y

T

H

O

N

P

Y

The key's initial letter and the plaintext's first letter are merged. The vigenere table's alphabetic row "P" and column "V" cross at "K," making "K" the initial letter of the ciphertext.

The second letter of the key is coupled with the second letter of the plaintext in a similar manner. The Vigenère table's alphabet "G" is intersected by the plain text "I" column and key "Y" row, therefore the second letter of the ciphertext is "G."

The plaintext is generated continually throughout this process.

Ciphertext = kgzlbrgc vpdutp

This can also be done by using the formula,

Decryption

The row of keys in the Vigenère table performs decryption. Choose the row of the key letter, locate the position of the ciphertext letter in that row, and then choose the label of the ciphertext's corresponding column as the plaintext.

K

G

Z

L

B

R

G

C

V

P

D

U

T

P

P

Y

T

H

O

N

P

Y

T

H

O

N

P

Y

For instance, if the plaintext letter "V" occurs in the first column of the key row "P" and the ciphertext letter "K" appears in the row of the key "P," then the first plaintext letter is "K."

The second plaintext letter is "I" since the row of the key has "Y," the ciphertext is "G," and this ciphertext letter occurs in column "I."

This procedure keeps on till the ciphertext is complete.

Plain text: vigenere cipher

These processes can be done using the formula:

For encryption:

Ei = (Pi + Ki) mod 26

For decryption:

Di = (Ei - Ki + 26) mod 26

Where E represents the encryption, D represents the decryption, P represents the plaintext and K represents the key.