I'm trying to take this hex number "A10000009296F2" and do a SHA1 hash and make it come out as "2d0e6efea8f8082c9703cf6636c4a2195c75b7ed". You can see
here that it does generate as "2d0e6efea8f8082c9703cf6636c4a2195c75b7ed".
I see other on-line calculators where this works as well. But I can't reproduce the results with Perl. My SHA-1 keeps coming out as 'cc73e65e0f3282e01a6de37446df45bbdd46ba02' or '4cf522d69e6334472377eed5959dbfaa422005dc'.
What is wrong with my code that I can't make a proper SHA-1 of my hex number? Any ideas? After the Perl code, I put in some Python that calc's it correctly.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Modern::Perl;
use Digest::SHA qw( sha1 sha1_hex sha1_base64 hmac_sha1 hmac_sha1_hex
+ hmac_sha1_base64 );
my $var = 'A10000009296F2';
say "hmac_sha1: " . hmac_sha1($var);
say "hmac_sha1_hex: " . hmac_sha1_hex($var);
say "hmac_sha1_bae_64: " . hmac_sha1_base64($var);
say "sha1: " . sha1($var);
say "sha1_hex: " . sha1_hex($var);
say "sha1_base64: " . sha1_base64($var);
say "orig var: " . $var;
Here is the Python code that calcs the SHA1 properly
import hashlib
mid = 'A10000009296F2'.upper()
s = hashlib.sha1(mid.decode('hex'))
print s.hexdigest()
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.