bit Flipper im the making 🐬
This commit is contained in:
parent
0851f73c88
commit
d631848d83
Binary file not shown.
Binary file not shown.
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user