From 2a35bbbfab8cdd5afcdddd5816ae542839c9772a Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Thu, 17 Mar 2022 12:33:23 +0100 Subject: [PATCH] start with the K function --- .idea/modules/kry-spn.test.iml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ src/main/java/ch/fhnw/kry/Main.java | 3 +++ src/main/java/ch/fhnw/kry/SPN.java | 10 ++++++++++ src/test/java/ch/fhnw/kry/SPNTest.java | 18 ++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 .idea/modules/kry-spn.test.iml create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/ch/fhnw/kry/SPN.java create mode 100644 src/test/java/ch/fhnw/kry/SPNTest.java diff --git a/.idea/modules/kry-spn.test.iml b/.idea/modules/kry-spn.test.iml new file mode 100644 index 0000000..4a4ce55 --- /dev/null +++ b/.idea/modules/kry-spn.test.iml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/ch/fhnw/kry/Main.java b/src/main/java/ch/fhnw/kry/Main.java index fb559fb..2df47b5 100644 --- a/src/main/java/ch/fhnw/kry/Main.java +++ b/src/main/java/ch/fhnw/kry/Main.java @@ -5,6 +5,9 @@ package ch.fhnw.kry; */ public class Main { + private static final String KEY = "00111010100101001101011000111111"; + private static final String CHIFFRE = "00000100110100100000101110111000000000101000111110001110011111110110000001010001010000111010000000010011011001110010101110110000"; + public static void main(String[] args) { } diff --git a/src/main/java/ch/fhnw/kry/SPN.java b/src/main/java/ch/fhnw/kry/SPN.java new file mode 100644 index 0000000..a93c850 --- /dev/null +++ b/src/main/java/ch/fhnw/kry/SPN.java @@ -0,0 +1,10 @@ +package ch.fhnw.kry; + +public class SPN { + public int k(int key, int i) { + i *= 4; + int mask = 0xFFFF >>> i; + + return key & mask; + } +} diff --git a/src/test/java/ch/fhnw/kry/SPNTest.java b/src/test/java/ch/fhnw/kry/SPNTest.java new file mode 100644 index 0000000..0f0d838 --- /dev/null +++ b/src/test/java/ch/fhnw/kry/SPNTest.java @@ -0,0 +1,18 @@ +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)); + } +}