Introduction: Vigenere Cipher With Arduino

Picture of Vigenere Cipher With Arduino

Few years ago, Digital Fortress by Dan Brown caught my attention and one particular thing stuck on my mind. Kryptos, the sculpture by Jim Sanborn which consists of ciphered text of which the first two parts are encrypted by Vigenère cipher. I started tapping into cryptography and found out how much fun it is (Dan Brown's fans will sure understand). This program allows you to encrypt/decrypt text using a keyword.

Step 1: Technique

Picture of Technique

Tabula recta is used to encrypt/decrypt the plain text/cipher. It consists of the alphabet written out 26 times in different rows, each alphabet shifted cyclically to the left compared to the previous alphabet. As the cipher should use only English alphabet, there are few limitations/workarounds use in the code.

Let's dig in!

Let's say we want to encrypt text "INSTRUCTABLES IS FUN", using keyword "ROBOT". The keyword is repeated until it matches the length of the plain text. When we start with the first letter from the plain text "I" and from the keyword "R", using the tabula recta (see the picture), we can see that the first letter of cipher is "Z".

Plain text: INSTRUCTABLES IS FUN
Keyword: ROBOTROBOTROBOTROBOT
Cipher: ZBTHKLQUOUCSTWLWIO

Repeat this for every following letter and you got your first cipher! Or use the code to get there much faster :)

Step 2: The Code

Picture of The Code

ACSII table:
There were few issues that had to be dealt with. I had to make sure the code will work both way for encryption and decryption and that needed some logic behind ASCII table.

As an example we are using the same letters from previous case - "I" for plain text and "R" for keyword.

Encryption:

input = inputStr[i];
keyword = keyStr[j];

//get the order in the alphabet for input and keyword (8+17), therefore the output is 25
output = (((input - 65) + (keyword - 65)));
if (output > 25) {
//we have to be careful not to overstep the ASCII limits
and stay within 65-90
output = output + 39;
}
else {
//get the letter from the ACSII (25+65=90 which corresponds with the letter "Z")
output = output + 65;
}
Serial.write(output);
i++;
j++;


Decryption:

input = inputStr[i];
keyword = keyStr[j];
//get the order in the alphabet for input and keyword (25-17), therefore the output is 8
output = (((input - 65) - (keyword - 65)));
if (output < 0) {

//we have to be careful not to overstep the ASCII limits and stay within 65-90
output = output + 91; }
else {
//get the letter from the ACSII (8+65=73 which corresponds with the letter "I")
output = output + 65;
} Serial.write(output);
i++;
j++;


Do's and dont's:

  • text and keyword is automatically changed to upper case
  • white spaces (space, tab, enter) in the text are allowed but the cipher will be without them
  • other than English alphabet letters (numbers, commas, etc.) will stay in the cipher as they were, therefore it is better to avoid using them and use, e.g. "FIVEFORTYSEVEN" instead of "5:47" if you want your cipher to be really hard to crack
  • keyword may contain only letters, otherwise you might get a nondecryptable nonsense


Step 3: That's It!

Picture of That's It!

Fire up Arduino IDE, connect your Arduino board, change the baud rate to correspond with your board, upload the code and open serial monitor. Simple menu will let you choose whether you want to encrypt or decrypt. That's it!

Now you can text your friends, backup all your passwords and hide them on plain sight (e.g. as a poster) knowing only you (assuming you will not use simple pass) can crack it. :)

What is next?

I plan to implement an option where you will be able to insert your own tabula recta in the same way as Jim Sandborn did in his scupture. Theory is done, now I have to figure out the rest. As always, if you like this Instructable, please leave a short comment. Thank you!

Comments

kirthik vasan (author)2017-11-11

that is intresting....

About This Instructable

215views

11favorites

License:

Bio: Technology geek, love discovering new possibilities...
More by PraetorianCZ:Vigenere Cipher With ArduinoTerraControl V3.0 - ESP8266 + BLYNKMotion Detector With Blynk Notifications (WeMos D1 Mini + HC-SR04)
Add instructable to: