can someone help me in coding hash 512 algorithm?

1 view (last 30 days)
yogya
yogya on 9 Nov 2014
Commented: Jan on 9 Nov 2014
hello i need a hash value that provide me as decimal value from 512 bits binary value. can someone please correct my code and help me. Where my code is
data = input('enter the data:','s');
pawrd = input('enter the password:','s');
bin = double(data);
display(bin);
n = dec2base(bin,16);
display(n);
len_n = length(n);
display(len_n);
k = dec2bin(bin,8);
display(k);
pwd = dec2bin(pawrd,8)';
pwd = pwd(:)'-'0';
ln_pwd = length(pwd);
disp(ln_pwd);
pad_pwd = [pwd , ones(1,64-ln_pwd)];
A = dec2bin(data,8)';
A = A(:)'-'0';
le_a = length(A);
pad2 = dec2bin(le_a,8)';
pad2 = pad2(:)'-'0';
j = length(pad2);
dap2 = [zeros(1,128-j), pad2];
display(pad2);
display(A);
display(le_a);
x = 896-le_a;
display(x);
if x == 0
display('seq need not to be padded');
else
padarray = [ones(1,1), zeros(1,x-1)];
paddedseq = [A, padarray];
finalpad = [paddedseq, dap2];
l_paddedseq = length(finalpad);
display(l_paddedseq);
display(paddedseq);
display(finalpad);
x1 = '6A09E667F3BCC908';
x2 = 'BB67AE8584CAA73B';
x3 = '3C6EF372FE94F82B';
x4 = 'A54FF53A5F1D36F1';
x5 = '510E527FADE682D1';
x6 = '9B05688C2B3E6C1F';
x7 = '1F83D9ABFB41BD6B';
x8 = '5BE0CD19137E2179';
bx1 = base2dec(x1,16);
bx2 = base2dec(x2,16);
bx3 = base2dec(x3,16);
bx4 = base2dec(x4,16);
bx5 = base2dec(x5,16);
bx6 = base2dec(x6,16);
bx7 = base2dec(x7,16);
bx8 = base2dec(x8,16);
a = dec2bin(bx1,64);
display(a);
b = dec2bin(bx2,64);
display(b);
c = dec2bin(bx3,64);
display(c);
d = dec2bin(bx4,64);
display(d);
e = dec2bin(bx5,64);
display(e);
f = dec2bin(bx6,64);
display(f);
g = dec2bin(bx7,64);
display(g);
h = dec2bin(bx8,64);
display(h);
end
w =reshape(finalpad,16,64);
display(w);
wi = w(i, 1:64);
disp(wi);
ki = circshift(pad_pwd,1);
disp(ki);
and1 = e&f;
and2 = (~e)&g;
and3 = a&b;
and4 = a&c;
and5 = b&c;
Ch = bitxor(and1,and2);
display(and1);
display(and2);
display(Ch);
Maj1 = bitxor(and3,and4);
display(Maj1);
maj = bitxor(Maj1,and5);
display(maj);
r1 = circshift(e,[0 +14])-'0' ;
disp(r1);
r2 = circshift(e,[0 +18])-'0';
disp(r2);
r3 = circshift(e,[0 +41])-'0';
r4 = circshift(a,[0 +28])-'0';
r5 = circshift(a,[0 +34])-'0';
r6 = circshift(a,[0 +39])-'0';
r12 = bitxor(r1,r2);
r45 = bitxor(r4,r5);
sum1e = bitxor(r12,r3);
sum0a = bitxor(r45,r6);
T1 = h|Ch|wi|ki|sum1e;
disp(T1);
T2 = maj|sum0a;
disp(T2);
h = g;
disp(h);
g = f;
disp(g);
f = e;
disp(f);
e = d|T1;
disp(e);
d = c;
disp(d);
c = b;
disp(c);
b = a;
disp(b);
a = T1|T2;
disp(a);
a=a(a~='0');
disp(a);
  1 Comment
Jan
Jan on 9 Nov 2014
If you want a correction of your code, you have to mention, what you assume to be a bug. It is impossible to find a bug based on working code only.

Sign in to comment.

Answers (0)

Categories

Find more on Chemistry in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!