Programming Encryption Algorithms

Computer Science (Caesar Cipher & Vigenere Cipher)

Encryption is the process of converting a plain text message into cipher text which can be decoded back into the original message. While security is an afterthought for many PC users, it’s a major priority for businesses of any size. Encryption is a way to keep your data safe. There are many different encryption algorithms being used today, some of the most regularly used are RSA, Triple DES, Blowfish, and AES. Two of the simplest and most widely known encryption techniques are Caesar Cipher, and Vignere Cipher. The two encryption methods we will focus on in this article are the Caesar Cipher, and Vignere Cipher algorithms.

Caesar Cipher

The Caesar cipher is a type of substitution encryption. It is considered one of the easiest algorithms to implement. It was used by and is named after Julius Caesar. This cipher is however easily broken through different techniques such as frequency analysis.

Substitution encryption is a type of encryption where some letter is replaced by another letter some constant number away.

The action of a Caesar cipher is to replace each plain text letter with a different one a fixed number of places down the alphabet. The cipher illustrated here uses a left shift of three, so that (for example) each occurrence of E in the plaintext becomes B in the cipher text.

How Encryption Works using (Caesar Cipher)

Lets say I want to send a secret message to someone, so I encrypt it using Caesar Cipher.

For instance, below I have an encrypted message using Caesar cipher and a right rotation of twenty three places, or equivalently a left shift of 3 (the “shift”/ “rotation” parameter is called the “key”):

EBIIL COFBKA

Once encrypted, the message becomes slightly unreadable. But, equipped with the secret pass code or “key” I text the sender, s/he can decrypt it and get the original message:key = 3

HELLO FRIEND

So the key was a left shift of 3 or equivalently a right shift of 23. You can see what that looks like for the alphabet below for the matching characters.

Plain Text:    ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher Text: XYZABCDEFGHIJKLMNOPQRSTUVW

Formula:

Encryption Formula
Decryption Formula

Caesar Cipher Program

Here is a video on programming this algorithm using the C — Programming language. You can use this video to create your own encrypted text.

Get the code here: https://github.com/randerson112358/C-Programs/blob/master/caesarCipher1.c

Vigenere Cipher

The Vigenère cipher is a form of polyalphabetic substitution. It is an algorithm of encrypting alphabetic text (e.g. “a” , “b”, “c” etc) by using a series of interwoven Caesar ciphers based on the letters of a keyword. Although Giovan Battista Bellaso had invented the cipher, the Vigenère cipher is named after Blaise de Vigenère.

Polyalphabetic cipher is any cipher based on substitution, using multiple substitution alphabets. Vigenere Cipher is an example of this. A more complex example is the Enigma machine.

How Encryption Works using (Vigenere Cipher)

Lets say I want to send a secret message to someone, so I encrypt it using Vigenere Cipher.

For instance, below I have an encrypted message using the Vigenere Cipher and a key = “ABCD”

CSASTP KV SIQUT GQU CSASTPIUAQJB

Once encrypted, the message becomes slightly unreadable. But, equipped with the secret pass code or “key” I text the sender, s/he can decrypt it and get the original message:key = “ABCD”

CRYPTO IS SHORT FOR CRYPTOGRAPHY

So the key was “ABCD”. You can see what that looks like for the alphabet below for the matching characters.

Key:        ABCDABCDABCDABCDABCDABCDABCD
Plaintext: CRYPTOISSHORTFORCRYPTOGRAPHY
Ciphertext: CSASTPKVSIQUTGQUCSASTPIUAQJB

Formula:

Vigenere Encryption Formula. Ci — i-th character of the ciphertext 
Ti — i-th character of the open text
Ki — i-th character of the key phrase (if the key phrase is shorter than the open text, which is usual, than the keyphrase is reapeated to math the length of the open text) 
m — length of the alphabet
Vigenere Decrypt Formula. Ci — i-th character of the ciphertext 
Ti — i-th character of the open text
Ki — i-th character of the key phrase (if the key phrase is shorter than the open text, which is usual, than the keyphrase is reapeated to math the length of the open text) 
m — length of the alphabet

Vigenere Cipher Program

Vigenere Cipher C Program video.

Get the Code :https://github.com/randerson112358/C-Programs/blob/master/vigenereCipher.c

Conclusion

Learning how these cyphers work can help your understanding of other encryption methods, but I wouldn’t use them if there was something confidential that I wanted to keep away from everyone else, accept maybe a in class love letter. Thanks for reading and I hope you enjoyed this article. Be sure to check out my videos on programming and computer science on YouTube !