Encrypt and Decrypt Caesar Cipher in Excel using Power Query

in #excel5 years ago (edited)

Over the last few months, I have found myself interested in cryptography. Cryptography is the art of writing and solving clues. Often solving clues involves decrypting some sort of hidden message. Encrypting and decrypting messages is a lot of fun.

A cipher is a series of steps taken to encrypt or decrypt a message that you might want to hide. One of the earliest known ciphers is Caesar Cipher.  Julius Caesar used this to hide military messages.  It’s a basic form of encryption where the letters were simply shifted by 3 back down the alphabet.  Now a day’s early school kids crack codes like this with ease.  However, it has lead to more secure encryptions such as Vigenère cipher and ROT13.

Excel is no match for most programming languages and many ciphers require multiple iterations and even processing power.  However, I wanted to see if I could create a Shift Caesar Cipher in Excel without the use of VBA (before I go on and try some more complicated ones), that could both encrypt and decrypt string text with ease.

A Google search did turn up some good results, however, these were rather old and did not make use of Excel Power Tool functionalities. So, to modernize the resources out there, I have created a Ceaeser Cipher using Excel and Excels Power Query in Office 365.  In this model, you can both encrypt and decrypt a text string using an alphabet shift.

You can download the Excel model at the end of this post.

Encrypting with Shift Cipher in Excel

Ceaser Cipher in Excel

To encrypt text with a shift Caeser cipher in Excel, we must first complete the blue input cells.   I have set the input cells up as tables as they will be used to load data into power query and drive formulas.

The first table is Text, in which we enter the text you wish to encrypt. 

The second table is where you define the number of letters to shift the text. On the decryptions side, this set up to shift forward or move up the alphabet.  On the encryptions side, it is set to shift back down the alphabet.

Once you have completed the inputs, to encrypt your text, select Refresh ALL twice from the data ribbon. 

Ceaser Cipher in Excel

The output table will populate with the encrypted text and the check table will output a reverse so you can ensure you have done the right thing.

Caeser Cipher in Excel- How it works

On the worksheet Encrypt workings, we have the workings to encrypt the text by shifting the letters by the specified number. The encryptions side will shift the letter to the left, or down the alphabet and the decryptions side will shift the letter to the right, or up the alphabet.

In columns A:B we have our reference table.  Down the rows of column A is each letter of the alphabet.  Column B uses the OFFSET function to create a restructured alphabet based on the shift.  In this example, we have 5 of a shift so f becomes a and so forth.

Ceaser Cipher in Excel

In column E we have a table returned by Power Query.  we created this table by loading the Text table from the inputs into power query on refresh.  It then splits the text by character and transposed it from a column to a row.  Each character of text is now in a cell going down a column. This table is loaded into Excel.

Column G, Return, then carries out a VLOOKUP, referencing the Alphabet table, returning the shifted letters.  This VLOOKUP is combined with other functions to account for spaces, punctuations, and errors. This same table is the also loaded to Power Query (on the second refresh).  In power query, the transformations transpose the text from rows to columns and then merges all the columns together.  The transformed table is then loaded back into Excel as the output table. 

The model also has a built in check. Columns J & K reverse the shift used on the alphabet.  This is then used to create the check column (column m) with the use of VLOOKUPS. This table is then loaded into power query where it is transposed and the columns combined to return the check output table on the main sheet.

Ceaeser Cipher in Excel-Model Limitations

The table with the text is first loaded to power query when we press refresh.  This returns a table in the workings sheet that drives the next table, which is also loaded into power query.  Therefore, we will need to refresh 4 times to account for the iterations.

There is also a limit of to plain or ciphertext of 90 characters in this model.  To increase this limited, you will need to edit the queries to account for the merge of the additional new columns.

Learn and Earn Activity

Decrypt the following piece of ciphertext. Comment below with the hidden message

extkg tgw xtkg hyyxk : 50% vtla wblvhngm hg tgr  mktbgbgz vhnklxl yhk hger 10 lmxxf    

(you may have to try multiple shifts before you find the correct answer)

If you have any questions, comments or more efficient steps, please do drop me a comment below.  It might also be worth a reward!!!!!

Sign up for my newsletter – Don’t worry, I won’t spam. Just useful Excel and Power BI tips and tricks to your inbox with Earn and Learn activities.SIGN UP NOW

learn and earn steem activity

Now there is value in Learning with The Excel Club and our Learn and Earn STEEM activities.

We are the first Excel, PowerBI and DAX blog in the world where you can Earn while you Learn.

To Find out more now and start earning while you are learning Excel and Power BI

DOWNLOAD Caeser Cipher Excel Model



Posted from my blog with SteemPress : http://theexcelclub.com/encrypt-and-decrypt-ceaser-cipher-in-excel-using-power-query/
Sort:  

I've recently come across some decryption in the satoshi treasure hunt where I had no idea where to start. As you have said here it is not suitable for more serious codes but I think this will really help with parts of it.

I will come back to this great post to reference it for the next time and have to go to try and solve your code now for practice. This might take a while but it's great to see how many uses you can put excel to. It really is a great tool for anybody to have in their inventory. These posts are always great to learn new skills.

I'm going to try to create some more difficult ones. With the excel power tool, a lot more can be done than before ;-)

Interesting stuff ! Thank you for writing that it's not suitable for anything serious, I too often see people using broken encryption for sensitive data (you wouldn't believe how many websites store password in plain text). Also I think you have a typo in your title, it's caesar not Ceaser :p

why do I think you would make a really good asset to the @steemclan satoshis treasure team???? Have you been invited? if not, would you like to join?

Thanks for visiting @howo - updated the multiple typos, thanks for the heads up

I have not :p but even though I did quite a lot of Cryptography in the past, I'm not a fan of cracking codes like satoshi treasure. It's always fun to see the solution whent hey have cracked it :)

To listen to the audio version of this article click on the play image.

Brought to you by @tts. If you find it useful please consider upvoting this reply.

Coin Marketplace

STEEM 0.29
TRX 0.11
JST 0.031
BTC 69768.04
ETH 3884.71
USDT 1.00
SBD 3.73