note
grep
<p>I am not (even close) to an expert on [wp://SHA hash functions], but after looking at the [http://www.perlshop.org/index.htm|Perlshop] [http://www.perlshop.org/files/perlshop_tar.tar|code], I wouldn't trust that code for production use. It also appears not to have been updated since '98 ([id://51012]).</p>
<p>I would use [cpan://Digest::SHA1]</p>
<c>
use strict;
use warnings;
use Digest::SHA1 qw(sha1_hex);
my $data = "squeamish ossifrage\n";
print sha1_hex($data);
</c>
prints 820550664cf296792b38d1647a4d8c0e1966af57
<p>
If you are actually using [http://www.perlshop.org/index.htm|Perlshop] and can't switch quickly, refactor the <c>SHA</c> sub to use [cpan://Digest::SHA1] then look at switching to [http://www.icdevgroup/|Interchange] which is actively developed.
<p>For anyone who's interested here is the <c>SHA</c> sub in question (formatting intact):</p>
<readmore>
<c>
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 1966af57
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;
}
</c>
</readmore>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-133383">
<p>
[id://133383|grep]
<table align="left" cellpadding="6">
<!-- <tr><td bgcolor="#000000"><font color="#33CC33"><tt>Mynd you, mønk bites Kan be pretti nasti...</tt></font></td></tr> -->
<!-- <tr><td bgcolor="#000000"><font color="#33CC33"><tt>One dead unjugged rabbit fish later...</tt></font></td></tr> -->
<!-- <tr><td bgcolor="#000000"><font color="#33CC33"><tt>Just me, the boy, two monks, and no questions asked</tt></font></td></tr> -->
<tr><td bgcolor="#000000"><font color="#33CC33"><tt>XP matters not. Look at me. Judge me by my XP, do you?</tt></font></td></tr>
</table>
</div></div>
586128
586128