Created
November 11, 2009 22:11
-
-
Save masak/232360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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