5 Ways to Relieve Baby of Gas Pain

As soon as baby starts to feed and explore his taste buds, parents start to worry about which food will be good for their baby’s little tummy. Gas pain in babies is common. Sometimes it’s because of…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




The Caesar Cipher

In the following example, I’m going to encrypt a message with a key of 2. This means that in order to decrypt a message, you have to shift the alphabet left or right. The key specifies how much you have to shift. Let’s take right shift decryption, for example, C becomes A and G becomes E. I think there is not much to explain the example is pretty straightforward.

If you’re not a programmer or new to programming, don’t worry I try to explain how the code works.

The encrypt(message, key) method takes two parameters. One is your message, the other is the key. I tried to eliminate some special characters from the supplied message, but it’s far from complete. Next, the loop goes through the message character by character and if the current character is not in the alphabet, then simply append the char to the encrypted message without tampering it. I needed the index of the character in the alphabet. I used it to calculate the shifted index by adding the key to the index and using the modulo operator which gives the remainder of the division with the length of the alphabet.

As you can see the decrypt(message, key) method has only one difference compared to the encrypt(message, key) method and that is the key subtraction from the letter index in the alphabet. Everything is else is exactly the same.

I created a gist on Github, so you can download and try the whole program.

Thank you for taking the time to read my article. If you found it helpful, please hit the 👏 button 👏 (up to 50x) and share it to help others with similar interest find it! + Feedback is always welcome! 🙏

Add a comment

Related posts:

Applying to College

So you are applying to college, scholarships etc. It’s a stressful time and it can feel super overwhelming. So here is some free advice in a step-by-step format. I want to preface this by saying you…