Image encryption and decryption using chess cipher
Create New

Image encryption and decryption using chess cipher

Project period

06/28/2017 - 07/27/2017

Views

340

4



Image encryption and decryption using chess cipher
Image encryption and decryption using chess cipher

Propagation of a communication signal is an open medium process. Various methods are proposed for securing the transmission of messages in the communication process. Cryptography provides us with a specific form or key by which the corresponding person or receiver could only retrieve the message transferred. There are many encryption and decryption algorithms for encrypting the data at sending edge and decrypting the encrypted data at the receiver edge ensuring secure data communication. Decryption is the reverse process of encryption. Here, we propose a method of encryption of any message or image using chess cipher algorithm.

Communication is one of the basic necessities in today’s world. Due to the rapid development of network and multimedia technologies, security of the messages communicated has very key importance and require a secure framework for transfer purpose. One of the greatest challenges posing in today’s techniques is the static cryptographic code. Encryption is the most effective way to achieve data security. This process achieves an effective role in hiding the contents of the message because the original information can only be recovered through the description process. There are several ways to transfer the data in a secure and reliable mode; one such way to secure the information in communication is using cryptography. Cryptography refers to the science of transfiguring messages to make them secure and invulnerable to hacking or outbreaks.

Why: Problem statement

Security is the major problem for sending secret messages. The problem associated with the encryption technique is that it does not provide security, once the data is decrypted.

How: Solution description

As the name Cipher Chess implies, our cipher uses an ordinary chessboard and pieces to encode, transmit, and decode secret messages with a high degree of security. We chose the game of chess for two reasons. First, chess already has a great amount of variety built into it, from the different types of pieces and the way they move to the number and colors of squares on the board. All these variations provide the potential for complexity, which is important for any cipher. Second, chess is a common game. There is nothing suspicious in two people playing chess, or even one person playing by him or herself. The use of an innocent game for encoding and hiding messages is the stenographic core of CipherChess. Combining principles of stenography, low-tech ciphers, and shared-key encryption, Cipher Chess delivers security and secrecy all at once.

How is it different from competition

Encryption is the process of transferring the message to an authorized person with high security. Here, the size of the original image is 256-bit. The 256-bit sequence is divided into 64 blocks is considered as the chess cipher. The original plain image is XORed with the cipher image to produce an encrypted image. Decryption is the reverse process of encryption which means retrieving the original image. The encrypted image is again XORed with the cipher image to get an original image. Thus, the receiver finally retrieves the original image.

Who are your customers

Military and Government offices can use this project for sharing high-level secret messages.

Project Phases and Schedule

Phase 1: Literature survey and analysis

Phase 2: Encryption algorithm

Phase 3: Decryption

Resources Required

Software Requirements: MATLAB

Download:
Project Code Code copy
/* Your file Name : Encryption_Decryption_total_process.m */
/* Your coding Language : matlab */
/* Your code snippet start here */
clc;
clear all;
%3D chaotic map for image encryption
%3.53<l<3.81
%0<b<0.022
%0<a<0.015
%      x(i+1)=l*x(i)*(1-x(i))+b*y(i)*y(i)*x(i)+a*z(i)*z(i)*z(i);
%      y(i+1)=l*y(i)*(1-y(i))+b*z(i)*z(i)*y(i)+a*x(i)*x(i)*x(i);
%      z(i+1)=l*z(i)*(1-z(i))+b*x(i)*x(i)*z(i)+a*y(i)*y(i);
%modify the chaos by this equation furthure
%z(i+1)=l*z(i)*(1-z(i))+b*x(i)*x(i)*z(i)+a*y(i)*y(i)*y(i);
%initial conditions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%% 3D CHAOS GENERATION CODE%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 x(1)=0.2350;
 y(1)=0.3500;
 z(1)=0.7350;
 a(1)=0.0125;
 b(1)=0.0157;
 l(1)=3.7700;
 image_height=256;
 for i=1:1:70000
     x(i+1)=l*x(i)*(1-x(i))+b*y(i)*y(i)*x(i)+a*z(i)*z(i)*z(i);
     y(i+1)=l*y(i)*(1-y(i))+b*z(i)*z(i)*y(i)+a*x(i)*x(i)*x(i);
     z(i+1)=l*z(i)*(1-z(i))+b*x(i)*x(i)*z(i)+a*y(i)*y(i);
 end
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %%%%%%histogram equalization and preparation for use%%%%%%%%%%%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 x=ceil(mod((x*100000),image_height));
 y=ceil(mod((y*100000),image_height));
 z=ceil(mod((z*100000),image_height));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%IMAGE INPUT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
original=imread('peppers.jpg');
rgb=rgb2gray(original);
[row,col]=size(rgb);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%INITIALIZE THE VALUE OF ROTATION%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=500;
p=600;
q=700;
for j=1:1:row
    k(j)=x(j+n);
    l(j)=y(j+p);
