mardi 16 janvier 2018

Hash the same for multiple values?

I understand that the hash for multiple values shouldn't be the same, but when I hash a random string, one of a few selections is the output: 7 or 34 for digest[0], 46, 120, or -125 for digest[1]. I haven't fully tested the other entries in digest[] yet but I'd assume its the same. The code is below:

private static String random() {
    Random rnd = new Random();
    char[] buf = new char[16];
    for (int i = 0; i < buf.length; i++)
        buf[i] = (char)(33 + rnd.nextInt(127 - 33));
    System.out.println(buf);
    return buf.toString();
}

private static int createInts() {
    SHA3.DigestSHA3 digestSHA3 = new SHA3.Digest256();
    byte[] digest = digestSHA3.digest(random().getBytes());
    int result = digest[1];
    System.out.println(result);
    String s = String.format("%8s", Integer.toBinaryString(digest[1] & 0xFF)).replace(' ', '0');
    System.out.println(s);
    return result;
}

What is going on?




Aucun commentaire:

Enregistrer un commentaire