Caesar Cipher Encryption Algorithm using Assembly

Maneesha Perera
2 min readNov 14, 2016

--

Caesar cipher encryption algorithm is one of the most simplest and widely used encryption algorithms. In this algorithm every alphabetical character in the plain text is replaced by a character/letter some fixed number of positions down the alphabet.

For an example consider the following plain text.

Plain Text: ABCDEF

Key: 3

Cipher Text: DEFGHI

Every letter of the plain text have been incremented by the provided key value. The same procedure is carried out in decryption but the difference is the value of the key is decreased from the cipher text in order to get the respective plain text.

I have implemented this Caesar cipher algorithm using MIPS assembly language and have used the MARS emulator to run the code.

Output for encryption
Output for Decryption

The following mechanism was used for the purpose of encryption and decryption.

Encryption( Letter)= ASCII( BaseCharacter (A/a))+(ASCII(Letter)-(ASCII( BaseCharacter (A/a))+Key)%26

Depending on whether the letter is an upper case or lower case the base character will change either as A or a.

Decryption( Letter) =ASCII( BaseCharacter (A/a))+(ASCII(Letter)-(ASCII( BaseCharacter (A/a))-Key)%26

I have used t, s, v and a registers mainly for the program. The main problem occurred when calculating the remainder (mod) in the case of decryption because there are situations where the mod of negative values needed to be calculated.

For an example:

(-2)mod 26

The div command in MIPS will move the remainder to the high order registers. Therefore if the div command was used for this purpose the value stored in high order registers would be -2. But real value of (-2)mod 26 should be 24.

Therefore for situations like this I have manually written a procedure to calculate the mod value for negative values.

--

--