I'd go with moritz's solution and simply use Digest::SHA1::sha1_base64(), but just in case you want to know why your attempt didn't work, here's why:

$sha->add(@ascii);

should've been

$sha->add(encode_utf8($x));

You just need to add the (UTF-8) string itself, not a list of stringified byte values such as "112", "97", "115"...  (i.e. you did compute the digest of the string "11297115115119111114100").

Also, in your Java code, you're printing out the digest as signed bytes. To get the same behaviour in Perl, you'd need to

@z = unpack("c*",$sha->digest);

which would then print out as expected (when adding spaces for better readability (print "@z\n") ):

91 -86 97 -28 -55 -71 63 63 6 -126 37 11 108 -8 51 27 126 -26 -113 -40

In reply to Re^3: Convert Java to Perl -> Script attached by almut
in thread Convert Java to Perl -> Script attached by smoky

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.