From d631848d839076eb9522631091c3f5ca0c12fb44 Mon Sep 17 00:00:00 2001 From: Simon Freiermuth Date: Thu, 17 Mar 2022 15:03:39 +0100 Subject: [PATCH] =?UTF-8?q?bit=20Flipper=20im=20the=20making=20?= =?UTF-8?q?=F0=9F=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/main/ch/fhnw/kry/SPN.class | Bin 2005 -> 2246 bytes bin/test/ch/fhnw/kry/SPNTest.class | Bin 1061 -> 1287 bytes src/main/java/ch/fhnw/kry/SPN.java | 10 ++++++++++ src/test/java/ch/fhnw/kry/SPNTest.java | 17 +++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/bin/main/ch/fhnw/kry/SPN.class b/bin/main/ch/fhnw/kry/SPN.class index e5a110b781695a9a792f4e01d4ad11b402c0f575..317df834b8e04d0d149ee6497600ddb0998a37c3 100644 GIT binary patch delta 297 zcmYk1y-EW?6otRLGugxi*(4B~XeYYqMPyMiiy-TN)JD4%8w(+jfL8G#?0f+m8_~uT zmKOHDjff{Mg2mkP%{kmN%xC=Gh(5l@Z@?NSPf^b$wZV1K&n|}pBTVu<@8pIRI_HKT zUiG`BWOt|T%&N~XuI6uzZFVqX^}ON`VbDlK28(|=Jg zT6K@wb}VQ%)dgK?#yp#>u*IUB_3{N0I=WGivLwsIDZ8TJm-a+X%L)4;uZkHCL=|%7 e4Z?WCzNp(|My7uT94ZLtaU_jY*rd&IIQ0WBUn)KT delta 56 zcmX>mc$J^))W2Q(7#J9A8T>YK1u{==WsYEE+kB6igGG{w!3!wC#Nf@~1Ejea7#V~Z Jq#1nKI03*73rqk2 diff --git a/bin/test/ch/fhnw/kry/SPNTest.class b/bin/test/ch/fhnw/kry/SPNTest.class index b5648b6d6f125bfefbc8ff36da7085fa615ed552..ec17f8356d549ebb4dc657897e5447d840227256 100644 GIT binary patch delta 265 zcmXAj%}N775QM)OXEw`Z6E{fIL!wd8#H>G{BKWhb#?yi?;L)Ra5hI8v@#F(|^qdC> zf{KC<;6sTe9=fKgr>nY0@nZ=x1t*1q+#uo#@QQFr)kL3q{v#%zmo5`tmWMw@$II2 zXSUt+!m$jNAY3FCc7=VaWYk$_h7CGwvdk8%Y^x7t@xO(Hnqq-P+VPl XPi#T~)9i~m#ndff$?3=9mm40ap2vY95&U{Ymd-n@^gk&%;;!3HS7#9#{m06hu( 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); + } }