MD4: Difference between revisions

942 bytes added ,  7 years ago
m (→‎{{header|Perl 6}}: 'push' requires 'slip')
Line 537:
 
echo MD4("Rosetta Code")</lang>
 
=={{header|PARI/GP}}==
 
Build a MD4 plugin using Linux system library and PARI's function interface. (Linux solution)
 
<lang C>#include <pari/pari.h>
#include <openssl/md4.h>
 
#define HEX(x) (((x) < 10)? (x)+'0': (x)-10+'a')
 
/*
* PARI/GP func: MD4 hash
*
* gp code: install("plug_md4", "s", "MD4", "<library path>");
*/
GEN plug_md4(char *text)
{
char md[MD4_DIGEST_LENGTH];
char hash[sizeof(md) * 2 + 1];
int i;
 
MD4((unsigned char*)text, strlen(text), (unsigned char*)md);
 
for (i = 0; i < sizeof(md); i++) {
hash[i+i] = HEX((md[i] >> 4) & 0x0f);
hash[i+i+1] = HEX(md[i] & 0x0f);
}
 
hash[sizeof(md) * 2] = 0;
 
return strtoGENstr(hash);
}</lang>
 
Compile with: gcc -Wall -O2 -fPIC -shared md4.c -o libmd4.so -lcrypt -lpari
 
Load plugin from your home directory into PARI:
<lang parigp>install("plug_md4", "s", "MD4", "~/libmd4.so");
 
MD4("Rosetta Code") </lang>
 
Output: "a52bcfc6a0d0d300cdc5ddbfbefe478b"
 
 
=={{header|Perl}}==
Line 547 ⟶ 589:
{{out}}
<pre>Rosetta Code => a52bcfc6a0d0d300cdc5ddbfbefe478b</pre>
 
=={{header|Perl 6}}==
<lang perl6>sub md4($str) {
Anonymous user