Implementation of Vigenère Cipher on Raspberry Pi Pico C++
by Northstrix in Circuits > Raspberry Pi
1260 Views, 7 Favorites, 0 Comments
Implementation of Vigenère Cipher on Raspberry Pi Pico C++

I've been browsing the web looking for Raspberry Pi Pico projects written in C++. There were lots of good projects written in Python, but there were few written in C++. I've decided to fix the situation by making a project written in C++.
What Is Vigenère Cipher
Vigenère Cipher is a polyalphabetic cipher. Unlike monoalphabetic ciphers, polyalphabetic ciphers are using multiple alphabets. Using multiple alphabets allows polyalphabetic ciphers to produce a ciphertext in which the frequency distribution of the ciphertext can be different from the frequency distribution of the plaintext. That makes a polyalphabetic cipher invulnerable to frequency analysis.
You can read about Vigenère Cipher and its implementation in C++ here: https://www.journaldev.com/43346/vigenere-cipher
Encryption


Find an intersection between the letter of the plaintext and the letter of the key. That will be the letter of the ciphertext.
Mathematically it will look like this: Ci = (Mi +Ki) mod 26
Example:
Plaintext: RASPBERRYPIPICO
Key: YOULLNEVERGUESS
Ciphertext: POMAMRVMCGOJMUG
Decryption


Find the column that has the letter of the key on top of it, then get down until you encounter the letter of the ciphertext. The first letter of that row is a letter of the plaintext.
Mathematically it will look like this: Mi = (Ci - Ki +26) mod 26
Example:
Ciphertext: POMAMRVMCGOJMUG
Key: YOULLNEVERGUESS
Plaintext: RASPBERRYPIPICO
Connect the Display to the Raspberry Pi Pico

Download the Firmware
You can download the firmware here: https://github.com/Northstrix/Vigenere-Cipher-on-R...
Flash the Raspberry Pi Pico

If you've never flashed Raspberry Pi Pico in Arduino IDE before, you can read how to configure the IDE here: https://www.instructables.com/How-to-Use-Raspberry...
Fixing Broken Conversion

Unfortunately, Raspberry Pi Pico support in Arduino IDE is still raw, and even some basic features might not work correctly. As it turned out, explicit conversion from integer to char doesn't always work. I've already fixed it in the code on Github. Just beware that you can sometimes encounter an error in a fully working code.
Test the Encryption

To encrypt the plaintext open the Serial Monitor, then enter 1 and press "Enter".
You can now enter the message. Let's encrypt RASPBERRYPIPICO using the key YOULLNEVERGUESS. By the way, make sure there are no spaces in the message. Also, the key length has to be at least the same length as the message, otherwise, only part of the message will be encrypted.
Test the Decryption

To decrypt the ciphertext open the Serial Monitor, then enter 2 and press "Enter".
Let's decrypt POMAMRVMCGOJMUG using the key YOULLNEVERGUESS.
As you can see, both encryption and decryption work fine.