Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@skids
Created January 7, 2015 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skids/47f2ed6b2f64630fc571 to your computer and use it in GitHub Desktop.
Save skids/47f2ed6b2f64630fc571 to your computer and use it in GitHub Desktop.
encoding for Digest::MD5
While building some dwimmy prefab classes for Sum, I was faced with
choosing which encoding is "dwimmy" for string arguments. I found
that perl5's Digest::MD5 disagrees with perl6's compat module.
# perl6-m -MSum::MD -e 'class myMD5 does Sum::MD5 does Sum::Marshal::Raw { }; myMD5.new.finalize("OHAIá".encode("ascii")).base(16).say;'
103E95F18E83AF205B1F6645A5A2E672
# perl6-m -MSum::MD -e 'class myMD5 does Sum::MD5 does Sum::Marshal::Raw { }; myMD5.new.finalize("OHAIá".encode("utf8")).base(16).say;'
ADB19C50200CA4D2E03DF482F3CCAB0
# perl6-m -MDigest::MD5 -e 'say Digest::MD5.md5_hex("OHAIá")'
103e95f18e83af205b1f6645a5a2e672
# perl -MDigest::MD5 -e 'print Digest::MD5::md5_hex("OHAIá"); print "\n";'
0adb19c50200ca4d2e03df482f3ccab0
...both agree on utf8 for output.
# perl6-m -e 'print "OHAIá"' | hexdump -C
00000000 4f 48 41 49 c3 a1 |OHAI..|
00000006
# perl -e 'print "OHAIá"' | hexdump -C
00000000 4f 48 41 49 c3 a1 |OHAI..|
00000006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment