Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

squeamish ossifrage - SHA failing

by vnomad (Novice)
on Nov 26, 2006 at 17:13 UTC ( #586128=perlquestion: print w/ replies, xml ) Need Help??
vnomad has asked for the wisdom of the Perl Monks concerning the following question:

Oh dear.

I'm using a SHA based on John Allen's algorithm in Perlshop where

SHA("squeamish ossifrage\n");
Should return 82055066 4cf29679 2b38d164 7a4d8c0e 1966af57

It does so when I run it here at home, but on my server (Prohosting) it produces a different hash, though with an equal number of ciphers, and format.

I suspect this might be a know issue for those more seasoned in Perl than myself - but I sure can't figure this one out.

It would be nice to get some help here!

-Dagfinn

Comment on squeamish ossifrage - SHA failing
Re: squeamish ossifrage - SHA failing
by grep (Monsignor) on Nov 26, 2006 at 17:50 UTC

    I am not (even close) to an expert on SHA hash functions, but after looking at the Perlshop code, I wouldn't trust that code for production use. It also appears not to have been updated since '98 (use CGI or die;).

    I would use Digest::SHA1

    use strict; use warnings; use Digest::SHA1 qw(sha1_hex); my $data = "squeamish ossifrage\n"; print sha1_hex($data);
    prints 820550664cf296792b38d1647a4d8c0e1966af57

    If you are actually using Perlshop and can't switch quickly, refactor the SHA sub to use Digest::SHA1 then look at switching to Interchange which is actively developed.

    For anyone who's interested here is the SHA sub in question (formatting intact):

    grep
    XP matters not. Look at me. Judge me by my XP, do you?

Re: squeamish ossifrage - SHA failing
by zentara (Archbishop) on Nov 26, 2006 at 19:17 UTC
    Do you think it's possible that the line ending \n is being interpolated differently on the server. Maybe try single quoting the string, and see what happens? I get different results with
    &SHA("squeamish ossifrage\n"); # vs. &SHA('squeamish ossifrage\n');

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      That's only because the character strings themselvers are different. The string "squeamish ossifrage\n" ends with a newline character, while 'squeamish ossifrage\n' ends with a backslash followed by a letter n. The \n sequence isn't special within single quotes.
        Well that was the point I was trying to make. How is "\n" interpolated if he was on a windows server? Does it interpolate to '\r\\n' ?

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: squeamish ossifrage - SHA failing
by dwhite20899 (Pilgrim) on Nov 27, 2006 at 00:32 UTC
    Personally, I suggest Digest::SHA rather than SHA1. SHA-1 will be superceded by 2010 at the latest, so you may want to be ready to implement SHA-256 or better with Digest::SHA. You may also want to look at the test data available at http://www.nsrl.nist.gov/testdata/
      Thanks to all! It's working good now.

      I found an evolved version of my SHA subroutine at: http://mail-archives.apache.org/mod_mbox/spamassassin-commits/200407.mbox/%3C20040701190945.25657.qmail@minotaur.apache.org%3E This one will also use Digest::SHA1 optionally if I read correctly, with 40X higher speed (!?).

      I played around with Perlshop 3.2 in the late nineties, customizing it for selling aerial photos searchable on maps, or in tables. This museum piece sleeps at: http://afoto.com/hildebilde/index.htm

      Had a lot of fun making it bilingual.

      Development of Perlshop continues at a good clip in version 4, with some nice features added while remaining effable for a neophyte like myself. This is the one that gave me the SHA error initially, but seems stable with the alternative routine.

      It would be interesting to compare the speed with, and without Digest::SHA1 under load.

      Thanks again for pointing me in the right direction!

      Dagfinn
        Could someone explain to me exactly what to change in perlshop.cgi to get the above to work please. Thank you

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://586128]
Approved by Joost
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-07-26 08:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls