how to convert md5 hash value as binary bits?

5 ビュー (過去 30 日間)
Megha Nayar
Megha Nayar 2019 年 5 月 29 日
コメント済み: Jan 2021 年 2 月 5 日
Hi,
Suppose hash string is YuRtBM.. (something like this), i need it as 000101010 (128 bits because its md5).
  2 件のコメント
yougharta ghennai
yougharta ghennai 2021 年 2 月 5 日
any answer for this problem my friend ?
Jan
Jan 2021 年 2 月 5 日
編集済み: Jan 2021 年 2 月 5 日
"(something like this)" is not enough to define the input uniquely. Maybe this is base64?

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2021 年 2 月 5 日
With the bold guess, that the input is a base64 string:
Out = matlab.net.base64decode('YuRtBM');
Bmat = dec2bin(Out);
Bvec = reshape(Bmat.', 1, []) - '0'
  2 件のコメント
yougharta ghennai
yougharta ghennai 2021 年 2 月 5 日
% i find something better than that i gues
hash = 'dc1c320defa535b9d8177fc07ace6481';
%there are 32 chars on hex ==> 2 chars for 1 element .
% ==> we use that and it will give you directly the 128 bits :
binary_hash = hexToBinaryVector(hash);
disp(binary_hash);
% and you will notice it .
Jan
Jan 2021 年 2 月 5 日
In the original question the hash was "YuRtBM..." which is not a hex string.
hexToBinaryVector is part of the Sata Acquisition Toolbox. Without it:
hash = 'dc1c320defa535b9d8177fc07ace6481';
hexToBin(hash)
function bin = hexToBin(hex)
dec = sscanf(hex, '%2x').';
bin = rem(floor(dec ./ pow2(7:-1:0).'), 2); % Auto-expand, >= R2016b
bin = reshape(bin, 1, []);
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by