一这hash算法

public static long hash(byte[] digest, int nTime)         {             long rv = ((long)(digest[3 + nTime * 4] & 0xFF) << 24)                     | ((long)(digest[2 + nTime * 4] & 0xFF) << 16)                     | ((long)(digest[1 + nTime * 4] & 0xFF) << 8)                     | ((long)digest[0 + nTime * 4] & 0xFF);

return rv & 0xffffffffL; /* Truncate to 32-bits */         }

/**          * Get the md5 of the given key.          */         public static byte[] computeMd5(string k)         {             MD5 md5 = new MD5CryptoServiceProvider();

byte[] keyBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(k));             md5.Clear();             //md5.update(keyBytes);             //return md5.digest();             return keyBytes;         }

public static long hash(string str)         {             byte[] bytes = computeMd5(str);             return hash(bytes, 0);         }

static void Main(string[] args)         {             Console.WriteLine(hash("460001202747635"));                       Console.Read();         }

上一篇:Java可重入锁如何避免死锁


下一篇:C++的三大特性:封装、继承和多态性的详解