Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
SHA message digest

Subject: SHA message digest

From: Abbas Cheddad

Date: 19 Nov, 2008 10:55:04

Message: 1 of 4

Hi,

I am using SHA-1 hash algorithm to digest a message. It is said (see for example Wikipedia) that SHA-1 (as well as SHA-0) produces a 160-bit digest from a message. That is 20 Hex * 8= 160 bits.

However, the built in function in PHP and another using Java produce apparently

40 hex * 8= 320 bits.

For example:

SHA('Test')='A94A8FE5CCB19BA61C4C0873D391E987982FBBD3'
dec2bin(double(SHA('Test')),8)=8*40


Any help here guys?


Cheers,
Abbas

Subject: SHA message digest

From: David

Date: 19 Nov, 2008 11:08:01

Message: 2 of 4

"Abbas Cheddad" <cheddad10NOSPAM@yahoo.com> wrote in message <gg0ra8$onh$1@fred.mathworks.com>...
> Hi,
>
> I am using SHA-1 hash algorithm to digest a message. It is said (see for example Wikipedia) that SHA-1 (as well as SHA-0) produces a 160-bit digest from a message. That is 20 Hex * 8= 160 bits.
>
> However, the built in function in PHP and another using Java produce apparently
>
> 40 hex * 8= 320 bits.
>
> For example:
>
> SHA('Test')='A94A8FE5CCB19BA61C4C0873D391E987982FBBD3'
> dec2bin(double(SHA('Test')),8)=8*40
>
>
> Any help here guys?
>
>
> Cheers,
> Abbas


a single hex digit is only 4 bits.

Subject: SHA message digest

From: Abbas Cheddad

Date: 19 Nov, 2008 13:00:20

Message: 3 of 4

Thanks David for the prompt reply. I did get it. But I am left wondering what would double produce in this case:
double('A')=65. Is it hardware dependent precision, meaning if I migrate to another machine will I get different value?

Thanks again.

=================================
"David" <dave@bigcompany.com> wrote in message <gg0s2h$3ls$1@fred.mathworks.com>...
> "Abbas Cheddad" <cheddad10NOSPAM@yahoo.com> wrote in message <gg0ra8$onh$1@fred.mathworks.com>...
> > Hi,
> >
> > I am using SHA-1 hash algorithm to digest a message. It is said (see for example Wikipedia) that SHA-1 (as well as SHA-0) produces a 160-bit digest from a message. That is 20 Hex * 8= 160 bits.
> >
> > However, the built in function in PHP and another using Java produce apparently
> >
> > 40 hex * 8= 320 bits.
> >
> > For example:
> >
> > SHA('Test')='A94A8FE5CCB19BA61C4C0873D391E987982FBBD3'
> > dec2bin(double(SHA('Test')),8)=8*40
> >
> >
> > Any help here guys?
> >
> >
> > Cheers,
> > Abbas
>
>
> a single hex digit is only 4 bits.

Subject: SHA message digest

From: David

Date: 19 Nov, 2008 14:17:01

Message: 4 of 4

"Abbas Cheddad" <cheddad10NOSPAM@yahoo.com> wrote in message <gg12l4$85r$1@fred.mathworks.com>...
> Thanks David for the prompt reply. I did get it. But I am left wondering what would double produce in this case:
> double('A')=65. Is it hardware dependent precision, meaning if I migrate to another machine will I get different value?
>
> Thanks again.
>
> =================================
> "David" <dave@bigcompany.com> wrote in message <gg0s2h$3ls$1@fred.mathworks.com>...
> > "Abbas Cheddad" <cheddad10NOSPAM@yahoo.com> wrote in message <gg0ra8$onh$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > I am using SHA-1 hash algorithm to digest a message. It is said (see for example Wikipedia) that SHA-1 (as well as SHA-0) produces a 160-bit digest from a message. That is 20 Hex * 8= 160 bits.
> > >
> > > However, the built in function in PHP and another using Java produce apparently
> > >
> > > 40 hex * 8= 320 bits.
> > >
> > > For example:
> > >
> > > SHA('Test')='A94A8FE5CCB19BA61C4C0873D391E987982FBBD3'
> > > dec2bin(double(SHA('Test')),8)=8*40
> > >
> > >
> > > Any help here guys?
> > >
> > >
> > > Cheers,
> > > Abbas
> >
> >
> > a single hex digit is only 4 bits.

double('A') gives you the ASCII value for the character 'A', that should always be the same unless you get into double byte characters or something strange like that.

just remember, that DOESN'T give you the decimal value of the hex digit Ah, to get that you need to do:
hex2dec('A')

ans =

    10
which should never change.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us