sfoteini / caesar-cipher

Caesar's cipher encryption algorithm in MATLAB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Caesar's cipher encryption algorithm

The Caesar cipher is one of the simplest and most widely known encryption techniques. It shifts the characters of a text by adding a fixed value to the ASCII value of each character. Decrypting a text is simply shifting it back by the same amount.
To pass an encrypted message from one person to another, it is first necessary that both parties have the key for the cipher, so that the sender may encrypt it and the receiver may decrypt it.

Caesar cipher function in MATLAB

The caesar function accepts two arguments:

  • the first is the character vector to be encrypted and
  • the second is the shift amount.
The function works with characters with ASCII codes from 32 to 126. If the shifted code goes outside of this range, it should wrap around.

Here is a quick example of the encryption and decryption steps involved with the caesar cipher. The text we will encrypt is 'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG', with a shift amount of 23.

  code = caesar('THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG', 23);
  uncode = caesar(code, -23);

Output:

  code = 
    'k_\7hl`Zb7Yifne7]fo7aldgj7fm\i7k_\7cXqp7[f^'
  uncode =
    'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG'

About

Caesar's cipher encryption algorithm in MATLAB


Languages

Language:MATLAB 100.0%