2022-03-17 12:33:23 +01:00
|
|
|
package ch.fhnw.kry;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
|
|
class SPNTest {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void k() {
|
|
|
|
var spn = new SPN();
|
|
|
|
|
|
|
|
final int key = 0xFFFFFFFF;
|
|
|
|
assertEquals(0xFFFF, spn.k(key, 0));
|
|
|
|
assertEquals(0xFFFF, spn.k(key, 1));
|
|
|
|
assertEquals(0xFFFF, spn.k(key, 2));
|
|
|
|
}
|
2022-03-17 14:40:35 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void substitution() {
|
|
|
|
var spn = new SPN();
|
|
|
|
|
|
|
|
//given
|
|
|
|
int x = 0xEF45;
|
|
|
|
int r = 0x051C;
|
|
|
|
System.out.print(Integer.toHexString(x));
|
|
|
|
|
|
|
|
//when
|
|
|
|
int y = spn.substitution(x);
|
|
|
|
|
|
|
|
// then
|
|
|
|
assertEquals(r, y);
|
|
|
|
|
|
|
|
// System.out.print(Integer.toHexString(spn.substitution(x)));
|
|
|
|
}
|
2022-03-17 15:03:39 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void swapBits() {
|
|
|
|
var spn = new SPN();
|
|
|
|
|
|
|
|
// given
|
|
|
|
int x = 0xA;
|
|
|
|
int r = 0xC;
|
|
|
|
|
|
|
|
// when
|
2022-03-17 17:59:32 +01:00
|
|
|
int y = spn.swapBits(x, 13, 14);
|
|
|
|
int yy = spn.swapBits(x, 14, 13);
|
|
|
|
int yyy = spn.swapBits(x, 14, 14);
|
2022-03-17 15:03:39 +01:00
|
|
|
|
|
|
|
// then
|
|
|
|
assertEquals(r, y);
|
|
|
|
assertEquals(r, yy);
|
2022-03-17 17:59:32 +01:00
|
|
|
assertEquals(x, yyy);
|
2022-03-17 15:03:39 +01:00
|
|
|
}
|
2022-03-17 12:33:23 +01:00
|
|
|
}
|