From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Master/Kryptografie/prakt3/prakt3WS/p3/.classpath | 6 + Master/Kryptografie/prakt3/prakt3WS/p3/.project | 19 +++ .../prakt3/prakt3WS/p3/bin/otp/LinReg.class | Bin 0 -> 1883 bytes .../prakt3/prakt3WS/p3/bin/otp/OTP.class | Bin 0 -> 3420 bytes .../prakt3/prakt3WS/p3/src/otp/LinReg.java | 100 ++++++++++++ .../prakt3/prakt3WS/p3/src/otp/OTP.java | 167 +++++++++++++++++++++ 6 files changed, 292 insertions(+) create mode 100644 Master/Kryptografie/prakt3/prakt3WS/p3/.classpath create mode 100644 Master/Kryptografie/prakt3/prakt3WS/p3/.project create mode 100644 Master/Kryptografie/prakt3/prakt3WS/p3/bin/otp/LinReg.class create mode 100644 Master/Kryptografie/prakt3/prakt3WS/p3/bin/otp/OTP.class create mode 100644 Master/Kryptografie/prakt3/prakt3WS/p3/src/otp/LinReg.java create mode 100644 Master/Kryptografie/prakt3/prakt3WS/p3/src/otp/OTP.java (limited to 'Master/Kryptografie/prakt3/prakt3WS/p3') diff --git a/Master/Kryptografie/prakt3/prakt3WS/p3/.classpath b/Master/Kryptografie/prakt3/prakt3WS/p3/.classpath new file mode 100644 index 0000000..d171cd4 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/p3/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Master/Kryptografie/prakt3/prakt3WS/p3/.project b/Master/Kryptografie/prakt3/prakt3WS/p3/.project new file mode 100644 index 0000000..a00503c --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/p3/.project @@ -0,0 +1,19 @@ + + + p3 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.jdt.core.javanature + org.eclipse.jem.beaninfo.BeanInfoNature + + diff --git a/Master/Kryptografie/prakt3/prakt3WS/p3/bin/otp/LinReg.class b/Master/Kryptografie/prakt3/prakt3WS/p3/bin/otp/LinReg.class new file mode 100644 index 0000000..4bee1e2 Binary files /dev/null and b/Master/Kryptografie/prakt3/prakt3WS/p3/bin/otp/LinReg.class differ diff --git a/Master/Kryptografie/prakt3/prakt3WS/p3/bin/otp/OTP.class b/Master/Kryptografie/prakt3/prakt3WS/p3/bin/otp/OTP.class new file mode 100644 index 0000000..b4c3e2b Binary files /dev/null and b/Master/Kryptografie/prakt3/prakt3WS/p3/bin/otp/OTP.class differ diff --git a/Master/Kryptografie/prakt3/prakt3WS/p3/src/otp/LinReg.java b/Master/Kryptografie/prakt3/prakt3WS/p3/src/otp/LinReg.java new file mode 100644 index 0000000..1e82b0e --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/p3/src/otp/LinReg.java @@ -0,0 +1,100 @@ +package otp; + +public class LinReg { + private int config; + private int status; + + public static final int bitMask = 0xff; + public static final int bitLength = 8; + + public LinReg (int config, int init) + { + this.config = 0; + this.status = 0; + this.config = config & bitMask; + this.status = init & bitMask; + //printOut(); + } + + public int getNextKeyBit() + { + return this.getNextBit(); + } + + public int getNextKey() + { + int ret=0; + int newBit; + for (int i=7;i>=0;i--) + { + newBit = getNextBit(); + //System.out.println(i+". key bit is: "+Integer.toBinaryString(newBit)); + ret += ( newBit << i); + //System.out.println("act key is: "+LinReg.to8BitString(ret)); + } + //System.out.println("New key is: "+LinReg.to8BitString(ret)); + return ret & bitMask; + } + + private int getNextBit() + { + //printOut(); + int ret=0; + //boolean tmp=false; + int cnt=0; + // left shift status to get next bit at bitLength + 1; + this.status = this.status << 1; + //System.out.println("Left shifted status: "+Integer.toBinaryString(this.status)); + // get bit at bitLength + 1; + ret = this.status & (~bitMask); + //System.out.println("key bit unshifted is: "+Integer.toBinaryString(ret)); + ret >>= bitLength; + //System.out.println("New key bit is: "+Integer.toBinaryString(ret)); + // calculate next bit from status and config + for (int i = 7; i >= 0; i--) + { + // test if actual status and config bit are + // set at position i + //if ( (this.status & i) && (this.config & i) ) + int statusBit = ((this.status & (1<> i); + int configBit = ((this.config & (1<> i); + + //System.out.println("Bit in Status: "+Integer.toBinaryString(statusBit)); + //System.out.println("Bit in Config: "+Integer.toBinaryString(configBit)); + + if ( (statusBit & configBit) == 1 ) + { + //System.out.println("Bit "+i+" is set in C and S"); + //tmp=!tmp; + cnt++; + } + } + if ( (cnt%2) == 1 ) + { + this.status |= 1; + //System.out.println("Appending 1 to status"); + } + else + { + //System.out.println("Appending 0 to status"); + } + this.status &= bitMask; + //printOut(); + return ret; + } + public void printOut() + { + System.out.println("Config is: "+to8BitString(this.config)); + System.out.println("Status is: "+to8BitString(this.status)); + } + + public static final String to8BitString(int input) + { + String res = Integer.toBinaryString(input); + for (int i = res.length();i=0;i--) + { + clearBit = clear & (1<