diff options
author | Mattias Andrée <maandree@operamail.com> | 2013-05-03 21:47:49 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2013-05-03 21:47:49 +0200 |
commit | 3b5d9f3799709cea2834d7d5976c20d242024f91 (patch) | |
tree | f31f7c75d0bcafe3074c15f1ff5a7735956b81fe /pure-java/sha3sum.java | |
parent | m (diff) | |
download | sha3sum-3b5d9f3799709cea2834d7d5976c20d242024f91.tar.gz sha3sum-3b5d9f3799709cea2834d7d5976c20d242024f91.tar.bz2 sha3sum-3b5d9f3799709cea2834d7d5976c20d242024f91.tar.xz |
debug stuff + hex input for java
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | pure-java/sha3sum.java | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/pure-java/sha3sum.java b/pure-java/sha3sum.java index 75f48b0..d8b5d85 100644 --- a/pure-java/sha3sum.java +++ b/pure-java/sha3sum.java @@ -67,7 +67,7 @@ public class sha3sum else if (cmd == "sha3-256sum") o = _o = 256; else if (cmd == "sha3-384sum") o = _o = 384; else if (cmd == "sha3-512sum") o = _o = 512; - boolean binary = false; + boolean binary = false, hex = false; int multi = 0; String[] files = new String[argv.length + 1]; @@ -111,6 +111,9 @@ public class sha3sum System.out.println(" -i ITERATIONS"); System.out.println(" --iterations The number of hash iterations to run. (default: " + _i + ")"); System.out.println(" "); + System.out.println(" -h"); + System.out.println(" --hex Read the input in hexadecimal, rather than binary."); + System.out.println(" "); System.out.println(" -b"); System.out.println(" --binary Print the checksum in binary, rather than hexadecimal."); System.out.println(" "); @@ -182,6 +185,8 @@ public class sha3sum binary = true; else if (arg == "--multi") multi++; + else if (arg == "--hex") + hex = true; else linger = new String[] { arg, null }; else if (arg.startsWith("-")) @@ -197,6 +202,11 @@ public class sha3sum multi++; arg = arg.substring(1); } + else if (arg.charAt(0) == 'h') + { + hex = true; + arg = arg.substring(1); + } else if (arg.length() == 1) linger = new String[] { "-" + arg, null }; else @@ -328,7 +338,18 @@ public class sha3sum int read = file.read(chunk, 0, blksize); if (read <= 0) break; - SHA3.update(chunk, read); + if (hex == false) + SHA3.update(chunk, read); + else + { + int n = read << 1; + for (int _ = 0; _ < n; _++) + { + byte a = chunk[_ << 1], b = chunk[(_ << 1) | 1]; + chunk[_] = (byte)((((a & 15) + (a <= '9' ? 0 : 9)) << 4) | ((b & 15) + (b <= '9' ? 0 : 9))); + } + SHA3.update(chunk, n); + } } byte[] bs = SHA3.digest(); if (multi == 0) |