end

% for i=1:1:row
%     k(i)=x(i+n);
% end
% for j=1:1:col
%     l(j)=y(j+p);
% end

for j=1:1:col*row
    m(j)=z(j+q);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IF k is even right shift row else left shift row%%%%%%%%%%%%%%%%%
% If l is even shift up column else down shift column%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%ROTATION OPERATION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for i=1:1:row
    for j=1:1:col
        if(mod(k(i),2)==0)
            if((j+k(i))<=col)   %shift right of row
               sh_row(i,j+k(i))=rgb(i,j);
               row_shift_even(i,j)=j+k(i);
            else
               sh_row(i,(j+k(i)-col))=rgb(i,j); 
               row_shift_even(i,j)=(j+k(i)-col);
            end
        else
            if((j-k(i))>=1)       %shift left of row
                sh_row(i,j-k(i))=rgb(i,j);
                row_shift_odd(i,j)=j-k(i);
            else
                sh_row(i,(col+j-k(i)))=rgb(i,j);
                row_shift_odd(i,j)=col+j-k(i);
            end
        end
    end
end
   

for j=1:1:col
    for i=1:1:row
        if(mod(l(j),2)==0)
           if((i-l(j))>=1)          %shift up of column
                sh_col(i-l(j),j)=sh_row(i,j);
                col_shift_even(i,j)=i-l(j);
            else
                sh_col((row+i-l(j)),j)=sh_row(i,j);
                col_shift_even(i,j)=row+i-l(j);
            end
        else
           if((i+l(j))<=row)           %shift down of column
               sh_col(i+l(j),j)=sh_row(i,j);
               col_shift_odd(i,j)=i+l(j);
               else
               sh_col((i+l(j)-row),j)=sh_row(i,j); 
               col_shift_odd(i,j)=(i+l(j)-row);
            end
        end
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%XOR IMAGE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
total_length=row*col;
column_image=reshape(sh_col,1,total_length);
for i=1:1:total_length
xorr1(1,i)=bitxor(column_image(i),m(i));
end
y=reshape(xorr1,row,col);
imwrite(y, 'encypted_peppers.jpg', 'Quality', 100);
figure
subplot(3,2,1)
imshow(rgb)
title('Original Image');
subplot(3,2,2)
imhist(rgb)
title('Histogram of original Image');

subplot(3,2,3)
imshow(y)
title('Encrypted Image');
subplot(3,2,4)
imhist(y)
title('Histogram of Encrypted Image');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%Decryption XOR%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[row,col]=size(y);
rgb=y;
total_length=row*col;
column_image=reshape(rgb,1,total_length);
for i=1:1:total_length
        xorr1(1,i)=bitxor(column_image(i),m(i));
end
shuffled_image=reshape(xorr1,row,col);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IF k is even right shift row else left shift row%%%%%%%%%%%%%%%%%
% If l is even shift up column else down shift column%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%ROTATION OPERATION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%ROW SHIFTING%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for j=1:1:col
    for i=1:1:row
        if(mod(l(j),2)==0)
           if((i+l(j))<=row)           %shift down of column
               sh_col(i+l(j),j)=shuffled_image(i,j);
               col_shift_even(i,j)=i+l(j);
               else
               sh_col((i+l(j)-row),j)=shuffled_image(i,j); 
               col_shift_even(i,j)=(i+l(j)-row);
            end
        else
           if((i-l(j))>=1)          %shift up of column
                sh_col(i-l(j),j)=shuffled_image(i,j);
                col_shift_odd(i,j)=i-l(j);
            else
                sh_col((row+i-l(j)),j)=shuffled_image(i,j);
                col_shift_odd(i,j)=row+i-l(j);
            end
        end
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


for i=1:1:row
    for j=1:1:col
        if(mod(k(i),2)==0)
            if((j-k(i))>=1)       %shift left of row
                sh_row(i,j-k(i))=sh_col(i,j);
                row_shift_even(i,j)=j-k(i);
            else
                sh_row(i,(col+j-k(i)))=sh_col(i,j);
                row_shift_even(i,j)=col+j-k(i);
            end
        else
            if((j+k(i))<=col)   %shift right of row
               sh_row(i,j+k(i))=sh_col(i,j);
               row_shift_even(i,j)=j+k(i);
            else
               sh_row(i,(j+k(i)-col))=sh_col(i,j); 
               row_shift_even(i,j)=(j+k(i)-col);
            end
        end
    end
end
   

subplot(3,2,5)
imshow (sh_row)
title('decrypted image');

subplot(3,2,6)
imhist(sh_row)
title('histogram decrypted image');

imwrite(sh_row, 'Decrypted_peppers.jpg', 'Quality', 100);




    

    

 

Comments

Leave a Comment

Post a Comment