2023年12月8日发(作者:)
matlabmd5代码,用MD5或SHA校验Matlab数组,结构,细胞
或文件
DataHash
DATAHASH - Checksum for Matlab array, struct, cell or file
Hash = DataHash(Data, Opt)
Data: Array of built-in types (U)INT8/16/32/64, SINGLE, DOUBLE (real or complex)
CHAR, LOGICAL, CELL, STRUCT (scalar or array, nested), function_handle.
Opt: Options struct:
: 'SHA-1', 'SHA-256', 'SHA-384', 'SHA-512', 'MD2', 'MD5'.
: 'hex', 'HEX', 'double', 'uint8', 'base64'.
:
'file': Data is a file name.
'bin': Only the contents of Data is considered.
Data must be numerical of a CHAR.
'array': Default, contents and type of Data are considered.
Nested CELLs and STRUCTs possible.
Hash: String or numeric vector.
EXAMPLES:
Default: MD5, hex:
DataHash([]) % 7de5637fd217d0e44e0082f4d79b3e73
SHA-1, Base64:
S.a = uint8([]);
S.b = {{1:10}, struct('q', uint64(415))};
= 'base64';
= 'SHA-1';
DataHash(S, Opt) % ZMe4eUAp0G9TDrvSW0/Qc0gQ9/A
This function uses James Tursa's smart and fast TYPECASTX, if installed:
For Matlab 6.5 installing TYPECASTX is obligatory to run DataHash.
Michael Kleder's "Compute Hash" works very similar, but does not accept structs, cells or files:
"CalcMD5" uses a faster C-Mex to create only the MD5 sum for an array or file:
Tested: Matlab 6.5, 7.7, 7.8, 7.13, WinXP, Win7/64, Java: 1.3.1_01, 1.6.0_04.
Bugreports and enhancement requests are welcome.


发布评论