timtowtdi has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

Is there a way to present an xxHash64 in Base64 notation? And how? :-)

Like there is with Digest::MD5:
The result of md5_base64($data) is 22 characters, instead of the 'standard notation' of 32 hex characters.

The 'standard notation' of an xxHash64 is 16 characters.
It would be really nice to write this down smaller like the above shown trick Base64 and MD5.

Can you help me?

The great mistake is to anticipate the outcome of the engagement; Let nature take it's course, and your tools will strike at the right moment.

Replies are listed 'Best First'.
Re: xxHash Base64
by BrowserUk (Patriarch) on Jun 09, 2016 at 10:59 UTC

    If you are running a 64-bit build of perl, or one that has 64-bit integer math, then you could do the following:

    use Digest::xxHash64 qw[ xxHash64 ]; use Mime::Base64; my $data = ...; ## from wherever my $xxH64B64 = encode_base64( pack 'Q', xxHash64( $data ) );

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.
      That was it! Thank you very much!
      The great mistake is to anticipate the outcome of the engagement; Let nature take it's course, and your tools will strike at the right moment.

      Or if you're not using a 64-bit perl,

      encode_base64( pack('H*', xxhash64_hex($data, 0)) );

      Note that xxhash is not preimage-resistant, so comparing it to cryptographic hashes like MD5 and SHA1 is highly misleading.

Re: xxHash Base64
by $h4X4_|=73}{ (Monk) on Jun 09, 2016 at 10:58 UTC

    Sorry, a cow is not a duck. Base64 (encoding) vs xxHash64 (Hash algorithm)... Hmmm