Home > Developer > JavaScript
* * A JavaScript implementation of the RSA Data Security, Inc. MD4 message * Digest algorithm, as defined in RFC 1320.
* Version 2.1 Copyright (C) Jerrad Pierce, Paul Johnston 1999-2002. * Other Contributors:greg Holt, Andrew Kepert, Ydnar, lostinet * Distributed under the BSD License * http://pajhome
. org.uk/crypt/md5 for more info. */
* * * Configurable variables. You could need to tweak this compatible with * server-side, but the defaults work in most. */ VarHexcase= 0; /* Hex output format. 0-lowercase; 1-uppercase * VarB64pad= ""; /* base-64 pad character. "=" for strict RFC compliance * * VarChrsz= 8; /* bits per input character. 8-ascii; 16-unicode * * * These are the functions "ll usually want to call * * functionHex_md4(S){ ReturnBinl2hex(Core_md4(Str2binl(S), S.Length* Chrsz));} functionB64_md4(S){ ReturnBinl2b64(Core_md4(Str2binl(S), S.Length* Chrsz));} functionStr_md4(S){ ReturnBinl2str(Core_md4(Str2binl(S), S.Length* Chrsz));} functionHex_hmac_md4(Key, data) { ReturnBinl2hex(Core_hmac_md4(Key, data)); } functionB64_hmac_md4(Key, data) { ReturnBinl2b64(Core_hmac_md4(Key, data)); } functionStr_hmac_md4(Key, data) { ReturnBinl2str(Core_hmac_md4(Key, data)); } * * Perform a simple self-test to, if the VM is working * * functionMd4_vm_test() { ReturnHex_md4("ABC") == "a448017aaf21d8525fc10ae87aa6729d"; } * * Calculate The MD4 of an array of Little-endian words, and a bit length * * functionCore_md4(X, Len) { /* Append padding * *X[len>> 5]|= 0x80 << (Len%32);x[(((Len +64) >>> 9) << 4)+14]=Len; VarA= 1732584193; VarB=-271733879; VarC=-1732584194; VarD= 271733878; For(VarI= 0;I<X.Length;i += 16) { VarOlda=A; VarOldb=B; VarOldc=C; VarOldd=D;A=Md4_ff(A, B, C, D, x[i+0],3 );D=Md4_ff(D, A, B, C, x[i+1],7 );C=Md4_ff(C, D, a, B, x[i+2],11);B=Md4_ff(b, C, D, a, x[i+3],19);A=Md4_ff(A, B, C, D, x[i+4],3 );D=Md4_ff(D, A, B, C, x[i+5],7 );C=Md4_ff(C, D, a, B, x[i+6],11);B=Md4_ff(b, C, D, a, x[i+7],19);A=Md4_ff(A, B, C, D, x[i+8],3 );D=Md4_ff(D, A, B, C, x[i+9],7 );C=Md4_ff(C, D, a, B, x[i+10],11)