%Image encryption using mandelbrot generated S-box clc; close all; clear all; %%%% Read an image %%%% tic I = imread('lena.bmp'); figure; imhist(I) imshow(I); %%% S-box Implemetation %%%% h=size(I); %%% Image Size %%% %%% S-box %%% sbox=[188 111 117 17 175 20 104 142 171 252 237 191 97 51 66 110 148 81 211 185 58 189 38 221 155 108 109 22 114 93 153 255 235 210 122 8 25 150 29 90 57 159 196 182 199 209 95 102 154 35 123 126 36 34 200 69 162 89 40 193 161 50 14 228 158 77 241 27 227 133 116 100 45 67 47 112 125 12 30 118 179 151 178 85 231 249 236 146 119 177 215 78 147 53 33 101 2 54 92 23 84 251 64 136 203 233 248 28 140 169 247 208 94 239 224 202 244 87 76 10 72 229 186 183 42 204 198 250 96 217 172 197 143 74 80 43 18 207 141 201 75 26 157 135 39 163 205 9 107 13 190 83 174 5 11 60 168 213 99 219 240 56 79 245 180 226 19 16 167 225 6 128 71 216 206 52 88 156 70 222 246 55 37 65 242 131 243 139 105 134 103 212 62 132 63 120 170 138 165 184 160 121 41 176 218 31 149 32 192 181 49 173 214 59 238 234 4 230 137 7 24 144 220 106 98 127 194 152 44 86 253 124 1 68 3 82 223 15 195 113 145 21 129 232 73 254 130 166 48 0 115 164 187 61 46 91 ]; %Place 256 values into 16*16 matirx sbox1=reshape(sbox,16,16); for i=1:h(1) for j=1:h(2) for k=1:h(3) c=dec2bin(I(i,j,k),8); d=[c(1) c(2) c(3) c(4)];%LSB e=[c(5) c(6) c(7) c(8)]; %MSBs f=bin2dec(d); % Row index g=bin2dec(e); % Column Index I(i,j,k)=sbox1(f+1,g+1); % Replacing values from table to image pixels end end end I; figure; imshow(I); n =size(I,1)*size(I,2)*size(I,3); level =0; s=10; r=3.55; b=0.25; x0=1.1840000001; y0=1.362700000; z0=1.2519000001; h=0.001; [x,y,z]=chenli(n,level,s,r,b,x0,y0,z0,h); drawnow; % rounding values X=10*x-round(10*x); Y=10*y-round(10*y); Z=10*z-round(10*z); drawnow; % % [X1,lx]=sort(X); [Y1,ly]=sort(Y); [Z1,lz]=sort(Z); drawnow; % % % A=I(:,:,1); B=I(:,:,2); C=I(:,:,3); A=repmat(A,3); B=repmat(B,3); C=repmat(C,3); A1=reshape(A,1,[]); B1=reshape(B,1,[]); C1=reshape(C,1,[]); A2(1:n)=A1(lx); B2(1:n)=B1(ly); C2(1:n)=C1(lz); A2=repmat(A2,1,3); B2=repmat(B2,1,3); C2=repmat(C2,1,3); % A3=reshape(A2,1,[]); % B3=reshape(B2,1,[]); % C3=reshape(C2,1,[]); A3=reshape(A2,size(A,1),size(A,2)); B3=reshape(B2,size(B,1),size(B,2)); C3=reshape(C2,size(C,1),size(C,2)); drawnow; % figure; A3=A3(1:512,1:512); B3=B3(1:512,1:512); C3=C3(1:512,1:512); % % I5(:,:,1)=A3; % I5(:,:,2)=B3; % I5(:,:,3)=C3; %red layer I5=A3; % I5(:,:,2)=B3; % I5(:,:,3)=C3; zz=randi([0,255],512,512); %zz=repmat(zz,1,3) zz1=randi([0,255],512,512); zz1=uint8(zz1); zz=uint8(zz); zzz=bitxor(zz,I5); zzz1=bitxor(zzz,zz1); imhist(zzz1) zz2R=reshape(zzz1(randperm(numel(zzz1))),size(zzz1)); figure; imshow(zz2R); c=entropy(zz2R) imsave %Green Layer I6=B3; zz=randi([0,255],512,512); %zz=repmat(zz,1,3) zz1=randi([0,255],512,512); zz1=uint8(zz1); zz=uint8(zz); zzz=bitxor(zz,I6); zzz1=bitxor(zzz,zz1); imhist(zzz1) zz2G=reshape(zzz1(randperm(numel(zzz1))),size(zzz1)); figure; imshow(zz2G) c=entropy(zz2G); imsave %blue layer I7=C3; zz=randi([0,255],512,512); %zz=repmat(zz,1,3) zz1=randi([0,255],512,512); zz1=uint8(zz1); zz=uint8(zz); zzz=bitxor(zz,I7); zzz1=bitxor(zzz,zz1); imhist(zzz1); zz2B=reshape(zzz1(randperm(numel(zzz1))),size(zzz1)); figure; imshow(zz2B) c=entropy(zz2B) imsave Encrypted_Image=cat(3,zz2R,zz2G,zz2B) imshow(Encrypted_Image) imsave toc