2

Can anyone identify this hash function? It is written in Javascript. I would like to duplicate it in another language (PHP). I would find it hard to believe that a function as tedious as this was written by a human. The function is called "cValue"... maybe that will help. Thanks in advance!

function (s) {
 function L(b, a) {
 return (b << a) | (b >>> (32 - a))
 }
 function K(k, b) {
 var F, a, d, x, c;
 d = (k & 2147483648);
 x = (b & 2147483648);
 F = (k & 1073741824);
 a = (b & 1073741824);
 c = (k & 1073741823) + (b & 1073741823);
 if (F & a) {
 return (c ^ 2147483648 ^ d ^ x)
 }
 if (F | a) {
 if (c & 1073741824) {
 return (c ^ 3221225472 ^ d ^ x)
 } else {
 return (c ^ 1073741824 ^ d ^ x)
 }
 } else {
 return (c ^ d ^ x)
 }
 }
 function r(a, c, b) {
 return (a & c) | ((~a) & b)
 }
 function q(a, c, b) {
 return (a & b) | (c & (~b))
 }
 function p(a, c, b) {
 return (a ^ c ^ b)
 }
 function n(a, c, b) {
 return (c ^ (a | (~b)))
 }
 function u(G, F, aa, Z, k, H, I) {
 G = K(G, K(K(r(F, aa, Z), k), I));
 return K(L(G, H), F)
 }
 function f(G, F, aa, Z, k, H, I) {
 G = K(G, K(K(q(F, aa, Z), k), I));
 return K(L(G, H), F)
 }
 function D(G, F, aa, Z, k, H, I) {
 G = K(G, K(K(p(F, aa, Z), k), I));
 return K(L(G, H), F)
 }
 function t(G, F, aa, Z, k, H, I) {
 G = K(G, K(K(n(F, aa, Z), k), I));
 return K(L(G, H), F)
 }
 function e(k) {
 var G;
 var d = k.length;
 var c = d + 8;
 var b = (c - (c % 64)) / 64;
 var F = (b + 1) * 16;
 var H = Array(F - 1);
 var a = 0;
 var x = 0;
 while (x < d) {
 G = (x - (x % 4)) / 4;
 a = (x % 4) * 8;
 H[G] = (H[G] | (k.charCodeAt(x) << a));
 x++
 }
 G = (x - (x % 4)) / 4;
 a = (x % 4) * 8;
 H[G] = H[G] | (128 << a);
 H[F - 2] = d << 3;
 H[F - 1] = d >>> 29;
 return H
 }
 function B(c) {
 var b = "",
 d = "",
 k, a;
 for (a = 0; a <= 3; a++) {
 k = (c >>> (a * 8)) & 255;
 d = "0" + k.toString(16);
 b = b + d.substr(d.length - 2, 2)
 }
 return b
 }
 function J(b) {
 b = b.replace(/\r\n/g, "\n");
 var a = "";
 for (var k = 0; k < b.length; k++) {
 var d = b.charCodeAt(k);
 if (d < 128) {
 a += String.fromCharCode(d)
 } else {
 if ((d > 127) && (d < 2048)) {
 a += String.fromCharCode((d >> 6) | 192);
 a += String.fromCharCode((d & 63) | 128)
 } else {
 a += String.fromCharCode((d >> 12) | 224);
 a += String.fromCharCode(((d >> 6) & 63) | 128);
 a += String.fromCharCode((d & 63) | 128)
 }
 }
 }
 return a
 }
 var C = Array();
 var P, h, E, v, g, Y, X, W, V;
 var S = 7,
 Q = 12,
 N = 17,
 M = 22;
 var A = 5,
 z = 9,
 y = 14,
 w = 20;
 var o = 4,
 m = 11,
 l = 16,
 j = 23;
 var U = 6,
 T = 10,
 R = 15,
 O = 21;
 s = J(s);
 C = e(s);
 Y = 1732584193;
 X = 4023233417;
 W = 2562383102;
 V = 271733878;
 for (P = 0; P < C.length; P += 16) {
 h = Y;
 E = X;
 v = W;
 g = V;
 Y = u(Y, X, W, V, C[P + 0], S, 3614090360);
 V = u(V, Y, X, W, C[P + 1], Q, 3905402710);
 W = u(W, V, Y, X, C[P + 2], N, 606105819);
 X = u(X, W, V, Y, C[P + 3], M, 3250441966);
 Y = u(Y, X, W, V, C[P + 4], S, 4118548399);
 V = u(V, Y, X, W, C[P + 5], Q, 1200080426);
 W = u(W, V, Y, X, C[P + 6], N, 2821735955);
 X = u(X, W, V, Y, C[P + 7], M, 4249261313);
 Y = u(Y, X, W, V, C[P + 8], S, 1770035416);
 V = u(V, Y, X, W, C[P + 9], Q, 2336552879);
 W = u(W, V, Y, X, C[P + 10], N, 4294925233);
 X = u(X, W, V, Y, C[P + 11], M, 2304563134);
 Y = u(Y, X, W, V, C[P + 12], S, 1804603682);
 V = u(V, Y, X, W, C[P + 13], Q, 4254626195);
 W = u(W, V, Y, X, C[P + 14], N, 2792965006);
 X = u(X, W, V, Y, C[P + 15], M, 1236535329);
 Y = f(Y, X, W, V, C[P + 1], A, 4129170786);
 V = f(V, Y, X, W, C[P + 6], z, 3225465664);
 W = f(W, V, Y, X, C[P + 11], y, 643717713);
 X = f(X, W, V, Y, C[P + 0], w, 3921069994);
 Y = f(Y, X, W, V, C[P + 5], A, 3593408605);
 V = f(V, Y, X, W, C[P + 10], z, 38016083);
 W = f(W, V, Y, X, C[P + 15], y, 3634488961);
 X = f(X, W, V, Y, C[P + 4], w, 3889429448);
 Y = f(Y, X, W, V, C[P + 9], A, 568446438);
 V = f(V, Y, X, W, C[P + 14], z, 3275163606);
 W = f(W, V, Y, X, C[P + 3], y, 4107603335);
 X = f(X, W, V, Y, C[P + 8], w, 1163531501);
 Y = f(Y, X, W, V, C[P + 13], A, 2850285829);
 V = f(V, Y, X, W, C[P + 2], z, 4243563512);
 W = f(W, V, Y, X, C[P + 7], y, 1735328473);
 X = f(X, W, V, Y, C[P + 12], w, 2368359562);
 Y = D(Y, X, W, V, C[P + 5], o, 4294588738);
 V = D(V, Y, X, W, C[P + 8], m, 2272392833);
 W = D(W, V, Y, X, C[P + 11], l, 1839030562);
 X = D(X, W, V, Y, C[P + 14], j, 4259657740);
 Y = D(Y, X, W, V, C[P + 1], o, 2763975236);
 V = D(V, Y, X, W, C[P + 4], m, 1272893353);
 W = D(W, V, Y, X, C[P + 7], l, 4139469664);
 X = D(X, W, V, Y, C[P + 10], j, 3200236656);
 Y = D(Y, X, W, V, C[P + 13], o, 681279174);
 V = D(V, Y, X, W, C[P + 0], m, 3936430074);
 W = D(W, V, Y, X, C[P + 3], l, 3572445317);
 X = D(X, W, V, Y, C[P + 6], j, 76029189);
 Y = D(Y, X, W, V, C[P + 9], o, 3654602809);
 V = D(V, Y, X, W, C[P + 12], m, 3873151461);
 W = D(W, V, Y, X, C[P + 15], l, 530742520);
 X = D(X, W, V, Y, C[P + 2], j, 3299628645);
 Y = t(Y, X, W, V, C[P + 0], U, 4096336452);
 V = t(V, Y, X, W, C[P + 7], T, 1126891415);
 W = t(W, V, Y, X, C[P + 14], R, 2878612391);
 X = t(X, W, V, Y, C[P + 5], O, 4237533241);
 Y = t(Y, X, W, V, C[P + 12], U, 1700485571);
 V = t(V, Y, X, W, C[P + 3], T, 2399980690);
 W = t(W, V, Y, X, C[P + 10], R, 4293915773);
 X = t(X, W, V, Y, C[P + 1], O, 2240044497);
 Y = t(Y, X, W, V, C[P + 8], U, 1873313359);
 V = t(V, Y, X, W, C[P + 15], T, 4264355552);
 W = t(W, V, Y, X, C[P + 6], R, 2734768916);
 X = t(X, W, V, Y, C[P + 13], O, 1309151649);
 Y = t(Y, X, W, V, C[P + 4], U, 4149444226);
 V = t(V, Y, X, W, C[P + 11], T, 3174756917);
 W = t(W, V, Y, X, C[P + 2], R, 718787259);
 X = t(X, W, V, Y, C[P + 9], O, 3951481745);
 Y = K(Y, h);
 X = K(X, E);
 W = K(W, v);
 V = K(V, g)
 }
 var i = B(Y) + B(X) + B(W) + B(V);
 return i.toLowerCase()
};
asked Mar 9, 2011 at 22:21
4
  • why do you want to duplicate it? Commented Mar 9, 2011 at 22:23
  • I need to perform the same hash server side. Commented Mar 9, 2011 at 22:24
  • This code looks like it was intentionally obfuscated to prevent exactly what you want to do. Your best bet is to either track down the original source code or actually rewrite it line by line in your language of choice. Commented Mar 9, 2011 at 22:26
  • All this code that I am digging through seems to have been run through some compression tool. Devastating. Commented Mar 9, 2011 at 22:31

