return; } /* b2iu是我写的一个把byte按照不考虑正负号的原则的"升位"程序,因为java没有unsigned运算 */ public static long b2iu(byte b) { return b < 0 ? b & 0x7F + 128 : b; } /*byteHEX(),用来把一个byte类型的数转换成十六进制的ASCII表示, 因为java中的byte的toString无法实现这一点,我们又没有C语言中的 sprintf(outbuf,"%02X",ib) */ public static String byteHEX(byte ib) { char[] Digit = { '0','1','2','3','4','5','6','7','8','9', 'A','B','C','D','E','F' }; char [] ob = new char[2]; ob[0] = Digit[(ib >>> 4) & 0X0F]; ob[1] = Digit[ib & 0X0F]; String s = new String(ob); return s; } public static void main(String args[]) { MD5 m = new MD5(); if (Array.getLength(args) == 0) { //如果没有参数,执行标准的Test Suite System.out.println("MD5 Test suite:"); System.out.println("MD5(\"\"):"+m.getMD5ofStr("")); System.out.println("MD5(\"a\"):"+m.getMD5ofStr("a")); System.out.println("MD5(\"abc\"):"+m.getMD5ofStr("abc")); System.out.println("MD5(\"message digest\"):"+m.getMD5ofStr("message digest")); System.out.println("MD5(\"abcdefghijklmnopqrstuvwxyz\"):"+ m.getMD5ofStr("abcdefghijklmnopqrstuvwxyz")); System.out.println("MD5(\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"):"+ m.getMD5ofStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")); } else System.out.println("MD5(" + args[0] + ")=" + m.getMD5ofStr(args[0])); } |