# Video Encryption using Caesar Cipher – Matlab Tutorial

In this matlab tutorial we are going to see video encryption using Caesar cipher. In cryptography, a Caesar cipher, also known as Caesar’s cipher, the shift cipherCaesar’s code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.

Example:-

The transformation can be represented by aligning two alphabets; the cipher alphabet is the plain alphabet rotated left or right by some number of positions. For instance, here is a Caesar cipher using a left rotation of three places, equivalent to a right shift of 23 (the shift parameter is used as the key):

Plain:   ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher:   XYZABCDEFGHIJKLMNOPQRSTUVW

The encryption can also be represented using modular arithmetic by first transforming the letters into numbers, according to the scheme, A = 0, B = 1,…, Z = 25. Encryption of a letter  by a shift n can be described mathematically as:

E(X)=(X+n) mod 26

Decryption is performed similarly,

D(X)=(X-n) mod 26

The Caesar cipher can be easily broken even in a ciphertext-only scenario. Two situations can be considered:

• an attacker knows (or guesses) that some sort of simple substitution cipher has been used, but not specifically that it is a Caesar scheme;
• an attacker knows that a Caesar cipher is in use, but does not know the shift value.

In the first case, the cipher can be broken using the same techniques as for a general simple substitution cipher, such as frequency analysis or pattern words. While solving, it is likely that an attacker will quickly notice the regularity in the solution and deduce that a Caesar cipher is the specific algorithm employed.

### Video, Its Representation and Encryption:

Any video is the collection of frames. These frames can be extracted from video or can be added to existing video at different speed (frame rates). In this project we have read the video directly from webcam frame by frame and the apply Caesar Cipher Encryption on the data from those frames. Every frame in video is consists of three matrices, 1st for representing Red color, 2nd for Green and 3rd for Blue

Example

For image of size 4 X 4

Matrix representing Red Color

(1 ; ; )

123      124      10        09

100      200      200      232

134      155      156      172

10        60        45        123

(; 2 ; ; )

123      124      10        09

100      200      200      232

134      155      156      172

10        60        45        123

(; ; 3 ; )

123      124      10        09

100      200      200      232

134      155      156      172

10        60        45        123

For encrypting such frame using Matlab following is the code snippet ( see complete code)

Note that here img_size is the matrix which will contain dimension details of the frame/image, here for example for 4 X 4 image its values will be [ 4 4 4 1] and the img1 matrix will contain encrypted image data which will be loaded back to frame.

### Video Decryption:

Decryption process is exactly opposite to encryption. Here video will be read from the file which is already encrypted, frames will be extracted and then decrypted, later stored to other video file, and following is the code snippet (see complete code )

## Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.