Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / testsuite / libjava.lang / md5test.java
blobffd0a93cf7508f877629478b05e78aa73bf91487
1 import java.security.*;
3 class md5test {
6 // gnu-crypto/source/gnu/testlet/gnu/crypto/hash/TestOfMD5.java
8 public static void main(String[] argv) {
9 String[] strings = {
10 "a",
11 "abc",
12 "message digest",
13 "abcdefghijklmnopqrstuvwxyz",
14 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
15 "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
18 String[] expected = {
19 "0CC175B9C0F1B6A831C399E269772661",
20 "900150983CD24FB0D6963F7D28E17F72",
21 "F96B697D7CB7938D525A2F31AAF161D0",
22 "C3FCD3D76192E4007DFB496CCA67E13B",
23 "D174AB98D277D9F5A5611C2C9F419D9F",
24 "57EDF4A22BE3C955AC49DA2E2107B67A"
27 for (int i = 0; i < strings.length; i++)
28 testString(strings[i], expected[i]);
32 public static void testString(String string, String expected) {
34 MessageDigest md=null;
35 try {
36 md = MessageDigest.getInstance("MD5");
37 md.update(string.getBytes(), 0, string.length());
38 String result = toString(md.digest());
39 System.out.println(expected);
40 System.out.println(result);
41 if (!expected.equals(result))
42 System.out.println("NOT EQUAL!");
43 } catch (Exception x) {
44 x.printStackTrace();
48 public static String toString(byte[] ba) {
49 return toString(ba, 0, ba.length);
51 public static final String toString(byte[] ba, int offset, int length) {
52 char[] buf = new char[length * 2];
53 for (int i = 0, j = 0, k; i < length; ) {
54 k = ba[offset + i++];
55 buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];
56 buf[j++] = HEX_DIGITS[ k & 0x0F];
58 return new String(buf);
61 private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray();