Skip to content

Instantly share code, notes, and snippets.

@masak
Created November 11, 2009 22:11
Show Gist options
  • Save masak/232360 to your computer and use it in GitHub Desktop.
Save masak/232360 to your computer and use it in GitHub Desktop.
$ cat bug
sub digest(Str $text) is export {
my $binary = Q:PIR {
.local string text
.local pmc digest
# Input
$P0 = find_lex '$text'
text = $P0
# Choose the right digest.
$P1 = loadlib 'digest_group'
digest = new 'SHA256'
# Calculate the digest.
digest.'Init'()
digest.'Update'(text)
$S0 = digest.'Final'()
%r = box $S0
};
# Convert to hex.
return [~] map { sprintf '%02x', .ord }, $binary.comb;
}
say digest('user_name=carl'.split("=")[1]);
say digest('carl');
$ perl6 bug
04f8996da763b7a969b1028ee3007569eaf3a635486ddab211d512c85b9df8fb
69bfe1e6e44821df7f8a0927bd7e61ef208fdb25deaa4353450bc3fb904abd52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment