Created
May 9, 2012 02:23
-
-
Save shkumagai/2641298 to your computer and use it in GitHub Desktop.
How to use add_bits() function in Digest::SHA
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
use strict; | |
use warnings; | |
use Digest::SHA; | |
# Using sha256 algorism | |
our $ctx = Digest::SHA->new(256); | |
sub bit_to_digest { | |
my ($bits) = @_; | |
printf "Origin: %s\n", $bits; | |
printf "Digest: %s\n", $ctx->add_bits($bits)->hexdigest; | |
printf "Digest: %s\n", $ctx->add_bits(pack('B*', $bits), length($bits))->hexdigest; | |
} | |
sub main { | |
bit_to_digest($ARGV[0]); | |
} | |
# Usage: | |
# $ perl digest_sample.pl 111100001010 | |
# | |
main() if (__FILE__ eq $0); | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment