diff --git a/bin/main/ch/fhnw/kry/SPN.class b/bin/main/ch/fhnw/kry/SPN.class index e5a110b..317df83 100644 Binary files a/bin/main/ch/fhnw/kry/SPN.class and b/bin/main/ch/fhnw/kry/SPN.class differ diff --git a/bin/test/ch/fhnw/kry/SPNTest.class b/bin/test/ch/fhnw/kry/SPNTest.class index b5648b6..ec17f83 100644 Binary files a/bin/test/ch/fhnw/kry/SPNTest.class and b/bin/test/ch/fhnw/kry/SPNTest.class differ diff --git a/src/main/java/ch/fhnw/kry/SPN.java b/src/main/java/ch/fhnw/kry/SPN.java index d0f5e49..a4a31db 100644 --- a/src/main/java/ch/fhnw/kry/SPN.java +++ b/src/main/java/ch/fhnw/kry/SPN.java @@ -61,4 +61,14 @@ public class SPN { return x; } + public int swapBits(int x, int a, int b) { + int tmpA = (x & (0x1 << 15 - a)) == 0 ? 0 : 1; + int tmpB = (x & (0x1 << 15 - b)) == 0 ? 0 : 1; + + x = tmpA == 0 ? (x & 0x1 << 15 - b) & 0b0 : (x & 0x1 << 15 - b) & ~0b0; + + + return 0; + } + } diff --git a/src/test/java/ch/fhnw/kry/SPNTest.java b/src/test/java/ch/fhnw/kry/SPNTest.java index 3a29036..63952b1 100644 --- a/src/test/java/ch/fhnw/kry/SPNTest.java +++ b/src/test/java/ch/fhnw/kry/SPNTest.java @@ -33,4 +33,21 @@ class SPNTest { // System.out.print(Integer.toHexString(spn.substitution(x))); } + + @Test + void swapBits() { + var spn = new SPN(); + + // given + int x = 0xA; + int r = 0xC; + + // when + int y = spn.swapBits(x, 1, 2); + int yy = spn.swapBits(x, 2, 1); + + // then + assertEquals(r, y); + assertEquals(r, yy); + } }