├── s5.mat ├── V5I5-1150.pdf ├── Images ├── Lena.jpg ├── ORLFace.jpg ├── baboon.jpg ├── panda.jpg ├── Football.jpg └── README.md ├── Results ├── SITlena.mat ├── SITpanda.mat ├── SITrohit.mat ├── SITFootball.mat ├── SITbaboon.mat ├── SecureForcelena.mat ├── SecureForcepanda.mat ├── SecureForcebaboon.mat └── SecureForceFootball.mat ├── README.md ├── SF-subFunctions ├── Hex2Bin.m ├── Dec2Bin.m ├── convert2bin.m ├── Scalling.m ├── Binary2Dec.m ├── h2b.m ├── Binary2Hex.m ├── fun.m ├── SF_Encrypt.m ├── SF_Decryption.m └── SF_Key_Gen.m ├── SIT-functions ├── Hex2Bin.m ├── Dec2Bin.m ├── f_fun.m ├── convert2bin.m ├── Scalling.m ├── Binary2Dec.m ├── h2b.m ├── Q_fun.m ├── P_fun.m ├── SF_Key_Gen.m ├── SF_Decryption.m └── SF_Encrypt.m ├── LICENSE ├── SecureForce.m ├── Estimated_trajectory.m └── SIT_Image_Encryption.m /s5.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/s5.mat -------------------------------------------------------------------------------- /V5I5-1150.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/V5I5-1150.pdf -------------------------------------------------------------------------------- /Images/Lena.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Images/Lena.jpg -------------------------------------------------------------------------------- /Images/ORLFace.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Images/ORLFace.jpg -------------------------------------------------------------------------------- /Images/baboon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Images/baboon.jpg -------------------------------------------------------------------------------- /Images/panda.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Images/panda.jpg -------------------------------------------------------------------------------- /Images/Football.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Images/Football.jpg -------------------------------------------------------------------------------- /Results/SITlena.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Results/SITlena.mat -------------------------------------------------------------------------------- /Results/SITpanda.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Results/SITpanda.mat -------------------------------------------------------------------------------- /Results/SITrohit.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Results/SITrohit.mat -------------------------------------------------------------------------------- /Results/SITFootball.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Results/SITFootball.mat -------------------------------------------------------------------------------- /Results/SITbaboon.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Results/SITbaboon.mat -------------------------------------------------------------------------------- /Results/SecureForcelena.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Results/SecureForcelena.mat -------------------------------------------------------------------------------- /Results/SecureForcepanda.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Results/SecureForcepanda.mat -------------------------------------------------------------------------------- /Results/SecureForcebaboon.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Results/SecureForcebaboon.mat -------------------------------------------------------------------------------- /Results/SecureForceFootball.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kakshak07/Comparison-between-image-encryption-algorithms-for-wireless-sensor/HEAD/Results/SecureForceFootball.mat -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Comparison-between-image-encryption-algorithms-for-wireless-sensor 2 | Comparison between image encryption algorithms: SIT and Secure Force Algorithms 3 | 4 | 5 | Please feel free to contact me: kakshak@gmail.com 6 | -------------------------------------------------------------------------------- /SF-subFunctions/Hex2Bin.m: -------------------------------------------------------------------------------- 1 | function [ bin ] = Hex2Bin( hex ) 2 | %HEX2BIN Summary of this function goes here 3 | % Detailed explanation goes here 4 | bin=logical([]); 5 | for b=1:length(hex) 6 | bin=[bin logical(h2b(hex(b)))]; 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /SIT-functions/Hex2Bin.m: -------------------------------------------------------------------------------- 1 | function [ bin ] = Hex2Bin( hex ) 2 | %HEX2BIN Summary of this function goes here 3 | % Detailed explanation goes here 4 | bin=logical([]); 5 | for b=1:length(hex) 6 | bin=[bin logical(h2b(hex(b)))]; 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /Images/README.md: -------------------------------------------------------------------------------- 1 | # Images 2 | 3 | 4 | This folder contain various images that need to be impoorted in code for various different encryption techniques.
5 | 6 | ## Different Images 7 | 8 | - Baboon 9 | - Football 10 | - Lena 11 | - ORLFace 12 | - Panda 13 | -------------------------------------------------------------------------------- /SIT-functions/Dec2Bin.m: -------------------------------------------------------------------------------- 1 | function [ bin ] = Dec2Bin( dec ) 2 | %DEC2BIN Summary of this function goes here 3 | % Detailed explanation goes here 4 | % bin=logical([]); 5 | hex=[]; 6 | for b=1:length(dec) 7 | hex=[hex dec2hex(dec(b),2)]; 8 | end 9 | [bin] = Hex2Bin(hex); 10 | end 11 | -------------------------------------------------------------------------------- /SF-subFunctions/Dec2Bin.m: -------------------------------------------------------------------------------- 1 | function [ bin ] = Dec2Bin( dec ) 2 | %DEC2BIN Summary of this function goes here 3 | % Detailed explanation goes here 4 | % bin=logical([]); 5 | hex=[]; 6 | for b=1:length(dec) 7 | hex=[hex dec2hex(dec(b),2)]; 8 | end 9 | [bin] = Hex2Bin(hex); 10 | end 11 | -------------------------------------------------------------------------------- /SIT-functions/f_fun.m: -------------------------------------------------------------------------------- 1 | function a = funM(a) 2 | a=[P_fun(a(1:4)),Q_fun(a(5:8)),P_fun(a(9:12)),Q_fun(a(13:16))]; 3 | a=[Q_fun([a(1:2),a(5:6)]),P_fun([a(3:4),a(7:8)]),Q_fun([a(9:10),a(13:14)]),P_fun([a(11:12),a(15:16)])]; 4 | a=[P_fun([a(1:2),a(5:6)]),Q_fun([a(3:4),a(7:8)]),P_fun([a(9:10),a(13:14)]),Q_fun([a(11:12),a(15:16)])]; 5 | end -------------------------------------------------------------------------------- /SIT-functions/convert2bin.m: -------------------------------------------------------------------------------- 1 | function [ Data_binary ] = convert2bin( Data ) 2 | %CONVERT2BIN Summary of this function goes here 3 | % Detailed explanation goes here 4 | Data_binary=[]; 5 | for j=1:size(Data,2) 6 | temp=[]; 7 | for i=1:size(Data,1) 8 | temp = [temp Dec2Bin(Data(i,j))]; 9 | end 10 | Data_binary=[Data_binary;temp]; 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /SF-subFunctions/convert2bin.m: -------------------------------------------------------------------------------- 1 | function [ Data_binary ] = convert2bin( Data ) 2 | %CONVERT2BIN Summary of this function goes here 3 | % Detailed explanation goes here 4 | Data_binary=[]; 5 | for j=1:size(Data,2) 6 | temp=[]; 7 | for i=1:size(Data,1) 8 | temp = [temp Dec2Bin(Data(i,j))]; 9 | end 10 | Data_binary=[Data_binary;temp]; 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /SF-subFunctions/Scalling.m: -------------------------------------------------------------------------------- 1 | function [Data,padding] = Scalling (Data,sf); 2 | % Data=imread('cameraman.tif'); 3 | Data=reshape(Data,[size(Data,1)*size(Data,2) 1]); 4 | Data=double(Data); 5 | padding=mod(length(Data),sf); 6 | if (padding~=0) 7 | padding=sf-padding; 8 | end 9 | Data=[Data;zeros(padding,1)]; 10 | Data=reshape(Data,[sf,length(Data)/sf]); -------------------------------------------------------------------------------- /SIT-functions/Scalling.m: -------------------------------------------------------------------------------- 1 | function [Data,padding] = Scalling (Data,sf); 2 | % Data=imread('cameraman.tif'); 3 | Data=reshape(Data,[size(Data,1)*size(Data,2) 1]); 4 | Data=double(Data); 5 | padding=mod(length(Data),sf); 6 | if (padding~=0) 7 | padding=sf-padding; 8 | end 9 | Data=[Data;zeros(padding,1)]; 10 | Data=reshape(Data,[sf,length(Data)/sf]); -------------------------------------------------------------------------------- /SF-subFunctions/Binary2Dec.m: -------------------------------------------------------------------------------- 1 | function [ dec ] = Binary2Dec( binary ) 2 | %binaryB2H Summary of this function goes here 3 | % Detailed explanation goes here 4 | E1=bin2dec(num2str(binary(1:8))); 5 | E2=bin2dec(num2str(binary(9:16))); 6 | E3=bin2dec(num2str(binary(17:24))); 7 | E4=bin2dec(num2str(binary(25:32))); 8 | E5=bin2dec(num2str(binary(33:40))); 9 | E6=bin2dec(num2str(binary(41:48))); 10 | E7=bin2dec(num2str(binary(49:56))); 11 | E8=bin2dec(num2str(binary(57:64))); 12 | dec=cell2mat({E1 E2 E3 E4 E5 E6 E7 E8}); 13 | end 14 | -------------------------------------------------------------------------------- /SIT-functions/Binary2Dec.m: -------------------------------------------------------------------------------- 1 | function [ dec ] = Binary2Dec( binary ) 2 | %binaryB2H Summary of this function goes here 3 | % Detailed explanation goes here 4 | E1=bin2dec(num2str(binary(1:8))); 5 | E2=bin2dec(num2str(binary(9:16))); 6 | E3=bin2dec(num2str(binary(17:24))); 7 | E4=bin2dec(num2str(binary(25:32))); 8 | E5=bin2dec(num2str(binary(33:40))); 9 | E6=bin2dec(num2str(binary(41:48))); 10 | E7=bin2dec(num2str(binary(49:56))); 11 | E8=bin2dec(num2str(binary(57:64))); 12 | dec=cell2mat({E1 E2 E3 E4 E5 E6 E7 E8}); 13 | end 14 | -------------------------------------------------------------------------------- /SIT-functions/h2b.m: -------------------------------------------------------------------------------- 1 | function b = h2b(h) 2 | switch h 3 | case {'0'} 4 | b = logical([0 0 0 0]); 5 | case {'1'} 6 | b = logical([0 0 0 1]); 7 | case {'2'} 8 | b = logical([0 0 1 0]); 9 | case {'3'} 10 | b = logical([0 0 1 1]); 11 | case {'4'} 12 | b = logical([0 1 0 0]); 13 | case {'5'} 14 | b = logical([0 1 0 1]); 15 | case {'6'} 16 | b = logical([0 1 1 0]); 17 | case {'7'} 18 | b = logical([0 1 1 1]); 19 | case {'8'} 20 | b = logical([1 0 0 0]); 21 | case {'9'} 22 | b = logical([1 0 0 1]); 23 | case {'A', 'a'} 24 | b = logical([1 0 1 0]); 25 | case {'B', 'b'} 26 | b = logical([1 0 1 1]); 27 | case {'C', 'c'} 28 | b = logical([1 1 0 0]); 29 | case {'D', 'd'} 30 | b = logical([1 1 0 1]); 31 | case {'E', 'e'} 32 | b = logical([1 1 1 0]); 33 | case {'F', 'f'} 34 | b = logical([1 1 1 1]); 35 | end -------------------------------------------------------------------------------- /SF-subFunctions/h2b.m: -------------------------------------------------------------------------------- 1 | function b = h2b(h) 2 | switch h 3 | case {'0'} 4 | b = logical([0 0 0 0]); 5 | case {'1'} 6 | b = logical([0 0 0 1]); 7 | case {'2'} 8 | b = logical([0 0 1 0]); 9 | case {'3'} 10 | b = logical([0 0 1 1]); 11 | case {'4'} 12 | b = logical([0 1 0 0]); 13 | case {'5'} 14 | b = logical([0 1 0 1]); 15 | case {'6'} 16 | b = logical([0 1 1 0]); 17 | case {'7'} 18 | b = logical([0 1 1 1]); 19 | case {'8'} 20 | b = logical([1 0 0 0]); 21 | case {'9'} 22 | b = logical([1 0 0 1]); 23 | case {'A', 'a'} 24 | b = logical([1 0 1 0]); 25 | case {'B', 'b'} 26 | b = logical([1 0 1 1]); 27 | case {'C', 'c'} 28 | b = logical([1 1 0 0]); 29 | case {'D', 'd'} 30 | b = logical([1 1 0 1]); 31 | case {'E', 'e'} 32 | b = logical([1 1 1 0]); 33 | case {'F', 'f'} 34 | b = logical([1 1 1 1]); 35 | end -------------------------------------------------------------------------------- /SF-subFunctions/Binary2Hex.m: -------------------------------------------------------------------------------- 1 | function [ Hex ] = Binary2Hex( binary ) 2 | %binaryB2H Summary of this function goes here 3 | % Detailed explanation goes here 4 | E1=dec2hex(bin2dec(num2str(binary(1:4)))); 5 | E2=dec2hex(bin2dec(num2str(binary(5:8)))); 6 | E3=dec2hex(bin2dec(num2str(binary(9:12)))); 7 | E4=dec2hex(bin2dec(num2str(binary(13:16)))); 8 | E5=dec2hex(bin2dec(num2str(binary(17:20)))); 9 | E6=dec2hex(bin2dec(num2str(binary(21:24)))); 10 | E7=dec2hex(bin2dec(num2str(binary(25:28)))); 11 | E8=dec2hex(bin2dec(num2str(binary(29:32)))); 12 | E9=dec2hex(bin2dec(num2str(binary(33:36)))); 13 | E10=dec2hex(bin2dec(num2str(binary(37:40)))); 14 | E11=dec2hex(bin2dec(num2str(binary(41:44)))); 15 | E12=dec2hex(bin2dec(num2str(binary(45:48)))); 16 | E13=dec2hex(bin2dec(num2str(binary(49:52)))); 17 | E14=dec2hex(bin2dec(num2str(binary(53:56)))); 18 | E15=dec2hex(bin2dec(num2str(binary(57:60)))); 19 | E16=dec2hex(bin2dec(num2str(binary(61:64)))); 20 | Hex=cell2mat({E1 E2 E3 E4 E5 E6 E7 E8 E9 E10 E11 E12 E13 E14 E15 E16}); 21 | end 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Kakshak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SIT-functions/Q_fun.m: -------------------------------------------------------------------------------- 1 | function O = Q(I) 2 | if(I==logical([0 0 0 0])) 3 | O = logical([1 0 0 1]); end 4 | if(I==logical([0 0 0 1])) 5 | O = logical([1 1 1 0]); end 6 | if(I==logical([0 0 1 0])) 7 | O = logical([0 1 0 1]); end 8 | if(I==logical([0 0 1 1])) 9 | O = logical([0 1 1 0]); end 10 | if(I==logical([0 1 0 0])) 11 | O = logical([1 0 1 0]); end 12 | if(I==logical([0 1 0 1])) 13 | O = logical([0 0 1 0]); end 14 | if(I==logical([0 1 1 0])) 15 | O = logical([0 0 1 1]); end 16 | if(I==logical([0 1 1 1])) 17 | O = logical([1 1 0 0]); end 18 | if(I==logical([1 0 0 0])) 19 | O = logical([1 1 1 1]); end 20 | if(I==logical([1 0 0 1])) 21 | O = logical([0 0 0 0]); end 22 | if(I==logical([1 0 1 0])) 23 | O = logical([0 1 0 0]); end 24 | if(I==logical([1 0 1 1])) 25 | O = logical([1 1 0 1]); end 26 | if(I==logical([1 1 0 0])) 27 | O = logical([0 1 1 1]); end 28 | if(I==logical([1 1 0 1])) 29 | O = logical([1 0 1 1]); end 30 | if(I==logical([1 1 1 0])) 31 | O = logical([0 0 0 1]); end 32 | if(I==logical([1 1 1 1])) 33 | O = logical([1 0 0 0]); end 34 | end -------------------------------------------------------------------------------- /SIT-functions/P_fun.m: -------------------------------------------------------------------------------- 1 | function O = P(I) 2 | if(I==logical([0 0 0 0])) 3 | O = logical([0 0 1 1]); end 4 | if(I==logical([0 0 0 1])) 5 | O = logical([1 1 1 1]); end 6 | if(I==logical([0 0 1 0])) 7 | O = logical([1 1 1 0]); end 8 | if(I==logical([0 0 1 1])) 9 | O = logical([0 0 0 0]); end 10 | if(I==logical([0 1 0 0])) 11 | O = logical([0 1 0 1]); end 12 | if(I==logical([0 1 0 1])) 13 | O = logical([0 1 0 0]); end 14 | if(I==logical([0 1 1 0])) 15 | O = logical([1 0 1 1]); end 16 | if(I==logical([0 1 1 1])) 17 | O = logical([1 1 0 0]); end 18 | if(I==logical([1 0 0 0])) 19 | O = logical([1 1 0 1]); end 20 | if(I==logical([1 0 0 1])) 21 | O = logical([1 0 1 0]); end 22 | if(I==logical([1 0 1 0])) 23 | O = logical([1 0 0 1]); end 24 | if(I==logical([1 0 1 1])) 25 | O = logical([0 1 1 0]); end 26 | if(I==logical([1 1 0 0])) 27 | O = logical([0 1 1 1]); end 28 | if(I==logical([1 1 0 1])) 29 | O = logical([1 0 0 0]); end 30 | if(I==logical([1 1 1 0])) 31 | O = logical([0 0 1 0]); end 32 | if(I==logical([1 1 1 1])) 33 | O = logical([0 0 0 1]); end 34 | end -------------------------------------------------------------------------------- /SF-subFunctions/fun.m: -------------------------------------------------------------------------------- 1 | function i = fun(a) 2 | b=cell(6,4); 3 | %Arrangent of 16bits into 4,4 Bit Blocks 4 | b{1,1}=a(1:4); 5 | b{1,2}=a(5:8); 6 | b{1,3}=a(9:12); 7 | b{1,4}=a(13:16); 8 | % Left Shifthing on each 4bit block 9 | b{2,1}=b{1,1}; 10 | b{2,2}=circshift(b{1,2},[1 1]); 11 | b{2,3}=circshift(b{1,3},[1 2]); 12 | b{2,4}=circshift(b{1,4},[1 3]); 13 | %performing And operation 14 | b{3,1}=b{2,1}; 15 | b{3,2}=and(b{3,1},b{2,2}); 16 | b{3,3}=and(b{3,2},b{2,3}); 17 | b{3,4}=and(b{3,3},b{2,4}); 18 | s=cell(1,4); 19 | s{1,1}=['0','f','2','d';'d','2','b','4';'8','7','2','d';'d','2','3','c']; 20 | s{1,2}=['0','1','c','f';'f','8','5','0';'0','9','4','f';'f','0','d','0']; 21 | s{1,3}=['0','e','c','0';'0','8','e','4';'8','e','4','0';'0','0','e','c']; 22 | s{1,4}=['0','1','3','0';'0','7','1','4';'8','1','8','0';'0','f','1','c']; 23 | % for Identifying the row and colomb within s-boxes 24 | for r=1:length(s) 25 | row=[b{3,r}(1,1),b{3,r}(1,4)]; 26 | col=[b{3,r}(2:3)]; 27 | x(r)=bin2dec(int2str(row))+1; 28 | y(r)=bin2dec(int2str(col))+1; 29 | end 30 | %substitute the value identified by s-boxes 31 | for r=1:length(s) 32 | b{4,r}=s{1,r}(x(r),y(r)); 33 | end 34 | %coverstion of hex no into bin no 35 | for j=1:length(s) 36 | b{5,j}=logical([]); 37 | b{5,j}=[b{5,j} h2b(b{4,j})]; 38 | end 39 | %performing OR operations on 4 bit blocks 40 | b{6,1}=b{5,1}; 41 | b{6,2}=or(b{6,1},b{5,2}); 42 | b{6,3}=or(b{6,2},b{5,3}); 43 | b{6,4}=or(b{6,3},b{5,4}); 44 | 45 | %for Final 16 bit 46 | i=[b{6,1},b{6,2},b{6,3},b{6,4}]; 47 | end -------------------------------------------------------------------------------- /SF-subFunctions/SF_Encrypt.m: -------------------------------------------------------------------------------- 1 | function [cipher]=SF_Encrypt(bin_msg,K1,K2,K3,K4,K5); 2 | %For Encryption of 64 bit msg 3 | bin_msg1=bin_msg(1:32); 4 | bin_msg2=bin_msg(33:64); 5 | 6 | enc=cell(8,4); 7 | % Arranging 64 bit into 16 bit block 8 | enc{1,1}=bin_msg(1:16); 9 | enc{1,2}=bin_msg(17:32); 10 | enc{1,3}=bin_msg(33:48); 11 | enc{1,4}=bin_msg(49:64); 12 | 13 | 14 | enc{2,1}=not(xor(K1,enc{1,1})); 15 | enc{2,2}=xor(fun(enc{2,1}),enc{1,3}); 16 | enc{2,4}=not(xor(K1,enc{1,4})); 17 | enc{2,3}=xor(fun(enc{2,4}),enc{1,2}); 18 | enc{3,1}=enc{2,2}; 19 | enc{3,2}=enc{2,1}; 20 | enc{3,3}=enc{2,4}; 21 | enc{3,4}=enc{2,3}; 22 | 23 | % For Second Round 24 | %performing Xnor operation with K2 25 | enc{4,1}=not(xor(K2,enc{3,1})); 26 | %Using f function and Xor operation obtain second 16 bit block 27 | enc{4,2}=xor(fun(enc{4,1}),enc{3,2}); 28 | %Performing xnor operation on last 16 bit 29 | enc{4,4}=not(xor(K2,enc{3,4})); 30 | %Using f function and Xor operation obtain third 16 bit block 31 | enc{4,3}=xor(fun(enc{4,4}),enc{3,3}); 32 | 33 | % For Third Round 34 | %Step no 01 35 | %performing xnor operation in first 16 bits with K3 36 | enc{5,1}=not(xor(K3,enc{4,1})); 37 | % Using f function and swaping tecniques on 16 bit 38 | enc{5,2}=xor(fun(enc{5,1}),enc{4,3}); 39 | %performing xnor operation in last 16 bits with K1 40 | enc{5,4}=not(xor(K3,enc{4,4})); 41 | % Using f function and swaping tecniques on 16 bit 42 | enc{5,3}=xor(fun(enc{5,4}),enc{4,2}); 43 | %Step no 02 44 | %Swaping Blocks 45 | enc{6,1}=enc{5,2}; 46 | enc{6,2}=enc{5,1}; 47 | enc{6,3}=enc{5,4}; 48 | enc{6,4}=enc{5,3}; 49 | 50 | %Round no 04 51 | %performing Xnor operation with K4 52 | enc{7,1}=not(xor(K4,enc{6,1})); 53 | %Using f function and Xor operation obtain second 16 bit block 54 | enc{7,2}=xor(fun(enc{7,1}),enc{6,2}); 55 | %Performing xnor operation on last 16 bit 56 | enc{7,4}=not(xor(K4,enc{6,4})); 57 | %Using f function and Xor operation obtain third 16 bit block 58 | enc{7,3}=xor(fun(enc{7,4}),enc{6,3}); 59 | 60 | % Round no 05 61 | %performing Xnor operation with K5 62 | enc{8,1}=not(xor(K5,enc{7,1})); 63 | %Using f function and Xor operation obtain second 16 bit block 64 | enc{8,2}=xor(fun(enc{8,1}),enc{7,3}); 65 | %Performing xnor operation on last 16 bit 66 | enc{8,4}=not(xor(K5,enc{7,4})); 67 | %Using f function and Xor operation obtain third 16 bit block 68 | enc{8,3}=xor(fun(enc{8,4}),enc{7,2}); 69 | % Encrypted Cipher 70 | cipher=[enc{8,1},enc{8,2},enc{8,3},enc{8,4}]; -------------------------------------------------------------------------------- /SIT-functions/SF_Key_Gen.m: -------------------------------------------------------------------------------- 1 | function [K1,K2,K3,K4,K5]=SF_Key_Gen(bin_key); 2 | %making a cell 3 | key= cell(5,4); 4 | %First for matrix of 16bit each 5 | key{1,1}=f_fun(bin_key(1:16));%bin_key(1:16); 6 | key{1,2}=f_fun(bin_key(33:48));%bin_key(17:32); 7 | key{1,3}=f_fun(bin_key(17:32));%bin_key(33:48); 8 | key{1,4}=f_fun(bin_key(49:64));%bin_key(49:64); 9 | 10 | % generating a matrix of each 16bit int 4*4 11 | key{2,1}(1,:)=key{1,1}(1:4); 12 | key{2,1}(2,:)=key{1,1}(5:8); 13 | key{2,1}(3,:)=key{1,1}(9:12); 14 | key{2,1}(4,:)=key{1,1}(13:16); 15 | key{2,2}(1,:)=key{1,2}(1:4); 16 | key{2,2}(2,:)=key{1,2}(5:8); 17 | key{2,2}(3,:)=key{1,2}(9:12); 18 | key{2,2}(4,:)=key{1,2}(13:16); 19 | key{2,3}(1,:)=key{1,3}(1:4); 20 | key{2,3}(2,:)=key{1,3}(5:8); 21 | key{2,3}(3,:)=key{1,3}(9:12); 22 | key{2,3}(4,:)=key{1,3}(13:16); 23 | key{2,4}(1,:)=key{1,4}(1:4); 24 | key{2,4}(2,:)=key{1,4}(5:8); 25 | key{2,4}(3,:)=key{1,4}(9:12); 26 | key{2,4}(4,:)=key{1,4}(13:16); 27 | 28 | %shifting 29 | key{3,1}(1,:)=key{2,1}(1,:); 30 | key{3,1}(2,:)=circshift(key{2,1}(2,:),[1 1]); 31 | key{3,1}(3,:)=circshift(key{2,1}(3,:),[1 2]); 32 | key{3,1}(4,:)=circshift(key{2,1}(4,:),[1 3]); 33 | 34 | key{3,2}(1,:)=key{2,2}(1,:); 35 | key{3,2}(2,:)=circshift(key{2,2}(2,:),[1 1]); 36 | key{3,2}(3,:)=circshift(key{2,2}(3,:),[1 2]); 37 | key{3,2}(4,:)=circshift(key{2,2}(4,:),[1 3]); 38 | 39 | key{3,3}(1,:)=key{2,3}(1,:); 40 | key{3,3}(2,:)=circshift(key{2,3}(2,:),[1 1]); 41 | key{3,3}(3,:)=circshift(key{2,3}(3,:),[1 2]); 42 | key{3,3}(4,:)=circshift(key{2,3}(4,:),[1 3]); 43 | 44 | key{3,4}(1,:)=key{2,4}(1,:); 45 | key{3,4}(2,:)=circshift(key{2,4}(2,:),[1 1]); 46 | key{3,4}(3,:)=circshift(key{2,4}(3,:),[1 2]); 47 | key{3,4}(4,:)=circshift(key{2,4}(4,:),[1 3]); 48 | 49 | key_1{8,1}=key{3,1}; %Modified 50 | key_1{8,2}=key{3,2}; %Modified 51 | key_1{8,3}=key{3,3}; %Modified 52 | key_1{8,4}=key{3,4}; %Modified 53 | 54 | key_1{9,1}=[key_1{8,1}(1,:),key_1{8,1}(2,:),key_1{8,1}(3,:),key_1{8,1}(4,:)]; 55 | key_1{9,2}=[key_1{8,2}(:,1)',flipdim(key_1{8,2}(:,2)',2),key_1{8,2}(:,3)',... 56 | flipdim(key_1{8,2}(:,4)',2)]; 57 | key_1{9,3}=[key_1{8,3}(:,1)',flipdim(key_1{8,3}(:,2)',2),key_1{8,3}(:,3)',... 58 | flipdim(key_1{8,3}(:,4)',2)]; 59 | key_1{9,4}=[key_1{8,4}(1,:),key_1{8,4}(2,:),key_1{8,4}(3,:),key_1{8,4}(4,:)]; 60 | 61 | % For Final KEY K1 62 | K1=key_1{9,1}; 63 | % For Final KEY K2 64 | K2=key_1{9,2}; 65 | % For Final KEY K3 66 | K3=key_1{9,3}; 67 | % For Final KEY K4 68 | K4=key_1{9,4}; 69 | % For Final KEY K5 70 | tmp=xor(K1,K2); 71 | tmp1=xor(K3,K4); 72 | K5=xor(tmp,tmp1); -------------------------------------------------------------------------------- /SF-subFunctions/SF_Decryption.m: -------------------------------------------------------------------------------- 1 | function [bin_msg]=SF_Decryption(binary_cipher,K1,K2,K3,K4,K5); 2 | %Decryption 3 | dec=cell(8,4); 4 | % Arranging 64 bit into 16 bit block 5 | dec{1,1}=binary_cipher(1:16); 6 | dec{1,2}=binary_cipher(17:32); 7 | dec{1,3}=binary_cipher(33:48); 8 | dec{1,4}=binary_cipher(49:64); 9 | 10 | % for first round 11 | %performing Xnor operation with K5 12 | dec{2,1}=not(xor(K5,dec{1,1})); 13 | %Using f function and Xor operation obtain second 16 bit block 14 | dec{2,3}=xor(fun(dec{1,1}),dec{1,2}); 15 | %Performing xnor operation on last 16 bit 16 | dec{2,4}=not(xor(K5,dec{1,4})); 17 | %Using f function and Xor operation obtain third 16 bit block 18 | dec{2,2}=xor(fun(dec{1,4}),dec{1,3}); 19 | 20 | % for Second Round 21 | %performing Xnor operation with K4 22 | dec{3,1}=not(xor(K4,dec{2,1})); 23 | %Using f function and Xor operation obtain second 16 bit block 24 | dec{3,2}=xor(fun(dec{2,1}),dec{2,2}); 25 | %Performing xnor operation on last 16 bit 26 | dec{3,4}=not(xor(K4,dec{2,4})); 27 | %Using f function and Xor operation obtain third 16 bit block 28 | dec{3,3}=xor(fun(dec{2,4}),dec{2,3}); 29 | 30 | % for Third Round 31 | %Step no 01 32 | %Swaping Blocks 33 | dec{4,1}=dec{3,2}; 34 | dec{4,2}=dec{3,1}; 35 | dec{4,3}=dec{3,4}; 36 | dec{4,4}=dec{3,3}; 37 | 38 | %Step no 02 39 | %performing xnor operation in first 16 bits with K3 40 | dec{5,1}=not(xor(K3,dec{4,1})); 41 | % Using f function and swaping tecniques on 16 bit 42 | dec{5,3}=xor(fun(dec{4,1}),dec{4,2}); 43 | %performing xnor operation in last 16 bits with K1 44 | dec{5,4}=not(xor(K3,dec{4,4})); 45 | % Using f function and swaping tecniques on 16 bit 46 | dec{5,2}=xor(fun(dec{4,4}),dec{4,3}); 47 | 48 | % for fourth Round 49 | %performing Xnor operation with K2 50 | dec{6,1}=not(xor(K2,dec{5,1})); 51 | %Using f function and Xor operation obtain second 16 bit block 52 | dec{6,2}=xor(fun(dec{5,1}),dec{5,2}); 53 | %Performing xnor operation on last 16 bit 54 | dec{6,4}=not(xor(K2,dec{5,4})); 55 | %Using f function and Xor operation obtain third 16 bit block 56 | dec{6,3}=xor(fun(dec{5,4}),dec{5,3}); 57 | 58 | % for fifth Round 59 | %Step no 01 60 | %Swaping Blocks 61 | dec{7,1}=dec{6,2}; 62 | dec{7,2}=dec{6,1}; 63 | dec{7,3}=dec{6,4}; 64 | dec{7,4}=dec{6,3}; 65 | %Step no 02 66 | %performing xnor operation in first 16 bits with K1 67 | dec{8,1}=not(xor(K1,dec{7,1})); 68 | % Using f function and swaping tecniques on 16 bit 69 | dec{8,3}=xor(fun(dec{7,1}),dec{7,2}); 70 | %performing xnor operation in last 16 bits with K1 71 | dec{8,4}=not(xor(K1,dec{7,4})); 72 | % Using f function and swaping tecniques on 16 bit 73 | dec{8,2}=xor(fun(dec{7,4}),dec{7,3}); 74 | 75 | bin_msg=[dec{8,1},dec{8,2},dec{8,3},dec{8,4}]; -------------------------------------------------------------------------------- /SIT-functions/SF_Decryption.m: -------------------------------------------------------------------------------- 1 | function [bin_msg]=SF_Decryption(binary_cipher,K1,K2,K3,K4,K5); 2 | %Decryption 3 | dec=cell(8,4); 4 | % Arranging 64 bit into 16 bit block 5 | dec{1,1}=binary_cipher(1:16); 6 | dec{1,2}=binary_cipher(17:32); 7 | dec{1,3}=binary_cipher(33:48); 8 | dec{1,4}=binary_cipher(49:64); 9 | 10 | % for first round 11 | %performing Xnor operation with K5 12 | dec{2,1}=not(xor(K5,dec{1,1})); 13 | %Using f f_function and Xor operation obtain second 16 bit block 14 | dec{2,3}=xor(f_fun(dec{1,1}),dec{1,2}); 15 | %Performing xnor operation on last 16 bit 16 | dec{2,4}=not(xor(K5,dec{1,4})); 17 | %Using f f_function and Xor operation obtain third 16 bit block 18 | dec{2,2}=xor(f_fun(dec{1,4}),dec{1,3}); 19 | 20 | % 21 | % dec{2,1}=dec{1,1}; 22 | % dec{2,1}=dec{1,2}; 23 | % dec{2,1}=dec{1,3}; 24 | % dec{2,1}=dec{1,4}; 25 | 26 | % for Second Round 27 | %performing Xnor operation with K4 28 | dec{3,1}=not(xor(K4,dec{2,1})); 29 | %Using f f_function and Xor operation obtain second 16 bit block 30 | dec{3,2}=xor(f_fun(dec{2,1}),dec{2,2}); 31 | %Performing xnor operation on last 16 bit 32 | dec{3,4}=not(xor(K4,dec{2,4})); 33 | %Using f f_function and Xor operation obtain third 16 bit block 34 | dec{3,3}=xor(f_fun(dec{2,4}),dec{2,3}); 35 | 36 | % for Third Round 37 | %Step no 01 38 | %Swaping Blocks 39 | dec{4,1}=dec{3,2}; 40 | dec{4,2}=dec{3,1}; 41 | dec{4,3}=dec{3,4}; 42 | dec{4,4}=dec{3,3}; 43 | 44 | %Step no 02 45 | %performing xnor operation in first 16 bits with K3 46 | dec{5,1}=not(xor(K3,dec{4,1})); 47 | % Using f f_function and swaping tecniques on 16 bit 48 | dec{5,3}=xor(f_fun(dec{4,1}),dec{4,2}); 49 | %performing xnor operation in last 16 bits with K1 50 | dec{5,4}=not(xor(K3,dec{4,4})); 51 | % Using f f_function and swaping tecniques on 16 bit 52 | dec{5,2}=xor(f_fun(dec{4,4}),dec{4,3}); 53 | 54 | % for fourth Round 55 | %performing Xnor operation with K2 56 | dec{6,1}=not(xor(K2,dec{5,1})); 57 | %Using f f_function and Xor operation obtain second 16 bit block 58 | dec{6,2}=xor(f_fun(dec{5,1}),dec{5,2}); 59 | %Performing xnor operation on last 16 bit 60 | dec{6,4}=not(xor(K2,dec{5,4})); 61 | %Using f f_function and Xor operation obtain third 16 bit block 62 | dec{6,3}=xor(f_fun(dec{5,4}),dec{5,3}); 63 | 64 | % for fifth Round 65 | %Step no 01 66 | %Swaping Blocks 67 | dec{7,1}=dec{6,2}; 68 | dec{7,2}=dec{6,1}; 69 | dec{7,3}=dec{6,4}; 70 | dec{7,4}=dec{6,3}; 71 | %Step no 02 72 | %performing xnor operation in first 16 bits with K1 73 | dec{8,1}=not(xor(K1,dec{7,1})); 74 | % Using f f_function and swaping tecniques on 16 bit 75 | dec{8,3}=xor(f_fun(dec{7,1}),dec{7,2}); 76 | %performing xnor operation in last 16 bits with K1 77 | dec{8,4}=not(xor(K1,dec{7,4})); 78 | % Using f f_function and swaping tecniques on 16 bit 79 | dec{8,2}=xor(f_fun(dec{7,4}),dec{7,3}); 80 | 81 | 82 | % %% Modification 83 | % dec{8,1}=dec{3,1}; 84 | % dec{8,2}=dec{3,2}; 85 | % dec{8,3}=dec{3,3}; 86 | % dec{8,4}=dec{3,4}; 87 | 88 | bin_msg=[dec{8,1},dec{8,2},dec{8,3},dec{8,4}]; -------------------------------------------------------------------------------- /SIT-functions/SF_Encrypt.m: -------------------------------------------------------------------------------- 1 | function [cipher]=SF_Encrypt(bin_msg,K1,K2,K3,K4,K5); 2 | %For Encryption of 64 bit msg 3 | bin_msg1=bin_msg(1:32); 4 | bin_msg2=bin_msg(33:64); 5 | 6 | enc=cell(8,4); 7 | % Arranging 64 bit into 16 bit block 8 | enc{1,1}=bin_msg(1:16); 9 | enc{1,2}=bin_msg(17:32); 10 | enc{1,3}=bin_msg(33:48); 11 | enc{1,4}=bin_msg(49:64); 12 | 13 | % For First round 14 | %Step no 01 15 | %performing xnor operation in first 16 bits with K1 16 | enc{2,1}=not(xor(K1,enc{1,1})); 17 | % Using f f_function and swaping tecniques on 16 bit 18 | enc{2,2}=xor(f_fun(enc{2,1}),enc{1,3}); 19 | %performing xnor operation in last 16 bits with K1 20 | enc{2,4}=not(xor(K1,enc{1,4})); 21 | % Using f f_function and swaping tecniques on 16 bit 22 | enc{2,3}=xor(f_fun(enc{2,4}),enc{1,2}); 23 | %Step no 02 24 | 25 | %Swaping Blocks 26 | enc{3,1}=enc{2,2}; 27 | enc{3,2}=enc{2,1}; 28 | enc{3,3}=enc{2,4}; 29 | enc{3,4}=enc{2,3}; 30 | 31 | % For Second Round 32 | %performing Xnor operation with K2 33 | enc{4,1}=not(xor(K2,enc{3,1})); 34 | %Using f f_function and Xor operation obtain second 16 bit block 35 | enc{4,2}=xor(f_fun(enc{4,1}),enc{3,2}); 36 | %Performing xnor operation on last 16 bit 37 | enc{4,4}=not(xor(K2,enc{3,4})); 38 | %Using f f_function and Xor operation obtain third 16 bit block 39 | enc{4,3}=xor(f_fun(enc{4,4}),enc{3,3}); 40 | 41 | % For Third Round 42 | %Step no 01 43 | %performing xnor operation in first 16 bits with K3 44 | enc{5,1}=not(xor(K3,enc{4,1})); 45 | % Using f f_function and swaping tecniques on 16 bit 46 | enc{5,2}=xor(f_fun(enc{5,1}),enc{4,3}); 47 | %performing xnor operation in last 16 bits with K1 48 | enc{5,4}=not(xor(K3,enc{4,4})); 49 | % Using f f_function and swaping tecniques on 16 bit 50 | enc{5,3}=xor(f_fun(enc{5,4}),enc{4,2}); 51 | %Step no 02 52 | %Swaping Blocks 53 | enc{6,1}=enc{5,2}; 54 | enc{6,2}=enc{5,1}; 55 | enc{6,3}=enc{5,4}; 56 | enc{6,4}=enc{5,3}; 57 | 58 | % %% Modified 59 | % enc{3,1}=enc{1,1}; 60 | % enc{3,2}=enc{1,2}; 61 | % enc{3,3}=enc{1,3}; 62 | % enc{3,4}=enc{1,4}; 63 | 64 | %Round no 04 65 | %performing Xnor operation with K4 66 | enc{7,1}=not(xor(K4,enc{6,1})); 67 | %Using f f_function and Xor operation obtain second 16 bit block 68 | enc{7,2}=xor(f_fun(enc{7,1}),enc{6,2}); 69 | %Performing xnor operation on last 16 bit 70 | enc{7,4}=not(xor(K4,enc{6,4})); 71 | %Using f f_function and Xor operation obtain third 16 bit block 72 | enc{7,3}=xor(f_fun(enc{7,4}),enc{6,3}); 73 | 74 | % Round no 05 75 | %performing Xnor operation with K5 76 | enc{8,1}=not(xor(K5,enc{7,1})); 77 | %Using f f_function and Xor operation obtain second 16 bit block 78 | enc{8,2}=xor(f_fun(enc{8,1}),enc{7,3}); 79 | %Performing xnor operation on last 16 bit 80 | enc{8,4}=not(xor(K5,enc{7,4})); 81 | %Using f f_function and Xor operation obtain third 16 bit block 82 | enc{8,3}=xor(f_fun(enc{8,4}),enc{7,2}); 83 | % Encrypted Cipher 84 | 85 | % enc{8,1}=enc{7,1}; 86 | % enc{8,2}=enc{7,2}; 87 | % enc{8,3}=enc{7,3}; 88 | % enc{8,4}=enc{7,4}; 89 | 90 | 91 | cipher=[enc{8,1},enc{8,2},enc{8,3},enc{8,4}]; 92 | % cipher=[enc{3,1},enc{3,2},enc{3,3},enc{3,4}]; -------------------------------------------------------------------------------- /SecureForce.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | tic 5 | addpath('C:\Users\hp\Desktop\Image Processing\Codes\SF-subFunctions\') 6 | Images_Path='C:\Users\hp\Desktop\Image Processing\Images\'; 7 | fname={'lena','baboon','panda','Football','ORLFace'}; % filename 8 | ext= '.jpg'; 9 | 10 | %Selecting Image for encryption 11 | fid=input('Select Image for encryption \n1.Lena\n2.Baboon\n3.Panda\n4.Football\n5.ORLFace\n'); 12 | %fid=1 for lena and so on.. 13 | 14 | Data=imread(strcat(Images_Path,fname{fid},ext)); 15 | [row,col,dim]=size(Data); 16 | if (dim>1) 17 | Data=rgb2gray(Data); % convert into grayscale if input image is a color image 18 | end 19 | 20 | [Data,padding]=Scalling(Data,8); 21 | Data_binary=convert2bin(Data); 22 | 23 | %% Key Selection and Expansion 24 | 25 | %User Inputs the key 26 | hex_key = input('Enter the 64 bit key for encryption: ','s'); 27 | %hex_key = '133457799bbcdff1'; 28 | %hex_key='FFFFFFFFFFFFFFFF'; 29 | [bin_key] = Hex2Bin( hex_key ); 30 | [K1,K2,K3,K4,K5]=SF_Key_Gen(bin_key); 31 | 32 | %% Encryption and Decryption 33 | orignal_msg=[]; 34 | encrypt_msg=[]; 35 | decrypt_msg=[]; 36 | for i=1:size(Data_binary,1) 37 | orignal=Data_binary(i,:); 38 | tic 39 | [cipher]=SF_Encrypt(orignal,K1,K2,K3,K4,K5); 40 | encryption_time(i)=toc; 41 | [plaintext]=SF_Decryption(cipher,K1,K2,K3,K4,K5); 42 | encrypt_msg(:,i)=Binary2Dec(cipher); 43 | decrypt_msg(:,i)=Binary2Dec(plaintext); 44 | end 45 | if (padding~=0) 46 | Data=reshape(Data,[size(Data,1)*size(Data,2) 1]); 47 | Data=Data(1:end-padding); 48 | encrypt_msg=reshape(encrypt_msg,[size(encrypt_msg,1)*size(encrypt_msg,2) 1]); 49 | encrypt_msg=encrypt_msg(1:end-padding); 50 | decrypt_msg=reshape(decrypt_msg,[size(decrypt_msg,1)*size(decrypt_msg,2) 1]); 51 | decrypt_msg=decrypt_msg(1:end-padding); 52 | end 53 | 54 | %% Converting the Vectors into Images 55 | Orignal=uint8(reshape(Data,[row,col])); 56 | Encrypted=uint8(reshape(encrypt_msg,[row,col])); 57 | Decrypted=uint8(reshape(decrypt_msg,[row,col])); 58 | 59 | %Showing image outputs 60 | figure 61 | subplot(1,3,1) 62 | imshow(Orignal) 63 | title('Orignal image') 64 | subplot(1,3,2) 65 | imshow(Encrypted) 66 | title('Encrypted image') 67 | subplot(1,3,3) 68 | imshow(Decrypted) 69 | title('Decrypted image') 70 | 71 | %Histogram 72 | figure 73 | subplot(2,1,1) 74 | imhist(Orignal); 75 | title('Original image histogram') 76 | subplot(2,1,2) 77 | imhist(Encrypted); 78 | title('Encrypted image histogram') 79 | 80 | toc 81 | 82 | %% Calculating the Encrypted and Orignal image's Entropy 83 | Y=(imhist(Encrypted)+0.00001)/(row*col); 84 | Y=-sum(Y.*log2(Y)); 85 | X=(imhist(Orignal)+0.00001)/(row*col); 86 | X=-sum(X.*log2(X)); 87 | Re=[X Y] 88 | display(sprintf('Entropy value of original image is: %f',X)) 89 | display(sprintf('Entropy value of the encrypted image is: %f',Y)) 90 | 91 | %Correlation plot 92 | figure 93 | subplot(1,2,1) 94 | scatter(Orignal(1:end-1),Orignal(2:end),'.') 95 | axis([0 255 0 255]) 96 | title('Correlation plot of Original Image') 97 | subplot(1,2,2) 98 | scatter(Encrypted(1:end-1),Encrypted(2:end),'.') 99 | axis([0 255 0 255]) 100 | title('Correlation plot of Encrypted image') 101 | 102 | % % 1 NPCR(%) 103 | NPCR=sum(sum(Encrypted~=Orignal))*100/(row*col) 104 | 105 | % 2 UACI(%) 106 | UACI=sum(sum(abs(Encrypted-Orignal)))*100/(row*col*255) 107 | 108 | 109 | 110 | display(sprintf('Total encryption time: %f',sum(encryption_time))) 111 | 112 | display('correlation coefficient of original image is: ') 113 | corrcoef(double(Orignal(1:end-1)),double(Orignal(2:end))) 114 | display('correlation coefficient of encrypted image') 115 | corrcoef(double(Encrypted(1:end-1)),double(Encrypted(2:end))) 116 | -------------------------------------------------------------------------------- /Estimated_trajectory.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | images = imageDatastore(fullfile(toolboxdir('vision'), 'visiondata', ... 4 | 'NewTsukuba')); 5 | % Create the camera parameters object using camera intrinsics from the 6 | % New Tsukuba dataset. 7 | K = [615 0 320; 0 615 240; 0 0 1]'; 8 | cameraParams = cameraParameters('IntrinsicMatrix', K); 9 | 10 | % Load ground truth camera poses. 11 | load(fullfile(toolboxdir('vision'), 'visiondata', ... 12 | 'visualOdometryGroundTruth.mat')); 13 | % Create an empty viewSet object to manage the data associated with each view. 14 | vSet = viewSet; 15 | 16 | % Read and display the first image. 17 | Irgb = readimage(images, 1); 18 | player = vision.VideoPlayer('Position', [20, 400, 650, 510]); 19 | step(player, Irgb); 20 | prevI = undistortImage(rgb2gray(Irgb), cameraParams); 21 | 22 | % Detect features. 23 | prevPoints = detectSURFFeatures(prevI, 'MetricThreshold', 500); 24 | 25 | % Select a subset of features, uniformly distributed throughout the image. 26 | numPoints = 150; 27 | prevPoints = selectUniform(prevPoints, numPoints, size(prevI)); 28 | 29 | % Extract features. Using 'Upright' features improves matching quality if 30 | % the camera motion involves little or no in-plane rotation. 31 | prevFeatures = extractFeatures(prevI, prevPoints, 'Upright', true); 32 | 33 | % Add the first view. Place the camera associated with the first view 34 | % at the origin, oriented along the Z-axis. 35 | viewId = 1; 36 | vSet = addView(vSet, viewId, 'Points', prevPoints, 'Orientation', eye(3),... 37 | 'Location', [0 0 0]); 38 | % Setup axes. 39 | figure 40 | axis([-220, 50, -140, 20, -50, 300]); 41 | 42 | % Set Y-axis to be vertical pointing down. 43 | view(gca, 3); 44 | set(gca, 'CameraUpVector', [0, -1, 0]); 45 | camorbit(gca, -120, 0, 'data', [0, 1, 0]); 46 | 47 | grid on 48 | xlabel('X (cm)'); 49 | ylabel('Y (cm)'); 50 | zlabel('Z (cm)'); 51 | hold on 52 | 53 | % Plot estimated camera pose. 54 | cameraSize = 7; 55 | camEstimated = plotCamera('Size', cameraSize, 'Location',... 56 | vSet.Views.Location{1}, 'Orientation', vSet.Views.Orientation{1},... 57 | 'Color', 'g', 'Opacity', 0); 58 | 59 | % Plot actual camera pose. 60 | camActual = plotCamera('Size', cameraSize, 'Location', ... 61 | groundTruthPoses.Location{1}, 'Orientation', ... 62 | groundTruthPoses.Orientation{1}, 'Color', 'b', 'Opacity', 0); 63 | 64 | % Initialize camera trajectories. 65 | trajectoryEstimated = plot3(0, 0, 0, 'g-'); 66 | trajectoryActual = plot3(0, 0, 0, 'b-'); 67 | 68 | legend('Estimated Trajectory', 'Actual Trajectory'); 69 | title('Camera Trajectory'); 70 | % Read and display the image. 71 | viewId = 2; 72 | Irgb = readimage(images, viewId); 73 | step(player, Irgb); 74 | 75 | % Convert to gray scale and undistort. 76 | I = undistortImage(rgb2gray(Irgb), cameraParams); 77 | 78 | % Match features between the previous and the current image. 79 | [currPoints, currFeatures, indexPairs] = helperDetectAndMatchFeatures(... 80 | prevFeatures, I); 81 | 82 | % Estimate the pose of the current view relative to the previous view. 83 | [orient, loc, inlierIdx] = helperEstimateRelativePose(... 84 | prevPoints(indexPairs(:,1)), currPoints(indexPairs(:,2)), cameraParams); 85 | 86 | % Exclude epipolar outliers. 87 | indexPairs = indexPairs(inlierIdx, :); 88 | 89 | % Add the current view to the view set. 90 | vSet = addView(vSet, viewId, 'Points', currPoints, 'Orientation', orient, ... 91 | 'Location', loc); 92 | % Store the point matches between the previous and the current views. 93 | vSet = addConnection(vSet, viewId-1, viewId, 'Matches', indexPairs); 94 | vSet = helperNormalizeViewSet(vSet, groundTruthPoses); 95 | helperUpdateCameraPlots(viewId, camEstimated, camActual, poses(vSet), ... 96 | groundTruthPoses); 97 | helperUpdateCameraTrajectories(viewId, trajectoryEstimated, trajectoryActual,... 98 | poses(vSet), groundTruthPoses); 99 | 100 | prevI = I; 101 | prevFeatures = currFeatures; 102 | prevPoints = currPoints; -------------------------------------------------------------------------------- /SIT_Image_Encryption.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | 5 | %% Initialization 6 | Test=0; % for right key encryption 7 | 8 | %Test=1; % for key sensitivity test 9 | addpath('C:\Users\hp\Desktop\Image Processing\Codes\SF-subFunctions\') 10 | Images_Path = 'C:\Users\hp\Desktop\Image Processing\Images\'; 11 | fname={'Lena','baboon','panda','Football','ORLFace'}; % filename 12 | ext='.jpg'; 13 | 14 | %Selecting image for encryption 15 | fid=input('Select Image for encryption \n1.Lena\n2.Baboon\n3.Panda\n4.Football\n5.ORLFace\n'); 16 | %fid = input('Select image for encryption \n1.Rohit\n'); 17 | %fid=1; % file ID 1 for lena 18 | IS =256; % Image size 19 | Data=imread(strcat(Images_Path,fname{fid},ext)); 20 | if (size(Data,3)==3) 21 | Data=rgb2gray(Data); 22 | end 23 | Data=imresize(Data,[IS IS]); % Image Size 24 | 25 | [row,col]=size(Data); 26 | [Data,padding]=Scalling(Data,8); 27 | Data_binary=convert2bin(Data); 28 | 29 | %User inputs key 30 | hex_key = input('Enter the 16bit key to be used for encryption: ','s'); 31 | %hex_key='FFFFFFFFFFFFFFFF'; 32 | %hex_key = 'AAAAAAAAAAAAAAAA'; 33 | [bin_key] = Hex2Bin( hex_key ); 34 | [K1,K2,K3,K4,K5]=SF_Key_Gen(bin_key); 35 | 36 | orignal_msg=[]; 37 | encrypt_msg=[]; 38 | decrypt_msg=[]; 39 | 40 | %% Encryption Process 41 | for kk=1:2 42 | for i=1:size(Data_binary,1) 43 | orignal=Data_binary(i,:); 44 | tic 45 | [cipher]=SF_Encrypt(orignal,K1,K2,K3,K4,K5); 46 | encryption_time(i)=toc; 47 | tK1=[K1(1:8),orignal(1:8)];tK2=orignal(9:24);tK3=orignal(25:40);tK4=orignal(41:56);tK5=[orignal(57:64),K5(9:16)]; 48 | K1=tK1;K2=tK2;K3=tK3;K4=tK4;K5=tK5; 49 | 50 | encrypt_msg(:,i)=Binary2Dec(cipher); 51 | cipher_data(i,:)=double(cipher); 52 | if(kk<2) 53 | Data_binary(i,:)=cipher_data(i,:); 54 | end 55 | end 56 | if (kk==1) 57 | D=reshape(encrypt_msg,[row,col]); 58 | D=D'; 59 | [row,col]=size(D); 60 | [D,padding]=Scalling(D,8); 61 | % Data=[Data Data]; 62 | Data_binary=double(convert2bin(D)); 63 | TT=[K1,K2,K3,K4,K5]; 64 | encrypt_msg=[]; 65 | end 66 | end 67 | 68 | TTT=TT; 69 | %% Decryption 70 | if (Test==1) 71 | K1(end)=~K1(end); 72 | TT=[K1,K2,K3,K4,K5]; 73 | end 74 | 75 | for kk=kk:-1:1 76 | if(kk==2) 77 | K11=TT(1:16);K12=TT(17:32);K13=TT(33:48);K14=TT(49:64);K15=TT(65:80); 78 | else 79 | [K11,K12,K13,K14,K15]=SF_Key_Gen(bin_key); 80 | D=reshape(decrypt_msg,[row,col]); 81 | D=D'; 82 | [row,col]=size(D); 83 | [D,padding]=Scalling(D,8); 84 | cipher_data=double(convert2bin(D)); 85 | 86 | decrypt_msg=[]; 87 | end 88 | for i=1:size(Data_binary,1) 89 | cipher=cipher_data(i,:); 90 | [plaintext]=SF_Decryption(cipher,K11,K12,K13,K14,K15); 91 | K11=[K11(1:8),plaintext(1:8)];K12=plaintext(9:24);K13=plaintext(25:40);K14=plaintext(41:56);K15=[plaintext(57:64),K15(9:16)]; 92 | 93 | decrypt_msg(:,i)=Binary2Dec(plaintext); 94 | cipher_data(i,:)=double(plaintext); 95 | end 96 | end 97 | 98 | % %% Results 99 | 100 | %Image outputs 101 | 102 | % 5 Orignal Image 103 | Orignal=uint8(reshape(Data,[row,col])); 104 | % 6 Encrypted Image 105 | Encrypted=uint8(reshape(encrypt_msg,[row,col])); 106 | % 7(Wrong Key Decyption (Key Sensitivity)) 107 | Decrypted=uint8(reshape(decrypt_msg,[row,col])); 108 | % %% 5 6 7 109 | figure 110 | subplot(1,3,1) 111 | imshow(Orignal) 112 | title('Orignal image') 113 | subplot(1,3,2) 114 | imshow(Encrypted) 115 | title('Encrypted image') 116 | subplot(1,3,3) 117 | imshow(Decrypted) 118 | title('Decrypted image') 119 | % 120 | % 8 Histogram 121 | figure 122 | subplot(2,1,1) 123 | imhist(Orignal); 124 | title('Original Histogram') 125 | subplot(2,1,2) 126 | imhist(Encrypted); 127 | title('Encrypted image Histogram') 128 | 129 | % 14 Image Entropy 130 | Y=(imhist(Encrypted)+0.00001)/(row*col);%(length(Data)-padding); 131 | Y=-sum(Y.*log2(Y)); 132 | X=(imhist(Orignal)+0.00001)/(row*col);%(length(Data)-padding); 133 | X=-sum(X.*log2(X)); 134 | Re=[X Y] 135 | 136 | display(sprintf('Entropy value of original image is: %f',X)) 137 | display(sprintf('Entropy value of the encrypted image is: %f',Y)) 138 | 139 | % 140 | % 9 Correlation plot 141 | figure 142 | subplot(1,2,1) 143 | scatter(Orignal(1:end-1),Orignal(2:end),'.') 144 | axis([0 255 0 255]) 145 | title('Correlation plot of Original Image') 146 | subplot(1,2,2) 147 | scatter(Encrypted(1:end-1),Encrypted(2:end),'.') 148 | axis([0 255 0 255]) 149 | title('Correlation plot of Encrypted image') 150 | % 151 | % % 1 NPCR(%) 152 | NPCR=sum(sum(Encrypted~=Orignal))*100/(row*col) 153 | 154 | % 2 UACI(%) 155 | UACI=sum(sum(abs(Encrypted-Orignal)))*100/(row*col*255) 156 | 157 | display(fprintf('Total encryption time: %f',sum(encryption_time))) 158 | 159 | display('correlation coefficient of original image is: ') 160 | corrcoef(double(Orignal(1:end-1)),double(Orignal(2:end))) 161 | display('correlation coefficient of encrypted image') 162 | corrcoef(double(Encrypted(1:end-1)),double(Encrypted(2:end))) 163 | 164 | %Results workspace 165 | %save(strcat('R:\Projects\Cryptography\Final Review crypto\Final\Results\SIT',fname{fid},'.mat')) -------------------------------------------------------------------------------- /SF-subFunctions/SF_Key_Gen.m: -------------------------------------------------------------------------------- 1 | function [K1,K2,K3,K4,K5]=SF_Key_Gen(bin_key); 2 | %making a cell 3 | key= cell(5,4); 4 | %First for matrix of 16bit each 5 | key{1,1}=bin_key(1:16); 6 | key{1,2}=bin_key(17:32); 7 | key{1,3}=bin_key(33:48); 8 | key{1,4}=bin_key(49:64); 9 | % generating a matrix of each 16bit int 4*4 10 | key{2,1}(1,:)=key{1,1}(1:4); 11 | key{2,1}(2,:)=key{1,1}(5:8); 12 | key{2,1}(3,:)=key{1,1}(9:12); 13 | key{2,1}(4,:)=key{1,1}(13:16); 14 | key{2,2}(1,:)=key{1,2}(1:4); 15 | key{2,2}(2,:)=key{1,2}(5:8); 16 | key{2,2}(3,:)=key{1,2}(9:12); 17 | key{2,2}(4,:)=key{1,2}(13:16); 18 | key{2,3}(1,:)=key{1,3}(1:4); 19 | key{2,3}(2,:)=key{1,3}(5:8); 20 | key{2,3}(3,:)=key{1,3}(9:12); 21 | key{2,3}(4,:)=key{1,3}(13:16); 22 | key{2,4}(1,:)=key{1,4}(1:4); 23 | key{2,4}(2,:)=key{1,4}(5:8); 24 | key{2,4}(3,:)=key{1,4}(9:12); 25 | key{2,4}(4,:)=key{1,4}(13:16); 26 | 27 | %shifting 28 | key{3,1}(1,:)=key{2,1}(1,:); 29 | key{3,1}(2,:)=circshift(key{2,1}(2,:),[1 1]); 30 | key{3,1}(3,:)=circshift(key{2,1}(3,:),[1 2]); 31 | key{3,1}(4,:)=circshift(key{2,1}(4,:),[1 3]); 32 | 33 | key{3,2}(1,:)=key{2,2}(1,:); 34 | key{3,2}(2,:)=circshift(key{2,2}(2,:),[1 1]); 35 | key{3,2}(3,:)=circshift(key{2,2}(3,:),[1 2]); 36 | key{3,2}(4,:)=circshift(key{2,2}(4,:),[1 3]); 37 | 38 | key{3,3}(1,:)=key{2,3}(1,:); 39 | key{3,3}(2,:)=circshift(key{2,3}(2,:),[1 1]); 40 | key{3,3}(3,:)=circshift(key{2,3}(3,:),[1 2]); 41 | key{3,3}(4,:)=circshift(key{2,3}(4,:),[1 3]); 42 | 43 | key{3,4}(1,:)=key{2,4}(1,:); 44 | key{3,4}(2,:)=circshift(key{2,4}(2,:),[1 1]); 45 | key{3,4}(3,:)=circshift(key{2,4}(3,:),[1 2]); 46 | key{3,4}(4,:)=circshift(key{2,4}(4,:),[1 3]); 47 | 48 | %transposition colomb-wise 49 | key{4,1}=key{3,1}'; 50 | key{4,2}=key{3,2}'; 51 | key{4,3}=key{3,2}'; 52 | key{4,4}=key{3,2}'; 53 | 54 | %performing xor operations 55 | key{5,1}=not(xor(key{4,1},key{4,2})); 56 | key{5,2}=xor(key{5,1},key{4,2}); 57 | key{5,3}=not(xor(key{5,2},key{4,3})); 58 | key{5,4}=xor(key{5,3},key{4,4}); 59 | %concatinate into 64bits 60 | key_64=[key{5,1}(1,:),key{5,1}(2,:),key{5,1}(3,:),key{5,1}(4,:)... 61 | key{5,2}(1,:),key{5,2}(2,:),key{5,2}(3,:),key{5,2}(4,:)... 62 | key{5,3}(1,:),key{5,3}(2,:),key{5,3}(3,:),key{5,3}(4,:)... 63 | key{5,4}(1,:),key{5,4}(2,:),key{5,4}(3,:),key{5,4}(4,:)]; 64 | %p-table 65 | p=[1,17,33,49,50,34,18,2;... 66 | 19,35,51,52,36,20,4,3;... 67 | 37,53,54,38,22,6,5,21;... 68 | 55,56,40,24,8,7,23,39;... 69 | 58,42,26,10,9,25,41,57;... 70 | 44,28,12,11,27,43,59,60;... 71 | 30,14,13,29,45,61,62,46;... 72 | 16,15,31,47,63,64,48,32]; 73 | %key after p-table 74 | for j=1:8 75 | for k=1:8 76 | key_p(j,k)=key_64(p(j,k)); 77 | end 78 | end 79 | %concatinated 64bitkey 80 | p_64=[key_p(1,:),key_p(2,:),key_p(3,:),key_p(4,:)... 81 | key_p(5,:),key_p(6,:),key_p(7,:),key_p(8,:)]; 82 | %Making a cell 83 | key_1=cell(9,4); 84 | % first four matrix of 16bit each 85 | key_1{1,1}=p_64(1:16); 86 | key_1{1,2}=p_64(17:32); 87 | key_1{1,3}=p_64(33:48); 88 | key_1{1,4}=p_64(49:64); 89 | %Each pattern change in matrix of 4*4 90 | key_1{2,1}(1,:)=key_1{1,1}(1:4); 91 | key_1{2,1}(2,:)=key_1{1,1}(5:8); 92 | key_1{2,1}(3,:)=key_1{1,1}(9:12); 93 | key_1{2,1}(4,:)=key_1{1,1}(13:16); 94 | 95 | key_1{2,2}(1,:)=key_1{1,2}(1:4); 96 | key_1{2,2}(2,:)=key_1{1,2}(5:8); 97 | key_1{2,2}(3,:)=key_1{1,2}(9:12); 98 | key_1{2,2}(4,:)=key_1{1,2}(13:16); 99 | 100 | key_1{2,3}(1,:)=key_1{1,3}(1:4); 101 | key_1{2,3}(2,:)=key_1{1,3}(5:8); 102 | key_1{2,3}(3,:)=key_1{1,3}(9:12); 103 | key_1{2,3}(4,:)=key_1{1,3}(13:16); 104 | 105 | key_1{2,4}(1,:)=key_1{1,4}(1:4); 106 | key_1{2,4}(2,:)=key_1{1,4}(5:8); 107 | key_1{2,4}(3,:)=key_1{1,4}(9:12); 108 | key_1{2,4}(4,:)=key_1{1,4}(13:16); 109 | %Performing shift operation 110 | 111 | key_1{3,1}(1,:)=key_1{2,1}(1,:); 112 | key_1{3,1}(2,:)=circshift(key_1{2,1}(2,:),[1 1]); 113 | key_1{3,1}(3,:)=circshift(key_1{2,1}(3,:),[1 2]); 114 | key_1{3,1}(4,:)=circshift(key_1{2,1}(4,:),[1 3]); 115 | 116 | key_1{3,2}(1,:)=key_1{2,2}(1,:); 117 | key_1{3,2}(2,:)=circshift(key_1{2,2}(2,:),[1 1]); 118 | key_1{3,2}(3,:)=circshift(key_1{2,2}(3,:),[1 2]); 119 | key_1{3,2}(4,:)=circshift(key_1{2,2}(4,:),[1 3]); 120 | 121 | key_1{3,3}(1,:)=key_1{2,3}(1,:); 122 | key_1{3,3}(2,:)=circshift(key_1{2,3}(2,:),[1 1]); 123 | key_1{3,3}(3,:)=circshift(key_1{2,3}(3,:),[1 2]); 124 | key_1{3,3}(4,:)=circshift(key_1{2,3}(4,:),[1 3]); 125 | 126 | key_1{3,4}(1,:)=key_1{2,4}(1,:); 127 | key_1{3,4}(2,:)=circshift(key_1{2,4}(2,:),[1 1]); 128 | key_1{3,4}(3,:)=circshift(key_1{2,4}(3,:),[1 2]); 129 | key_1{3,4}(4,:)=circshift(key_1{2,4}(4,:),[1 3]); 130 | 131 | % generate fix matrix 132 | f_mat=cell(1,4); 133 | f_mat{1,1}=[1,2,3,1;2,3,1,1;3,1,1,2;1,1,2,3]; 134 | f_mat{1,2}=[1,2,3,1;1,1,2,3;3,1,1,2;2,3,1,1]; 135 | f_mat{1,3}=[1,2,3,1;2,3,1,1;1,1,2,3;3,1,1,2]; 136 | f_mat{1,4}=[1,2,3,1;1,1,2,3;2,3,1,1;3,1,1,2]; 137 | 138 | % multiply fix matrix #1 with shifted matrix 139 | for j=1:4 140 | for k=1:4 141 | tmp=(key_1{3,1}(:,j))'; 142 | if f_mat{1,1}(j,k)==1 143 | key_1{4,1}(j,k)=cellstr(num2str(tmp)); 144 | elseif f_mat{1,1}(j,k)==2 145 | key_1{4,1}(j,k)=cellstr(num2str(circshift(tmp,[1 1]))); 146 | elseif f_mat{1,1}(j,k)==3 147 | tmp1=circshift(tmp,[1 1]); 148 | key_1{4,1}(j,k)=cellstr(num2str(xor(tmp,tmp1))); 149 | end 150 | end 151 | end 152 | 153 | % multiply fix matrix #2 with shifted matrix 154 | for j=1:4 155 | for k=1:4 156 | tmp=(key_1{3,2}(:,j))'; 157 | if f_mat{1,2}(j,k)==1 158 | key_1{4,2}(j,k)=cellstr(num2str(tmp)); 159 | elseif f_mat{1,2}(j,k)==2 160 | key_1{4,2}(j,k)=cellstr(num2str(circshift(tmp,[1 1]))); 161 | elseif f_mat{1,2}(j,k)==3 162 | tmp1=circshift(tmp,[1 1]); 163 | key_1{4,2}(j,k)=cellstr(num2str(xor(tmp,tmp1))); 164 | end 165 | end 166 | end 167 | 168 | % multiply fix matrix #3 with shifted matrix 169 | for j=1:4 170 | for k=1:4 171 | tmp=(key_1{3,3}(:,j))'; 172 | if f_mat{1,3}(j,k)==1 173 | key_1{4,3}(j,k)=cellstr(num2str(tmp)); 174 | elseif f_mat{1,3}(j,k)==2 175 | key_1{4,3}(j,k)=cellstr(num2str(circshift(tmp,[1 1]))); 176 | elseif f_mat{1,3}(j,k)==3 177 | tmp1=circshift(tmp,[1 1]); 178 | key_1{4,3}(j,k)=cellstr(num2str(xor(tmp,tmp1))); 179 | end 180 | end 181 | end 182 | 183 | % multiply fix matrix #4 with shifted matrix 184 | 185 | for j=1:4 186 | for k=1:4 187 | tmp=(key_1{3,4}(:,j))'; 188 | if f_mat{1,4}(j,k)==1 189 | key_1{4,4}(j,k)=cellstr(num2str(tmp)); 190 | elseif f_mat{1,4}(j,k)==2 191 | key_1{4,4}(j,k)=cellstr(num2str(circshift(tmp,[1 1]))); 192 | elseif f_mat{1,4}(j,k)==3 193 | tmp1=circshift(tmp,[1 1]); 194 | key_1{4,4}(j,k)=cellstr(num2str(xor(tmp,tmp1))); 195 | end 196 | end 197 | end 198 | 199 | % shifting After fix matrix Multiplication 200 | key_1{5,1}(1,:)=key_1{4,1}(1,:); 201 | key_1{5,1}(2,:)=circshift(key_1{4,1}(2,:),[1 1]); 202 | key_1{5,1}(3,:)=circshift(key_1{4,1}(3,:),[1 2]); 203 | key_1{5,1}(4,:)=circshift(key_1{4,1}(4,:),[1 3]); 204 | 205 | key_1{5,2}(1,:)=key_1{4,2}(1,:); 206 | key_1{5,2}(2,:)=circshift(key_1{4,2}(2,:),[1 1]); 207 | key_1{5,2}(3,:)=circshift(key_1{4,2}(3,:),[1 2]); 208 | key_1{5,2}(4,:)=circshift(key_1{4,2}(4,:),[1 3]); 209 | 210 | key_1{5,3}(1,:)=key_1{4,3}(1,:); 211 | key_1{5,3}(2,:)=circshift(key_1{4,3}(2,:),[1 1]); 212 | key_1{5,3}(3,:)=circshift(key_1{4,3}(3,:),[1 2]); 213 | key_1{5,3}(4,:)=circshift(key_1{4,3}(4,:),[1 3]); 214 | 215 | key_1{5,4}(1,:)=key_1{4,4}(1,:); 216 | key_1{5,4}(2,:)=circshift(key_1{4,4}(2,:),[1 1]); 217 | key_1{5,4}(3,:)=circshift(key_1{4,4}(3,:),[1 2]); 218 | key_1{5,4}(4,:)=circshift(key_1{4,4}(4,:),[1 3]); 219 | 220 | % Performing And Operation row Wise 221 | for i=1:length(key_1{5,1}) 222 | tmp(i,:)=and(logical(str2num(key_1{5,1}{1,i})),logical(str2num(key_1{5,1}{2,i}))); 223 | tmp1(i,:)=and(logical(str2num(key_1{5,1}{3,i})),logical(str2num(key_1{5,1}{4,i}))); 224 | key_1{6,1}(i,:)=and(tmp(i,:),tmp1(i,:)); 225 | end 226 | 227 | for i=1:length(key_1{5,2}) 228 | tmp(i,:)=xor(logical(str2num(key_1{5,2}{1,i})),logical(str2num(key_1{5,2}{2,i}))); 229 | tmp1(i,:)=xor(logical(str2num(key_1{5,2}{3,i})),logical(str2num(key_1{5,2}{4,i}))); 230 | key_1{6,2}(i,:)=xor(tmp(i,:),tmp1(i,:)); 231 | end 232 | 233 | for i=1:length(key_1{5,3}) 234 | tmp(i,:)=and(logical(str2num(key_1{5,3}{1,i})),logical(str2num(key_1{5,3}{2,i}))); 235 | tmp1(i,:)=and(logical(str2num(key_1{5,3}{3,i})),logical(str2num(key_1{5,3}{4,i}))); 236 | key_1{6,3}(i,:)=and(tmp(i,:),tmp1(i,:)); 237 | end 238 | 239 | for i=1:length(key_1{5,4}) 240 | tmp(i,:)=xor(logical(str2num(key_1{5,4}{1,i})),logical(str2num(key_1{5,4}{2,i}))); 241 | tmp1(i,:)=xor(logical(str2num(key_1{5,4}{3,i})),logical(str2num(key_1{5,4}{4,i}))); 242 | key_1{6,4}(i,:)=xor(tmp(i,:),tmp1(i,:)); 243 | end 244 | 245 | % performing xor operation to 4x4(16 bit block) 246 | 247 | % Result 4 bit key will be obtain 248 | 249 | tmp=xor(key_1{6,1}(1,:),key_1{6,1}(2,:)); 250 | tmp1=xor(key_1{6,1}(3,:),key_1{6,1}(4,:)); 251 | key_1{7,1}=xor(tmp,tmp1); 252 | 253 | tmp=xor(key_1{6,2}(1,:),key_1{6,2}(2,:)); 254 | tmp1=xor(key_1{6,2}(3,:),key_1{6,2}(4,:)); 255 | key_1{7,2}=xor(tmp,tmp1); 256 | 257 | tmp=xor(key_1{6,3}(1,:),key_1{6,3}(2,:)); 258 | tmp1=xor(key_1{6,3}(3,:),key_1{6,3}(4,:)); 259 | key_1{7,3}=xor(tmp,tmp1); 260 | 261 | tmp=xor(key_1{6,4}(1,:),key_1{6,4}(2,:)); 262 | tmp1=xor(key_1{6,4}(3,:),key_1{6,4}(4,:)); 263 | key_1{7,4}=xor(tmp,tmp1); 264 | 265 | %using transposition table 266 | 267 | trans_mat=cell(1,4); 268 | trans_mat{1,1}=[0,0,0,0;0,0,0,1;0,0,1,0;0,0,1,1]; 269 | trans_mat{1,2}=[0,1,0,0;0,1,0,1;0,1,1,0;0,1,1,1]; 270 | trans_mat{1,3}=[1,0,0,0;1,0,0,1;1,0,1,0;1,0,1,1]; 271 | trans_mat{1,4}=[1,1,0,0;1,1,0,1;1,1,1,0;1,1,1,1]; 272 | 273 | % For First key by Transposition 274 | 275 | for i=1:length(trans_mat) 276 | for j=1:length(key_1{6,1}) 277 | if key_1{7,1}(1,:)==trans_mat{1,i}(j,:) 278 | if i==1 279 | key_1{8,1}=[key_1{6,1}(:,1),key_1{6,1}(:,4),key_1{6,1}(:,2),... 280 | key_1{6,1}(:,3)]; 281 | elseif i==2 282 | key_1{8,1}=[key_1{6,1}(:,2),key_1{6,1}(:,3),key_1{6,1}(:,4),... 283 | key_1{6,1}(:,1)]; 284 | elseif i==3 285 | key_1{8,1}=[key_1{6,1}(:,3),key_1{6,1}(:,2),key_1{6,1}(:,1),... 286 | key_1{6,1}(:,4)]; 287 | else i==4 288 | key_1{8,1}=[key_1{6,1}(:,4),key_1{6,1}(:,1),key_1{6,1}(:,3),... 289 | key_1{6,1}(:,2)]; 290 | end 291 | end 292 | end 293 | end 294 | 295 | % For Second key by Real Fence 296 | 297 | key_1{8,2}=[key_1{6,2}(1,:);circshift(key_1{6,2}(2,:),[1 1]);... 298 | key_1{6,2}(3,:);circshift(key_1{6,2}(4,:),[1 1])]; 299 | 300 | 301 | % For Third key by Real Fence 302 | 303 | key_1{8,3}=[key_1{6,3}(1,:);circshift(key_1{6,3}(2,:),[1 1]);... 304 | key_1{6,3}(3,:);circshift(key_1{6,3}(4,:),[1 1])]; 305 | 306 | 307 | % For Fourth key by transposition 308 | 309 | for i=1:length(trans_mat) 310 | for j=1:length(key_1{6,4}) 311 | if key_1{7,4}(1,:)==trans_mat{1,i}(j,:) 312 | if i==1 313 | key_1{8,4}=[key_1{6,4}(:,1),key_1{6,4}(:,4),key_1{6,4}(:,2),... 314 | key_1{6,4}(:,3)]; 315 | elseif i==2 316 | key_1{8,4}=[key_1{6,4}(:,2),key_1{6,4}(:,3),key_1{6,4}(:,4),... 317 | key_1{6,4}(:,1)]; 318 | elseif i==3 319 | key_1{8,4}=[key_1{6,4}(:,3),key_1{6,4}(:,2),key_1{6,4}(:,1),... 320 | key_1{6,4}(:,4)]; 321 | else i==4 322 | key_1{8,4}=[key_1{6,4}(:,4),key_1{6,4}(:,1),key_1{6,4}(:,3),... 323 | key_1{6,4}(:,2)]; 324 | end 325 | end 326 | end 327 | end 328 | 329 | % For Final KEY K1 330 | key_1{9,1}=[key_1{8,1}(1,:),key_1{8,1}(2,:),key_1{8,1}(3,:),key_1{8,1}(4,:)]; 331 | K1=key_1{9,1}; 332 | % For Final KEY K2 333 | key_1{9,2}=[key_1{8,2}(:,1)',flipdim(key_1{8,2}(:,2)',2),key_1{8,2}(:,3)',... 334 | flipdim(key_1{8,2}(:,4)',2)]; 335 | K2=key_1{9,2}; 336 | % For Final KEY K3 337 | key_1{9,3}=[key_1{8,3}(:,1)',flipdim(key_1{8,3}(:,2)',2),key_1{8,3}(:,3)',... 338 | flipdim(key_1{8,3}(:,4)',2)]; 339 | K3=key_1{9,3}; 340 | % For Final KEY K4 341 | key_1{9,4}=[key_1{8,4}(1,:),key_1{8,4}(2,:),key_1{8,4}(3,:),key_1{8,4}(4,:)]; 342 | K4=key_1{9,4}; 343 | % For Final KEY K5 344 | tmp=xor(K1,K2); 345 | tmp1=xor(K3,K4); 346 | K5=xor(tmp,tmp1); --------------------------------------------------------------------------------