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

Subversion Repositories openrisc

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

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 shatest {
4
 
5
    // gnu-crypto/source/gnu/testlet/gnu/crypto/hash/TestOfSha160.java
6
 
7
    public static void main(String[] argv) {
8
        MessageDigest md=null;
9
        try {
10
            md = MessageDigest.getInstance("SHA-1");
11
        } catch (Exception e) {
12
            e.printStackTrace();
13
        }
14
        md.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq".getBytes(), 0, 56);
15
        String exp = "84983E441C3BD26EBAAE4AA1F95129E5E54670F1";
16
        String result = toString(md.digest());
17
        System.out.println(exp);
18
        System.out.println(result);
19
        if (!exp.equals(result))
20
            System.out.println("NOT EQUAL!");
21
 
22
    }
23
 
24
    public static String toString(byte[] ba) {
25
        return toString(ba, 0, ba.length);
26
    }
27
    public static final String toString(byte[] ba, int offset, int length) {
28
        char[] buf = new char[length * 2];
29
        for (int i = 0, j = 0, k; i < length; ) {
30
            k = ba[offset + i++];
31
            buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];
32
            buf[j++] = HEX_DIGITS[ k        & 0x0F];
33
        }
34
        return new String(buf);
35
    }
36
 
37
    private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray();
38
 
39
}

powered by: WebSVN 2.1.0

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