# Vigenere Cipher With Arduino

1,625

12

8

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.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: 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

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!

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!

Participated in the
Hiding Places Contest 2017

## Recommendations

• ### Internet of Things Class

22,782 Enrolled

## 8 Discussions

Hi

can you post the code please so that modifications can be tried

6 replies