MD5: Difference between revisions

1,802 bytes added ,  5 years ago
Add Jsish
(Add Jsish)
Line 1,081:
Other options for digest algorithms (to replace "MD5" in the example above) include: MD2, SHA-1, SHA-256, SHA-384, and SHA-512.
Other encoding options (to replace "UTF_8" in the example above) are available from the Charset and StandardCharsets classes.
 
=={{header|Jsish}}==
<lang javascript>/* MD5 hash in Jsish */
var str = 'Rosetta code';
puts(Util.hash(str, {type:'md5'}));
 
/* MD5 RFC1321 test suite */
function MD5(str) { return Util.hash(str, {type:'md5'}); }
 
;MD5('');
;MD5('a');
;MD5('abc');
;MD5('message digest');
;MD5('abcdefghijklmnopqrstuvwxyz');
;MD5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789');
;MD5('12345678901234567890123456789012345678901234567890123456789012345678901234567890');
 
/*
=!EXPECTSTART!=
bf0ac9c7e94e9d50c18f4ff592643546
MD5('') ==> d41d8cd98f00b204e9800998ecf8427e
MD5('a') ==> 0cc175b9c0f1b6a831c399e269772661
MD5('abc') ==> 900150983cd24fb0d6963f7d28e17f72
MD5('message digest') ==> f96b697d7cb7938d525a2f31aaf161d0
MD5('abcdefghijklmnopqrstuvwxyz') ==> c3fcd3d76192e4007dfb496cca67e13b
MD5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') ==> d174ab98d277d9f5a5611c2c9f419d9f
MD5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') ==> 57edf4a22be3c955ac49da2e2107b67a
=!EXPECTEND!=
*/</lang>
 
{{out}}
<pre>prompt$ jsish md5.jsi
bf0ac9c7e94e9d50c18f4ff592643546
 
prompt$ jsish --U md5.jsi # display unit test echos
bf0ac9c7e94e9d50c18f4ff592643546
MD5('') ==> d41d8cd98f00b204e9800998ecf8427e
MD5('a') ==> 0cc175b9c0f1b6a831c399e269772661
MD5('abc') ==> 900150983cd24fb0d6963f7d28e17f72
MD5('message digest') ==> f96b697d7cb7938d525a2f31aaf161d0
MD5('abcdefghijklmnopqrstuvwxyz') ==> c3fcd3d76192e4007dfb496cca67e13b
MD5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') ==> d174ab98d277d9f5a5611c2c9f419d9f
MD5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') ==> 57edf4a22be3c955ac49da2e2107b67a
 
prompt$ jsish -u md5.jsi # run the unit tests
[PASS] md5.jsi</pre>
 
=={{header|Julia}}==
Anonymous user