diff --git a/bin/main/ch/fhnw/kry/SPN.class b/bin/main/ch/fhnw/kry/SPN.class index 317df83..335e3cb 100644 Binary files a/bin/main/ch/fhnw/kry/SPN.class and b/bin/main/ch/fhnw/kry/SPN.class differ diff --git a/src/main/java/ch/fhnw/kry/SPN.java b/src/main/java/ch/fhnw/kry/SPN.java index a4a31db..b17ea73 100644 --- a/src/main/java/ch/fhnw/kry/SPN.java +++ b/src/main/java/ch/fhnw/kry/SPN.java @@ -62,13 +62,22 @@ public class SPN { } 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; + int tmpA = (x & (0x1 << (15 - a))); + int tmpB = (x & (0x1 << (15 - b))); + + tmpA = tmpA == 0 ? 0 : 1; + tmpB = tmpB == 0 ? 0 : 1; - x = tmpA == 0 ? (x & 0x1 << 15 - b) & 0b0 : (x & 0x1 << 15 - b) & ~0b0; + tmpA = tmpA << (15 -b); + tmpB = tmpB << (15 - a); + x = x | tmpA; + x = x | tmpB; - return 0; + // x = tmpA == 0 ? (x & 0x1 << 15 - b) | 0b0 : (x & 0x1 << 15 - b) | ~0b0; + // x = tmpB == 0 ? (x & 0x1 << 15 - a) | 0b0 : (x & 0x1 << 15 - a) | ~0b0; + + return x; } }