IN today’s era, where the rise of Information and communication technologies (ICT) which are deeply embedded into the majority has created an exponential increase in development and innovation for our society. According to ‘world bank’ around 40% of the world’s population use the internet today.

/
Source

We use so many devices such as, mobile phones, laptops, printers, emerging Alexa devices which increases our chance of being vulnerable when using these devices to communicate with others. Therefore, companies that produce devices that relies on the internet have to implement a fundamental and crucial system which provides their consumers to be fully secured.

HISTORY

The process of Encryption is one of the main fundamental infrastructures that has been developed way before the information era has risen. Going back to 1900BC where a carved inscription was found in the chambers of the tomb nobleman Khnumhotep II, in Egypt. This field of encryption and decryption comes from the field of cryptography and although it was applied many thousands of years ago by using secret messages, the systematic study of cryptology as a science just started a century ago.

Around 100BC the famous renowned general and a very talented scholar, ‘Julius Caesar’ was also known to use a simple but yet effective encryption to convey the secret messages to his army. Later the cipher itself was named after him which today is called the Caesar cipher.

ENCODING/DECODING STRING USING PYTHON

Using Python, I was able to use the Caesar cipher to develop a simple algorithm that allows a user to encrypt and decrypt a message based on a key. I used python as python provides the ability to easily process data and is much more efficient.

Locks and clouds are shown in a 3D graphic illustration

BUT FIRST, WHAT IS A CAESAR CIPHER

As I mentioned before Caesar cipher is named after the famous ‘Julius Caesar’. This cipher is one of the simplest encryption techniques which uses a given key as number to shift the alphabet by that number of places. For example, if the user encrypts the letter ‘A’ by using the key number ‘3’ then the letter ‘A’ will be shifted by 3 places and becomes the letter ‘D’.

STEP BY STEP GUIDE

Firstly, I created a menu option to provide users a guide to what they can do inside my program. Then I declare a string variable which contains the 26 letters of the alphabet.

CODE:

/

/

Then by creating a while loop, it will allow me to execute both options repeatedly.


SELECTING OPTION E:

/

/

SELECTING OPTION D:


/

/

For both Options I create a key variable which will store the users’ key that the user decided to use to encrypt/decrypt the message he wrote.

ENCRYPT KEY VARIABLE:

/

/

Now for executing the algorithm to both parts, it must be either encrypting or decrypting the message. But before going through the code lets first understand how the algorithm works.

HOW DOES THE ALGORITHM WORK?

When the variable ‘text’, receives the users’ input and the variable ‘key’ retrieves the users’ choice to how much the text should be shifted by. Looping through the ‘text’ string one letter each time and comparing to the variable ‘alphabet’. When the letter is found in the ‘alphabet’ variable then by creating a new variable called ‘encodedText’ I add the new string based on selecting the alphabet letter and moving that position by the ‘key’ amount and applying a modulus to overlap the shift, making it circular. This prevents the Out of bounds index error.

ADDING NEW STRING TO ‘ENCODEDTEXT’

I’m incrementing the letter added to the ‘encodedText’ variable every loop. By finding the array position of variable ‘alphabet’ where the matched letter is found and adding the ‘key’ number and setting the new generated number to the array position and assigning this to the variable ‘encodedText’ using “+=” to increment the string and not overwrite the variable.

% - Modulus Length of alphabet – 26

Generated number = Alphabet [(matched index from variable ‘text’ and alphabet) %length of alphabet] encodedText += Alphabet [_Generated Number_].

DIAGRAM:

/

NOW LET’S LOOK AT THE ALGORITHM IN PRACTICE

ENCRYPTION ALGORITHM

/

DECRYPTION ALGORITHM

/

For shifting, I’m able to execute an algorithm which retrieves the current position number, adds the key number to that number then apply modulus 26 to that number and all that is executed inside “Alphabet [_New Generated Number position_]”.

Go back to

Projects