C++ Tutorial: Caesar cipher | encryption and decryption (Very easy)

in #programming6 years ago

Hey!
Hope you will like this short tutorial. :)

Programs used:

IDE: http://www.eclipse.org/downloads/eclipse-packages/
Compiler: http://www.mingw.org/

Let's start!

We are looking for an encryption like this:

Therefore we need nothing special.
Only 3 variables.

We can also write the code to input our variables.

Now we need a for-loop to go through every letter.
Therefore we declared the variable " inputLength " wich gives us the length of our input with:

In our for-loop we are checking if the current charactere is alphanumeric.

Now we are converting our upper case letters into lower case letters.

In our loop we need another for-loop wich is our displacement.
Inside there we check if the current letter is " z " and if it's true, then convert it to " a ".
That's because we don't want to run out of letters if we reach " z ".

We also add an else statement. In there we are just counting up our input variable.

For the decrypting we are doing almost the same, but instead of counting our input variable up, we are counting it down.

That's it! Hope you like it :)

Sort:  

Yay. Caesar Cipher, one of most basic shift ciphers. Unfortunately this cipher is very, very weak especially for longer texts, because you can easily deduce which letter has the place of another.

Still - I like your post and fact that you implemented that in C++. Cheers!

Great that you like it :)

Coin Marketplace

STEEM 0.18
TRX 0.14
JST 0.030
BTC 58679.35
ETH 3155.04
USDT 1.00
SBD 2.44