guidata(hObject, handles);
clear all;
clc;
global Img;
global EncImg;
global DecImg;
function varargout = ImageEncryptionGui_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
global Img;
global key;
X = uigetfile('*.jpg;*.tiff;*.ppm;*.pgm;*.png','pick a jpge file');
Img = imread(X);
axes(handles.axes1)
imshow(Img);
[n m k] = size(Img);
key = keyGen(n*m);
guidata(hObject, handles);
function pushbutton2_Callback(hObject, eventdata, handles)
global Img ;
global EncImg;
global key;
EncImg = imageProcess(Img,key);
axes(handles.axes2)
imshow(EncImg);
imwrite(EncImg,'Encoded.jpg','jpg');
guidata(hObject, handles);
function pushbutton3_Callback(hObject, eventdata, handles)
global DecImg;
global EncImg;
global key;
DecImg = imageProcess(EncImg,key);
axes(handles.axes3);
imshow(DecImg);
imwrite(DecImg,'Decoded.jpg','jpg');
guidata(hObject, handles);
fichier 2:
function [proImageOut] = imageProcess(ImgInp,key)
[n m k] = size(ImgInp);
% key =cell2mat(struct2cell( load('key5.mat')));
% key = keyGen(n*m);
for ind = 1 : m
Fkey(:,ind) = key((1+(ind-1)*n) : (((ind-1)*n)+n));
end
len = n;
bre = m;
for ind = 1 : k
Img = ImgInp(:,:,ind);
for ind1 = 1 : len
for ind2 = 1 : bre
proImage(ind1,ind2) = bitxor(Img(ind1,ind2),Fkey(ind1,ind2));
end
end
proImageOut(:,:,ind) = proImage(:,:,1);
end
% figure,imshow(proImageOut);
return;
fichier 3 :
function [key] = keyGen(n)
% Le paramètre n est le nombre d'octets dans la clé
% n * 8 est de convertir en un nombre de bits
n = n*8;
% bin_x est utilisé pour stocker la représentation binaire de la clé
% initialisation bin_x par n zeros.
bin_x = zeros(n,1,'uint8');
% bin_x_N_Minus_1 est la valeur que nous utilisons pour calculer le prochain bit
%doit etre entre 0 et 1.
bin_x_N_Minus_1 = 0.1;
x_N = 0;
% tic et toc sont utilisées pour calculer le temps de cette boucle for
tic
% Dans la première boucle , on boucle à travers les bits de la clé (le premier bit est toujours 0)
% Si x_N est positif, le bit correspondant de la clé est à 1, sinon il est égal à zéro.
for ind = 2 : n
% formule permet de calculer les valeur de x_N
x_N = 1 - 2* bin_x_N_Minus_1 * bin_x_N_Minus_1;
if (x_N > 0.0)
bin_x(ind-1) = 1;
end
bin_x_N_Minus_1 = x_N;
end
toc
% Initialisation key par n zeros.
key = zeros(n/8,1,'uint8');
% Cette boucle pour convertir les bits de la clé en octets et les stocke
% dans le tableau de sortie (clé)
for ind1 = 1 : n/8
for ind2 = 1 : 8
key(ind1) = key(ind1) + [bin_x(ind2*ind1)* 2] ^ (ind2-1);
end