1 function hashVec=
hash(inpArr,methodName)
14 hashVec=
hashinner(
'valueisemptynohash',methodName);
19 function hashVec=
structhash(structB,methodName)
20 fieldNames=fieldnames(structB);
22 [{
'itisastruct';num2str(size(structB))};fieldNames],methodName);
24 hashMat=[hashMat;
cellhash(struct2cell(structB),methodName)];
28 function hashVec=
cellhash(cellB,methodName)
31 hashCell=cellfun(@(x)
hash(x,methodName),cellB,
'UniformOutput',
false);
32 hashCell=reshape(hashCell,[],1);
34 hashMat=[
hash([
'itisacell' num2str(size(cellB))]);hashMat];
35 hashVec=
hash(hashMat,methodName);
41 % convert strings and logicals into uint8 format
42 if ischar(inpVec) || islogical(inpVec)
43 byteVec=uint8(inpVec);
44 else % convert everything
else into uint8 format without loss of data
45 if isnumeric(inpVec)&&isreal(inpVec)
46 byteVec=typecast(inpVec,
'uint8');
48 byteVec=getByteStreamFromArray(inpArr);
52 % verify
hash method, with some syntactical forgiveness:
65 algs={
'MD2',
'MD5',
'SHA-1',
'SHA-256',
'SHA-384',
'SHA-512'};
66 if isempty(strcmp(meth,algs))
67 mxberry.
core.throwerror(
'wrongInput',[
'Hash algorithm must be ' ...
68 'MD2, MD5, SHA-1, SHA-256, SHA-384, or SHA-512']);
71 x=java.security.MessageDigest.getInstance(meth);
73 h=typecast(x.digest,
'uint8');
75 if(size(h,1))==1 % remote possibility: all hash bytes < 128, so pad: 76 h=[repmat('0
',[1 size(h,2)]);h]; function cellhash(in cellB, in methodName)
function hash(in inpArr, in methodName)
OBJECTHASH counts the hash of input object/array.
function hashinner(in inpArr, in meth)
HASH - Convert an input variable into a message digest using any of several common hash algorithms...
function structhash(in structB, in methodName)
function cell2mat(in inpCArr)
CELL2MAT does the same as the built-in cell2mat function but a) 20% faster b) works with cell arrays ...