Fix byte issues. (it is signed not unsigned)

This commit is contained in:
Peter Boraros 2011-11-09 04:56:19 +01:00
parent 31351acda5
commit 820bacc34e
2 changed files with 9 additions and 12 deletions

View file

@ -5,26 +5,23 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CrackerCore { public class CrackerCore {
public static byte[] select(List<long[]> stats) { public static int[] select(List<long[]> stats) {
// each item of the stats must have length exactly Byte.MAX_VALUE // each item of the stats must have length exactly Byte.MAX_VALUE
double[] means = Stats.mean(stats); double[] means = Stats.mean(stats);
if (means.length >= Byte.MAX_VALUE) { ArrayList<Integer> idx = new ArrayList<Integer>();
throw new RuntimeException("Something gone wrong. Expecting exactly "+ Byte.MAX_VALUE+ " items.");
}
ArrayList<Byte> idx = new ArrayList<Byte>();
// TODO: implement your code here ************************** // TODO: implement your code here **************************
for (int i = 0; i< means.length; i++) {
// for each byte test the condition // for each byte test the condition
for (byte i = 0; i< means.length; i++) {
idx.add(i); idx.add(i);
} }
// ********************************************************* // *********************************************************
if (idx.isEmpty() || idx.size() > 6) return null; if (idx.isEmpty() || idx.size() > 6) return null;
byte[] result = new byte[idx.size()]; int[] result = new int[idx.size()];
int i = 0; for (byte b : idx) result[i++] = b; int i = 0; for (int b : idx) result[i++] = b;
return result; return result;
} }

View file

@ -70,7 +70,7 @@ public class HmacCracker implements Runnable {
} }
private boolean dfs(byte[] hmac, int ptr) { private boolean dfs(byte[] hmac, int ptr) {
byte[] guessed = null; int[] guessed = null;
if (ptr <= this.hmac.length) { if (ptr <= this.hmac.length) {
guessed = guessNext(message, hmac, ptr, maxIterations, inputStream, outputStream); guessed = guessNext(message, hmac, ptr, maxIterations, inputStream, outputStream);
if (guessed==null) { if (guessed==null) {
@ -92,7 +92,7 @@ public class HmacCracker implements Runnable {
return false; return false;
} }
private byte[] guessNext(byte[] msg, byte[] hmac, int ptr, int maxIt, InputStream is, OutputStream os) { private int[] guessNext(byte[] msg, byte[] hmac, int ptr, int maxIt, InputStream is, OutputStream os) {
List<long[]> statsPool = new ArrayList<long[]>(); List<long[]> statsPool = new ArrayList<long[]>();
@ -124,7 +124,7 @@ public class HmacCracker implements Runnable {
statsPool.add(Arrays.copyOf(stats, stats.length)); statsPool.add(Arrays.copyOf(stats, stats.length));
maxIt--; maxIt--;
} }
byte[] bestM = CrackerCore.select(statsPool); int[] bestM = CrackerCore.select(statsPool);
if (bestM == null) { if (bestM == null) {
bin = bin*2; bin = bin*2;
System.out.print("#"); // we need to collect more stats System.out.print("#"); // we need to collect more stats