4.71429

4.7 | 14 ratings Rate this file 303 downloads (last 30 days) File Size: 2.58 KB File ID: #8944

Compute hash using MD2, MD5, SHA-1, SHA-256, SHA-384, or SHA-512

by Michael Kleder

 

04 Nov 2005 (Updated 03 May 2006)

No BSD License  

Hashes a string (or other MATLAB variable) using a vairiety of hash algorithms

Download Now | Watch this File

File Information
Description

Recently, some common hash algorithms have been criticized in cryptological studies. In response, more choices among common hash algorithms need to be available.

This function, called HASH, computes a digest using a hash function chosen from among MD2, MD5, SHA-1, SHA-256, SHA-384, and SHA-512. It can hash strings or variables of several data types. Use "help hash" for more information.

Michael Kleder, Nov 2005

MATLAB release MATLAB 7.0.4 (R14SP2)
Other requirements This function uses Java.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (19)
26 Feb 2006 Tim Dirchley

very fast & useful

02 May 2006 Andrew Medlin

Simple and useful reference for computing hash values.

04 Jul 2006 Sharat Chikkerur

very useful. Saved myself a lot of coding

09 Nov 2006 Stephan Hellerbrand

Very useful tool. Thanks!

04 Dec 2006 M I

Very useful tool. Thanks
Simple and useful reference for computing hash values, and quick!

29 Dec 2006 billow he

Thanks for your contribution, it will help me much in my work.

22 Mar 2007 JongMin Jeong  
30 Mar 2007 George Varbanov

Interesting Good

06 Nov 2007 P. McNamara

Be careful. Also we are looking at your downloads records.

04 May 2008 Peter Pan  
13 Aug 2008 ahmed abd ellatif

thank you

28 Oct 2008 Chris Rodgers

To cope with complex input, replace with this code from line 46:

else % convert everything else into uint8 format without loss of data
    if ~isreal(inp)
        inp=reshape([real(inp(:)).'; imag(inp(:)).'],[],1);
    end
    inp=typecast(inp,'uint8');
end

20 Dec 2008 mani kandan

Sir,
I am Manikandan from INDIA. Ur code for SHA and other hash algorithms are ok. But , I got an error. Plz. check ur mail id.. and help me on this regard.

mail me at manekantan@gmail.com

23 Dec 2008 Evaristo Rojas Mayoral

It woks OK.

12 Feb 2009 mani kandan

Sir, this code is working fine. But , Sir, Is it compatible for Images
I could not get the proper hash , for images
plz reply to manekantan@gmail.com

10 Jun 2009 Derek Hoyle

Very elegant!

12 Jun 2009 Thomas Deneux

clear and useful!

20 Oct 2009 Jan Simon

Works correctly, good help, no H1-line, example, date and author mentioned in the source.

~any(strcmp(meth, algs))
  is faster than:
isempty(strmatch(meth,algs,'exact'))

The conversion of the HEX output is to complicated:
  h=typecast(x.digest,'uint8');
  h=dec2hex(h)';
  if(size(h,1))==1
     h=[repmat('0',[1 size(h,2)]);h];
  end
  h=lower(h(:)');
Easier and faster:
  h = sprintf('%.2x', typecast(x.digest, 'uint8'));
For Matlab 6.5: only MD5 and SHA-1 are working, TYPECAST must be downloaded from FEX, and the SPRINTF needs a cast to DOUBLE.

Because you call Java for the calculation, this is not very fast, but still the most reliable hash tool in the FEX. Thanks!

09 Nov 2009 Danila  
Please login to add a comment or rating.
Updates
09 Nov 2005

title & comment clarifications

03 May 2006

Three minor syntax adjustments suggested by MLINT were made. There is no functional impact except a very small improvement in speed.

Tag Activity for this File
Tag Applied By Date/Time
md2 Michael Kleder 22 Oct 2008 08:05:31
md5 Michael Kleder 22 Oct 2008 08:05:31
sha1 Michael Kleder 22 Oct 2008 08:05:31
sha256 Michael Kleder 22 Oct 2008 08:05:31
sha512 Michael Kleder 22 Oct 2008 08:05:31
sha384 Michael Kleder 22 Oct 2008 08:05:31
md2 Thomas Deneux 12 Jun 2009 10:01:38
md2 Fuzzy Worm 13 Jul 2009 03:01:00
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com