關於MD5的RFC-1321 spec也包含了對算法的詳細解釋,W關於CRC的iki文章非常清楚。
畢竟,您的主要問題顯然實際上是對二進制系統和位運算符的無知。以下是有關二元體系的幾個優秀導遊員和參與運營商:
這一定讓你開始。
編輯:如果你想homegrow一個MD5函數的實際原因是,你實際上似乎無法找到Java中的現有功能,那麼你會發現這個片斷非常有用:
/**
* Generate MD5 hash for the given String.
* @param string The String to generate the MD5 hash for.
* @return The 32-char hexadecimal MD5 hash of the given String.
*/
public static String hashMD5(String string) {
byte[] hash;
try {
hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
// Unexpected exception. "MD5" is just hardcoded and supported.
throw new RuntimeException("MD5 should be supported?", e);
} catch (UnsupportedEncodingException e) {
// Unexpected exception. "UTF-8" is just hardcoded and supported.
throw new RuntimeException("UTF-8 should be supported?", e);
}
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
if ((b & 0xff) < 0x10) hex.append("0");
hex.append(Integer.toHexString(b & 0xff));
}
return hex.toString();
}
您的公司從事什麼語言? – Skilldrick
我在Java中工作,但我想爲Unrealscript的早期版本做這個,它沒有這些內置函數。 –
@高性能標記:我確實瞭解基本級別的按位運算。看來關於這個主題的文章對讀者以前的知識做了一些假設(因此是「傻瓜」的標題)。我會看看這個週末我是否可以解決CRC問題,因爲這是最簡單的。 –