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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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):

sub SHA { ### This algorithm is based on the implementation +of SHA ### written by: John Allen (allen@grumman.com). ### &SHA("squeamish ossifrage\n"); ### Should return 82055066 4cf29679 2b38d164 7a4d8c0e 1966 +af57 my ($msg, $p, $l) = @_; #$p=0; $l=0 local $_; $temp = 'D9T4C`>_-JXF8NMS^$#)4=L/2X?!:@GF9;MGKH8\;O-S*8L\'6'; $m = 4294967296; ###$m=1+~0; @A=unpack"N*",unpack u,$temp; @K=splice@A,5,4; sub M{($x=pop)-($m)*int$x/$m}; sub L{$n=pop;($x=pop)<<$n|2**$n-1&$x>>32-$n} @F=(sub{$b&($c^$d)^$d},$S=sub{$b^$c^$d},sub{($b|$c)&$d|$b&$c},$S); do{ $msg=~s/.{0,64}//s;$_=$&; $l+=$r=length; $r++,$_.="\x80"if$r<64&&!$p++;@W=unpack N16,$_."\0"x7;$W[15]=$l*8 if$r<57; for(16..79){push@W,L$W[$_ -3]^$W[$_-8]^$W[$_-14]^$W[$_-16],1}($a,$b,$c,$d,$e)=@A; for(0..79){$t=M&{$F[$_/ 20]}+$e+$W[$_]+$K[$_/20]+L$a,5; $e=$d; $d=$c; $c=L$b,30; $b=$a; $a=$t}$v='a'; @A=map{ M$_+${$v++}}@A }while$r>56; return sprintf'%8x 'x4 . '%8x',@A; }

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


In reply to Re: squeamish ossifrage - SHA failing by grep
in thread squeamish ossifrage - SHA failing by vnomad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (8)
    As of 2014-07-10 06:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (202 votes), past polls