How to implement SHA256 to get hash value for image?
13 次查看(过去 30 天)
显示 更早的评论
I try to implement this paper:" A novel plaintext-related image encryption scheme using hyper-chaotic system"
I try to implement permutation process: I have an image and I need to implement SHA256 for sum of pixels image, then i need divide the output(256bits) of SHA256 as initial key for lorenz system. I write this code but I could'nt understand how we take output(256bits) of SHA256 as initial key for lorenz system by divid its 4 parts, every parts have many bits.
What is value of A1,A2,A3 and A4 after divided output(256bits) of SHA256 to calculat the initial conditions (Px0, Py0, Pz0, and Pw0) ???.
A1=? , A2=?, A3=?and A4=?
I need some one cooperate and help me to implement all steps in this paper and I would be grateful for your help.
%%%%%%%%%%%%%%%%%%%% code of permutation algorithm in paper :" A novel plaintext-related image encryption scheme using %hyper-chaotic system: permutation phase"
close all;
clear all;
clc;
tic
timg = imread('lena.bmp');
[row,col]=size(timg);
s=row*col;
img=reshape(timg,s,1);% 1 means 1 col to make matrix in one dim
x=sum(img);
string_img = num2str(x); % Converts numeric matrices to a string
string_img = string_img(~isspace(num2str(string_img)));
% Perform hashing
sha256hasher = System.Security.Cryptography.SHA256Managed; % Create hash object (?) - this part was copied from the forum post mentioned above, so no idea what it actually does
imageHash_uint8 = uint8(sha256hasher.ComputeHash(uint8(string_img))); % Find uint8 of hash, outputs as a 1x32 uint8 array
imageHash_hex = dec2hex(imageHash_uint8);
imageHash_bin=uint8(dec2bin(imageHash_uint8));
% let's say tha the initial key is :
initial_key_hex=['FE', 'DC' 'BA' '98' '76' '54' '32' '10' '12' '34' '56' '78' '9A' 'BC' 'DE' 'FE'];
% calculate IC1
sha256hasher2 = System.Security.Cryptography.SHA256Managed; % Create hash object (?) - this part was copied from the forum post mentioned above, so no idea what it actually does
keyHash_uint8 = uint8(sha256hasher.ComputeHash(uint8(initial_key_hex))); % Find uint8 of hash, outputs as a 1x32 uint8 array
keyHash_hex = dec2hex(keyHash_uint8);
keyHash_bin=uint8(dec2bin(keyHash_uint8));
IC1=bitxor(imageHash_bin,keyHash_bin);
% calculate IC2
string_ic1= num2str(IC1);
sha256hasher3 = System.Security.Cryptography.SHA256Managed; % Create hash object (?) - this part was copied from the forum post mentioned above, so no idea what it actually does
IC2Hash_uint8 = uint8(sha256hasher.ComputeHash(uint8(initial_key_hex))); % Find uint8 of hash, outputs as a 1x32 uint8 array
IC2Hash_hex = dec2hex(IC2Hash_uint8);
IC2Hash_bin=(dec2bin(IC2Hash_uint8));
% Split IC2 into four parts, and every part with 64 bits,
%denoted as A1, A2, A3, and A4.
A1=(IC2Hash_bin(1:8,:));
A2=IC2Hash_bin(9:16,:);
A3=IC2Hash_bin(17:24,:);
A4=IC2Hash_bin(25:32,:);
% The initial conditions (Px0, Py0, Pz0, and Pw0)
%of hyper-chaotic Lorenz system given in Eq. (2) are generated by:
px0=(mod(fix(A1/(10^8)),80)-40)+(A1/(10^14)-fix(A1/(10^14)));
py0=(mod(fix(A2/(10^8)),80)-40)+(A2/(10^14)-fix(A2/(10^14)));
pz0=(mod(fix(A3/(10^8)),80)-40)+(A3/(10^14)-fix(A3/(10^14)));
pw0=(mod(fix(A4/(10^8)),80)-40)+(A4/(10^14)-fix(A4/(10^14)));
3 个评论
Jan
2021-12-17
编辑:Jan
2021-12-17
I do not know the paper.
Are you sure, that you need the UINT8, Hex and decimal representation of the hash? If A1 are really the decimal value of the UINT8 value, dividing it by 1e8 and 1e14 is meaningless, because all values are vanishing then.
This does not look correct:
IC2Hash_uint8 = uint8(sha256hasher.ComputeHash(uint8(initial_key_hex)));
IC2Hash_bin=(dec2bin(IC2Hash_uint8));
A1=(IC2Hash_bin(1:8,:));
I assume, that the paper uses another method.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!