4 Answers 4

8

Defining this function as a() :

var a = /* what you posted */

And calling the following :

a('test');
a('plop');
a('this is another test just to be sure');

I get the three following results :

098f6bcd4621d373cade4e832627b4f6
64a4e8faed1a1aa0bf8bf0fc84938d25
17733df129ee53bd321a323b0ae55401

A 32 characters long string immediatly looks like a [**md5 hash**][1] ; but let's verify a bit more.
Calling this in PHP :
var_dump(md5('test'));
var_dump(md5('plop'));
var_dump(md5('this is another test just to be sure'));

I get the following output :

string '098f6bcd4621d373cade4e832627b4f6' (length=32)
string '64a4e8faed1a1aa0bf8bf0fc84938d25' (length=32)
string '17733df129ee53bd321a323b0ae55401' (length=32)

Which are the three exact same results.


Of course, only three tests are not much, and you should do a couple more to be sure... But, as far as I cant tell, your function seems to be calculating a md5 hash -- and the corresponding PHP function is [**`md5()`**][2] ;-)
answered Mar 9, 2011 at 22:27
Sign up to request clarification or add additional context in comments.

3 Comments

You are so baller. Ill test it more but this is crazy promising. Thanks!
@Nate : You're welcome :-) Have fun! (In the meantime, I've edited my answer with two other tests, as a precaution)
It is MD5. The transformation matrix is what gives it away. Here is the original algorithm: faqs.org/rfcs/rfc1321.html - refer to /* Constants for MD5Transform routine. lines which corresponds to the var S = 7, ... lines.
0

Due to the use of XOR in function K() and the multi-stage process of calling functions which all use K(), my best guess is that this is an implementation of some cryptographic algorithm. Also, since there only seems to be one multi-stage function, it is likely to be some form of hash-generator such as MD5

answered Mar 9, 2011 at 22:29

Comments

0

MD5 call this function with simple string, get hash and go to this site: http://www.onlinehashcrack.com/free-hash-reverse.php

answered Mar 9, 2011 at 22:29

Comments

0

This hash function is MD5. As shown in the for (P = 0; P < C.length; P+=16) loop, it features MD5 compression, repeating the u/f/d/t/k functions.

answered Sep 2, 2023 at 21:36

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.