push garbage

This commit is contained in:
Sebastian Hugentobler 2022-03-22 17:21:33 +01:00
parent 18cdd1ed81
commit 3bc74649ad
Signed by: shu
GPG key ID: BB32CF3CA052C2F0
7 changed files with 137 additions and 43 deletions

View file

@ -0,0 +1,34 @@
package ch.fhnw.kry;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
public class CTR {
private final SPN spn = new SPN();
private final int iv;
private final int key;
public CTR(int key) {
this.iv = generateIV();
this.key = key;
}
public int getIV() {
return iv;
}
public int generateIV() {
Random random = ThreadLocalRandom.current();
byte[] r = new byte[2];
random.nextBytes(r);
return r[0] << 8 & r[1];
}
public int decrypt(int block, int idx) {
int e = (iv + idx) % (1 << 16);
e = spn.decryptBlock(key, e);
return block ^ e;
}
}