Banana encryption: Decoding Caesar Cipher with Power Automate

Bala Madhusoodhanan - Feb 5 - - Dev Community

Intro:
Lets dive on mischievous world of Minions and the ancient art of encryption. Julius Caesar, the original mastermind behind a secret language Caesar cipher. It encrypts letters by shifting them over by a certain number of places in the alphabet. We call the length of shift the key. For example, if the key is 3, then A becomes D, B becomes E, C becomes F, and so on.

Logic:
The process of encrypting messages in Power Automate involves taking the user's input message and a secret key. Initially, the user's message is converted to uppercase, and the length of the secret key is recorded for subsequent steps.

toUpper(triggerBody()['text'])
Enter fullscreen mode Exit fullscreen mode

To execute the encryption, a scale or array is necessary, containing all the alphabets, spaces, and numbers. A new variable is introduced to iterate through each character of the user's message and offset it based on the key length.

length(triggerBody()['text_1'])
Enter fullscreen mode Exit fullscreen mode

To facilitate the offset process, the user's message is divided into an array of characters using the Chunk function.

chunk(outputs('UsrInput'),1)
Enter fullscreen mode Exit fullscreen mode

The offset logic consists of two main steps. First, the index of each character in the user's message is found against the fixed list of characters.

indexof(outputs('Alphastring'),items('Apply_to_each'))
Enter fullscreen mode Exit fullscreen mode

Subsequently, the lookup is offset by the length of the character

chunk(outputs('Alphastring'),1)[add(outputs('GetIndex'),outputs('Key'))]
Enter fullscreen mode Exit fullscreen mode

The final step involves appending the variable after each character is successfully offset, completing the encryption process.

Demo:

Encrypt

User Input Key Encrypt Output
"Good Morning " CAT JRRG2PRUQLQJ2
"Good Morning" CAT JRRG2PRUQLQJ
"Good Morning" encrypt NVVK6TVYUPUN

I hope you had a good time learning about encryption and how to use Power Automate for it. Happy coding!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .