Читать книгу Optical Cryptosystems - Naveen K. Nishchal - Страница 28

MATLAB codes

Оглавление

I. Fourier transform domain encryption

%Double Random Phase encoding (DRPE)%PT is the plaintext%Phase_mask1 and Phase_mask2 are the two random phase masks to be used as the keys.PT=imread(’D:\Program\images\godisgreat.bmp’);%reading the image to be encryptedPT=double(PT(:,:,1));PT=PT./max(max(PT));figure;imagesc(abs(PT));colormap(gray);title(’original input image’);%defining the two random phase masks for the two keys[M,N]=size(PT);phase_values1=rand(M);phase_values2=rand(M);phase_mask1=exp(j*2*pi*phase_values1);%First Keyphase_mask2=exp(j*2*pi*phase_values2);%Second Key%%%%%Encryption%First Fourier transformA=PT.*phase_mask1;A=frt2(A);%Second Fourier transformB=A.*phase_mask2;B=fft2(B);%ciphertextfigure;imagesc(abs(B));colormap(gray);title(’encrypted image’);

%%%%%decryptionD=ifft2(ifft2(B).*conj(phase_mask2));figure;imagesc(abs(D));colormap(gray);title(’decrypted image’);

II. Fractional Fourier transform

function[X]=frt(obj,p)% MATLAB code for fractional Fourier transform% obj is the input subjected to fractional Fourier transform% p is the order of fractional Fourier transformN=size(obj);%p=0.5;n=N(1);[mx,my]=meshgrid(-n/2:1:n/2-1);% Action of first lensL1=exp(-j*(pi/n)*tan(p*pi/4)*(mx.*mx+my.*my));A=obj.*L1;% Free space propagationAf=fft2(A);L2=exp(-j*(pi/n)*sin(p*pi/2)*(mx.*mx+my.*my));B=Af.*L2;C=ifft2(B);% Action of second lensL3=exp(-j*(pi/n)*tan(p*pi/4)*(mx.*mx+my.*my));D=C.*L3;%Multiplication by a phase factorpf=exp(-j*(pi/n))./sqrt(abs(sin(p*pi/2)));X=D.*pf;

III. Fractional Fourier transform domain encryption

% Double Random Phase encoding (DRPE) in fractional Fourier domain% The code uses the functionfrtto perform the fractional Fourier transform.% This function requires two inputs: the entity to be fractional% Fourier transformed and the order of transformation.

% PT is the plaintext% Phase_mask1 and Phase_mask2 are the two random phase masks to be used as the keys.PT=imread(’D:\Program\images\godisgreat.bmp’);%reading the image to be encryptedPT=double(PT(:,:,1));PT=PT./max(max(PT));figure;imagesc(abs(PT));colormap(gray);title(’original input image’);%defining the two random phase masks for the two keys[M,N]=size(PT);phase_values1=rand(M);phase_values2=rand(M);phase_mask1=exp(j*2*pi*phase_values1);%First Keyphase_mask2=exp(j*2*pi*phase_values2);%Second Key%%%%%Encryption%First Fractional Fourier transform with fractional order 0.25A=PT.*phase_mask1;A=frt(A,0.25);%Second Fractional Fourier transform with fractional order 0.45B=A.*phase_mask2;B=frt(B,0.45);%ciphertextfigure;imagesc(abs(B));colormap(gray);title(’encrypted image’);%%%%%decryptionD=frt(frt(B,−0.45).*conj(phase_mask2),−0.25);figure;imagesc(abs(D));colormap(gray);title(’decrypted image’);

IV. Gyrator transform

functionqt=gyrator(q,a)% Matlab code for fast algorithm of discrete gyrator transform%qis an input signal and a is rotation angle% Direct DGT[M,N]=size(q);mm=((0:M−1)-(M)/2)/sqrt(M);nn=((0:N−1)-(N)/2)/sqrt(N);[x,y]=meshgrid(nn,fliplr(mm));[u,v]=meshgrid(mm,fliplr(nn));p1=exp(−2*j*pi*x.*y*tan(a/2));p2=fftshift(exp(−2*j*pi*u.*v*sin(a)));qt=p1.*(ifft2(fft2(p1.*q).*p2));end

Optical Cryptosystems

Подняться наверх