OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [testsuite/] [libjava.lang/] [md5test.java] - Blame information for rev 769

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 765 jeremybenn
import java.security.*;
2
 
3
class md5test {
4
 
5
 
6
    // gnu-crypto/source/gnu/testlet/gnu/crypto/hash/TestOfMD5.java
7
 
8
    public static void main(String[] argv) {
9
        String[] strings = {
10
            "a",
11
            "abc",
12
            "message digest",
13
            "abcdefghijklmnopqrstuvwxyz",
14
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
15
            "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
16
        };
17
 
18
        String[] expected = {
19
            "0CC175B9C0F1B6A831C399E269772661",
20
            "900150983CD24FB0D6963F7D28E17F72",
21
            "F96B697D7CB7938D525A2F31AAF161D0",
22
            "C3FCD3D76192E4007DFB496CCA67E13B",
23
            "D174AB98D277D9F5A5611C2C9F419D9F",
24
            "57EDF4A22BE3C955AC49DA2E2107B67A"
25
        };
26
 
27
        for (int i = 0; i < strings.length; i++)
28
            testString(strings[i], expected[i]);
29
 
30
    }
31
 
32
    public static void testString(String string, String expected) {
33
 
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();
45
        }
46
    }
47
 
48
    public static String toString(byte[] ba) {
49
        return toString(ba, 0, ba.length);
50
    }
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];
57
        }
58
        return new String(buf);
59
    }
60
 
61
    private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray();
62
 
63
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.