diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources')
23 files changed, 1027 insertions, 0 deletions
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/14/d027667d752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/14/d027667d752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..bbcbcf8 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/14/d027667d752a001d1a90a200dcb914a6 @@ -0,0 +1,36 @@ +package otp;
+
+import java.awt.Frame;
+
+public class OtpGui extends Frame {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * This is the default constructor
+ */
+ public OtpGui() {
+ super();
+ initialize();
+ }
+
+ /**
+ * This method initializes this
+ *
+ * @return void
+ */
+ private void initialize() {
+ this.setSize(300,200);
+ this.setTitle("Frame");
+
+ }
+
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/1a/7081ff1c752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/1a/7081ff1c752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..04fedf7 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/1a/7081ff1c752a001d1a90a200dcb914a6 @@ -0,0 +1,168 @@ +package otp;
+
+import LinReg;
+
+import java.util.Random;
+import java.util.Observable;
+
+public class OTP extends Observable {
+ LinReg enc_reg = null;
+ LinReg dec_reg = null;
+ Random rnd = new Random();
+ int config;
+ int init;
+ String plain="";
+ String cipher="";
+
+ public int[] getKeys()
+ {
+ int [] keys = new int[2];
+ keys[0] = config;
+ keys[1] = init;
+ return keys;
+ }
+
+ public String getPlain() {
+ return this.plain;
+ }
+
+ public String getCipher() {
+ return this.cipher;
+ }
+ public void setPlain(String p)
+ {
+ this.plain=p;
+ }
+
+ public void setCypher(String c)
+ {
+ this.cipher=c;
+ }
+
+ public void encrypt()
+ {
+ this.cipher = this.encrypt(this.config, this.init, this.plain);
+ }
+
+ public void decrypt()
+ {
+ this.plain = this.decrypt(this.config, this.init, this.cipher);
+ }
+
+ public int encryptOne(int clear, int key)
+ {
+ int cipher_int=0;
+ int keyBit=0;
+ int clearBit=0;
+ int cipherBit=0;
+ for (int i=7;i>=0;i--)
+ {
+ clearBit = clear & (1<<i);
+ keyBit = key & (1<<i);
+ cipherBit = keyBit ^ clearBit;
+ cipher_int |= cipherBit;
+ }
+ return cipher_int;
+ }
+
+ public int decryptOne(int cipher, int key)
+ {
+ int clear = encryptOne(cipher,key);
+ return clear;
+ }
+
+ private int encode(char c)
+ {
+ int ret = (int) c;
+ return ret;
+ }
+
+ private char decode(int i)
+ {
+ char ret = (char) i;
+ return ret;
+ }
+ public String encrypt(int config, int init, String plain)
+ {
+ enc_reg = new LinReg(config,init);
+ String cipherStr=new String();
+ int key=0;
+ int plain_int=0;
+ int cipher_int = 0;
+ char cipher_char = ' ';
+ char[] cipher_chars= new char[plain.length()];
+ for (int i = 0;i < plain.length(); i++)
+ {
+ key=enc_reg.getNextKey();
+ plain_int = encode(plain.charAt(i));
+ cipher_int = encryptOne(plain_int,key);
+ cipher_char = decode(cipher_int);
+ cipher_chars[i]=cipher_char;
+ }
+ cipherStr = String.copyValueOf(cipher_chars);
+ return cipherStr;
+ }
+
+ public String decrypt(int config, int init, String cipher)
+ {
+ dec_reg = new LinReg(config,init);
+ String plainStr=new String();
+ int key=0;
+ int plain_int=0;
+ int cipher_int = 0;
+ char plain_char = ' ';
+ char[] plain_chars= new char[cipher.length()];
+ for (int i = 0;i < cipher.length(); i++)
+ {
+ key=dec_reg.getNextKey();
+ cipher_int=encode(cipher.charAt(i));
+ plain_int=decryptOne(cipher_int,key);
+ plain_char=decode(plain_int);
+ plain_chars[i]=plain_char;
+ }
+ plainStr = String.copyValueOf(plain_chars);
+ return plainStr;
+ }
+
+ public void initialize()
+ {
+ setKeys(rnd.nextInt(0xff), rnd.nextInt(0xff));
+ }
+
+ public void setKeys(int c, int i)
+ {
+ config=c;
+ init=i;
+ enc_reg = new LinReg(config,init);
+ dec_reg = new LinReg(config,init);
+ }
+
+ public void doIt()
+ {
+
+ //int config=0x56;
+ //int init=0xf4;
+
+ this.initialize();
+
+/* String plain = "A quite long text";
+ String cipher= new String();
+ cipher=encrypt(config,init,plain);
+ System.out.println("Plain: "+plain.toUpperCase());
+ System.out.println("Cipher ASCII: "+cipher.toLowerCase());
+ System.out.print("Cipher dec: ");
+ for (int i=0;i<cipher.length();i++)
+ {
+ System.out.print((int)cipher.charAt(i)+" ");
+ }
+ System.out.println();
+ System.out.print("Cipher hex: ");
+ for (int i=0;i<cipher.length();i++)
+ {
+ System.out.print(Integer.toHexString((int)cipher.charAt(i))+" ");
+ }
+ System.out.println();
+ System.out.println("Decrypted: "+decrypt(config,init,cipher).toUpperCase());*/
+ }
+
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/1e/2099302e752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/1e/2099302e752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/1e/2099302e752a001d1a90a200dcb914a6 diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/24/50b44618752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/24/50b44618752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..04fedf7 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/24/50b44618752a001d1a90a200dcb914a6 @@ -0,0 +1,168 @@ +package otp;
+
+import LinReg;
+
+import java.util.Random;
+import java.util.Observable;
+
+public class OTP extends Observable {
+ LinReg enc_reg = null;
+ LinReg dec_reg = null;
+ Random rnd = new Random();
+ int config;
+ int init;
+ String plain="";
+ String cipher="";
+
+ public int[] getKeys()
+ {
+ int [] keys = new int[2];
+ keys[0] = config;
+ keys[1] = init;
+ return keys;
+ }
+
+ public String getPlain() {
+ return this.plain;
+ }
+
+ public String getCipher() {
+ return this.cipher;
+ }
+ public void setPlain(String p)
+ {
+ this.plain=p;
+ }
+
+ public void setCypher(String c)
+ {
+ this.cipher=c;
+ }
+
+ public void encrypt()
+ {
+ this.cipher = this.encrypt(this.config, this.init, this.plain);
+ }
+
+ public void decrypt()
+ {
+ this.plain = this.decrypt(this.config, this.init, this.cipher);
+ }
+
+ public int encryptOne(int clear, int key)
+ {
+ int cipher_int=0;
+ int keyBit=0;
+ int clearBit=0;
+ int cipherBit=0;
+ for (int i=7;i>=0;i--)
+ {
+ clearBit = clear & (1<<i);
+ keyBit = key & (1<<i);
+ cipherBit = keyBit ^ clearBit;
+ cipher_int |= cipherBit;
+ }
+ return cipher_int;
+ }
+
+ public int decryptOne(int cipher, int key)
+ {
+ int clear = encryptOne(cipher,key);
+ return clear;
+ }
+
+ private int encode(char c)
+ {
+ int ret = (int) c;
+ return ret;
+ }
+
+ private char decode(int i)
+ {
+ char ret = (char) i;
+ return ret;
+ }
+ public String encrypt(int config, int init, String plain)
+ {
+ enc_reg = new LinReg(config,init);
+ String cipherStr=new String();
+ int key=0;
+ int plain_int=0;
+ int cipher_int = 0;
+ char cipher_char = ' ';
+ char[] cipher_chars= new char[plain.length()];
+ for (int i = 0;i < plain.length(); i++)
+ {
+ key=enc_reg.getNextKey();
+ plain_int = encode(plain.charAt(i));
+ cipher_int = encryptOne(plain_int,key);
+ cipher_char = decode(cipher_int);
+ cipher_chars[i]=cipher_char;
+ }
+ cipherStr = String.copyValueOf(cipher_chars);
+ return cipherStr;
+ }
+
+ public String decrypt(int config, int init, String cipher)
+ {
+ dec_reg = new LinReg(config,init);
+ String plainStr=new String();
+ int key=0;
+ int plain_int=0;
+ int cipher_int = 0;
+ char plain_char = ' ';
+ char[] plain_chars= new char[cipher.length()];
+ for (int i = 0;i < cipher.length(); i++)
+ {
+ key=dec_reg.getNextKey();
+ cipher_int=encode(cipher.charAt(i));
+ plain_int=decryptOne(cipher_int,key);
+ plain_char=decode(plain_int);
+ plain_chars[i]=plain_char;
+ }
+ plainStr = String.copyValueOf(plain_chars);
+ return plainStr;
+ }
+
+ public void initialize()
+ {
+ setKeys(rnd.nextInt(0xff), rnd.nextInt(0xff));
+ }
+
+ public void setKeys(int c, int i)
+ {
+ config=c;
+ init=i;
+ enc_reg = new LinReg(config,init);
+ dec_reg = new LinReg(config,init);
+ }
+
+ public void doIt()
+ {
+
+ //int config=0x56;
+ //int init=0xf4;
+
+ this.initialize();
+
+/* String plain = "A quite long text";
+ String cipher= new String();
+ cipher=encrypt(config,init,plain);
+ System.out.println("Plain: "+plain.toUpperCase());
+ System.out.println("Cipher ASCII: "+cipher.toLowerCase());
+ System.out.print("Cipher dec: ");
+ for (int i=0;i<cipher.length();i++)
+ {
+ System.out.print((int)cipher.charAt(i)+" ");
+ }
+ System.out.println();
+ System.out.print("Cipher hex: ");
+ for (int i=0;i<cipher.length();i++)
+ {
+ System.out.print(Integer.toHexString((int)cipher.charAt(i))+" ");
+ }
+ System.out.println();
+ System.out.println("Decrypted: "+decrypt(config,init,cipher).toUpperCase());*/
+ }
+
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/4/f0405a7d752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/4/f0405a7d752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..c10a6af --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/4/f0405a7d752a001d1a90a200dcb914a6 @@ -0,0 +1,15 @@ +package otp;
+
+import java.awt.Frame;
+
+public class OtpGui extends Frame {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/4c/f0a31e65752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/4c/f0a31e65752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..b2180a6 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/4c/f0a31e65752a001d1a90a200dcb914a6 @@ -0,0 +1,13 @@ +package otp;
+
+public class OtpUi {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ System.out.
+ }
+
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/5/d0b6637d752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/5/d0b6637d752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..647f66d --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/5/d0b6637d752a001d1a90a200dcb914a6 @@ -0,0 +1,25 @@ +package otp;
+
+import java.awt.Frame;
+
+public class OtpGui extends Frame {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * This is the default constructor
+ */
+ public OtpGui() {
+ super();
+ initialize();
+ }
+
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/51/603c041d752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/51/603c041d752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..1e82b0e --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/51/603c041d752a001d1a90a200dcb914a6 @@ -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) ) >> i);
+ int configBit = ((this.config & (1<<i) ) >> 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<bitLength;i++)
+ {
+ res="0"+res;
+ }
+ return res;
+ }
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/65/c0484795752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/65/c0484795752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..6104213 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/65/c0484795752a001d1a90a200dcb914a6 @@ -0,0 +1,36 @@ +package otp;
+
+import java.awt.Frame;
+
+public class OtpGui extends Frame {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * This is the default constructor
+ */
+ public OtpGui() {
+ super();
+ initialize();
+ }
+
+ /**
+ * This method initializes this
+ *
+ * @return void
+ */
+ private void initialize() {
+ this.setSize(300, 200);
+ this.setTitle("Frame");
+
+ }
+
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/a2/f0321c65752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/a2/f0321c65752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..97b76b8 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/a2/f0321c65752a001d1a90a200dcb914a6 @@ -0,0 +1,13 @@ +package otp;
+
+public class OtpUi {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/ab/a0ba2718752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/ab/a0ba2718752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..1c0f850 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/ab/a0ba2718752a001d1a90a200dcb914a6 @@ -0,0 +1,166 @@ +package otp;
+
+import java.util.Random;
+import java.util.Observable;
+
+public class OTP extends Observable {
+ LinReg enc_reg = null;
+ LinReg dec_reg = null;
+ Random rnd = new Random();
+ int config;
+ int init;
+ String plain="";
+ String cipher="";
+
+ public int[] getKeys()
+ {
+ int [] keys = new int[2];
+ keys[0] = config;
+ keys[1] = init;
+ return keys;
+ }
+
+ public String getPlain() {
+ return this.plain;
+ }
+
+ public String getCipher() {
+ return this.cipher;
+ }
+ public void setPlain(String p)
+ {
+ this.plain=p;
+ }
+
+ public void setCypher(String c)
+ {
+ this.cipher=c;
+ }
+
+ public void encrypt()
+ {
+ this.cipher = this.encrypt(this.config, this.init, this.plain);
+ }
+
+ public void decrypt()
+ {
+ this.plain = this.decrypt(this.config, this.init, this.cipher);
+ }
+
+ public int encryptOne(int clear, int key)
+ {
+ int cipher_int=0;
+ int keyBit=0;
+ int clearBit=0;
+ int cipherBit=0;
+ for (int i=7;i>=0;i--)
+ {
+ clearBit = clear & (1<<i);
+ keyBit = key & (1<<i);
+ cipherBit = keyBit ^ clearBit;
+ cipher_int |= cipherBit;
+ }
+ return cipher_int;
+ }
+
+ public int decryptOne(int cipher, int key)
+ {
+ int clear = encryptOne(cipher,key);
+ return clear;
+ }
+
+ private int encode(char c)
+ {
+ int ret = (int) c;
+ return ret;
+ }
+
+ private char decode(int i)
+ {
+ char ret = (char) i;
+ return ret;
+ }
+ public String encrypt(int config, int init, String plain)
+ {
+ enc_reg = new LinReg(config,init);
+ String cipherStr=new String();
+ int key=0;
+ int plain_int=0;
+ int cipher_int = 0;
+ char cipher_char = ' ';
+ char[] cipher_chars= new char[plain.length()];
+ for (int i = 0;i < plain.length(); i++)
+ {
+ key=enc_reg.getNextKey();
+ plain_int = encode(plain.charAt(i));
+ cipher_int = encryptOne(plain_int,key);
+ cipher_char = decode(cipher_int);
+ cipher_chars[i]=cipher_char;
+ }
+ cipherStr = String.copyValueOf(cipher_chars);
+ return cipherStr;
+ }
+
+ public String decrypt(int config, int init, String cipher)
+ {
+ dec_reg = new LinReg(config,init);
+ String plainStr=new String();
+ int key=0;
+ int plain_int=0;
+ int cipher_int = 0;
+ char plain_char = ' ';
+ char[] plain_chars= new char[cipher.length()];
+ for (int i = 0;i < cipher.length(); i++)
+ {
+ key=dec_reg.getNextKey();
+ cipher_int=encode(cipher.charAt(i));
+ plain_int=decryptOne(cipher_int,key);
+ plain_char=decode(plain_int);
+ plain_chars[i]=plain_char;
+ }
+ plainStr = String.copyValueOf(plain_chars);
+ return plainStr;
+ }
+
+ public void initialize()
+ {
+ setKeys(rnd.nextInt(0xff), rnd.nextInt(0xff));
+ }
+
+ public void setKeys(int c, int i)
+ {
+ config=c;
+ init=i;
+ enc_reg = new LinReg(config,init);
+ dec_reg = new LinReg(config,init);
+ }
+
+ public void doIt()
+ {
+
+ //int config=0x56;
+ //int init=0xf4;
+
+ this.initialize();
+
+/* String plain = "A quite long text";
+ String cipher= new String();
+ cipher=encrypt(config,init,plain);
+ System.out.println("Plain: "+plain.toUpperCase());
+ System.out.println("Cipher ASCII: "+cipher.toLowerCase());
+ System.out.print("Cipher dec: ");
+ for (int i=0;i<cipher.length();i++)
+ {
+ System.out.print((int)cipher.charAt(i)+" ");
+ }
+ System.out.println();
+ System.out.print("Cipher hex: ");
+ for (int i=0;i<cipher.length();i++)
+ {
+ System.out.print(Integer.toHexString((int)cipher.charAt(i))+" ");
+ }
+ System.out.println();
+ System.out.println("Decrypted: "+decrypt(config,init,cipher).toUpperCase());*/
+ }
+
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/b1/50aa317d752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/b1/50aa317d752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/b1/50aa317d752a001d1a90a200dcb914a6 diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/cb/60cb011d752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/cb/60cb011d752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..1e82b0e --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/cb/60cb011d752a001d1a90a200dcb914a6 @@ -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) ) >> i);
+ int configBit = ((this.config & (1<<i) ) >> 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<bitLength;i++)
+ {
+ res="0"+res;
+ }
+ return res;
+ }
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0fb5e7d752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0fb5e7d752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..05d5de9 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0fb5e7d752a001d1a90a200dcb914a6 @@ -0,0 +1,17 @@ +package otp;
+
+import java.awt.Frame;
+
+public class OtpGui extends Frame {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/f9/70eb3518752a001d1a90a200dcb914a6 b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/f9/70eb3518752a001d1a90a200dcb914a6 new file mode 100644 index 0000000..04fedf7 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.history/f9/70eb3518752a001d1a90a200dcb914a6 @@ -0,0 +1,168 @@ +package otp;
+
+import LinReg;
+
+import java.util.Random;
+import java.util.Observable;
+
+public class OTP extends Observable {
+ LinReg enc_reg = null;
+ LinReg dec_reg = null;
+ Random rnd = new Random();
+ int config;
+ int init;
+ String plain="";
+ String cipher="";
+
+ public int[] getKeys()
+ {
+ int [] keys = new int[2];
+ keys[0] = config;
+ keys[1] = init;
+ return keys;
+ }
+
+ public String getPlain() {
+ return this.plain;
+ }
+
+ public String getCipher() {
+ return this.cipher;
+ }
+ public void setPlain(String p)
+ {
+ this.plain=p;
+ }
+
+ public void setCypher(String c)
+ {
+ this.cipher=c;
+ }
+
+ public void encrypt()
+ {
+ this.cipher = this.encrypt(this.config, this.init, this.plain);
+ }
+
+ public void decrypt()
+ {
+ this.plain = this.decrypt(this.config, this.init, this.cipher);
+ }
+
+ public int encryptOne(int clear, int key)
+ {
+ int cipher_int=0;
+ int keyBit=0;
+ int clearBit=0;
+ int cipherBit=0;
+ for (int i=7;i>=0;i--)
+ {
+ clearBit = clear & (1<<i);
+ keyBit = key & (1<<i);
+ cipherBit = keyBit ^ clearBit;
+ cipher_int |= cipherBit;
+ }
+ return cipher_int;
+ }
+
+ public int decryptOne(int cipher, int key)
+ {
+ int clear = encryptOne(cipher,key);
+ return clear;
+ }
+
+ private int encode(char c)
+ {
+ int ret = (int) c;
+ return ret;
+ }
+
+ private char decode(int i)
+ {
+ char ret = (char) i;
+ return ret;
+ }
+ public String encrypt(int config, int init, String plain)
+ {
+ enc_reg = new LinReg(config,init);
+ String cipherStr=new String();
+ int key=0;
+ int plain_int=0;
+ int cipher_int = 0;
+ char cipher_char = ' ';
+ char[] cipher_chars= new char[plain.length()];
+ for (int i = 0;i < plain.length(); i++)
+ {
+ key=enc_reg.getNextKey();
+ plain_int = encode(plain.charAt(i));
+ cipher_int = encryptOne(plain_int,key);
+ cipher_char = decode(cipher_int);
+ cipher_chars[i]=cipher_char;
+ }
+ cipherStr = String.copyValueOf(cipher_chars);
+ return cipherStr;
+ }
+
+ public String decrypt(int config, int init, String cipher)
+ {
+ dec_reg = new LinReg(config,init);
+ String plainStr=new String();
+ int key=0;
+ int plain_int=0;
+ int cipher_int = 0;
+ char plain_char = ' ';
+ char[] plain_chars= new char[cipher.length()];
+ for (int i = 0;i < cipher.length(); i++)
+ {
+ key=dec_reg.getNextKey();
+ cipher_int=encode(cipher.charAt(i));
+ plain_int=decryptOne(cipher_int,key);
+ plain_char=decode(plain_int);
+ plain_chars[i]=plain_char;
+ }
+ plainStr = String.copyValueOf(plain_chars);
+ return plainStr;
+ }
+
+ public void initialize()
+ {
+ setKeys(rnd.nextInt(0xff), rnd.nextInt(0xff));
+ }
+
+ public void setKeys(int c, int i)
+ {
+ config=c;
+ init=i;
+ enc_reg = new LinReg(config,init);
+ dec_reg = new LinReg(config,init);
+ }
+
+ public void doIt()
+ {
+
+ //int config=0x56;
+ //int init=0xf4;
+
+ this.initialize();
+
+/* String plain = "A quite long text";
+ String cipher= new String();
+ cipher=encrypt(config,init,plain);
+ System.out.println("Plain: "+plain.toUpperCase());
+ System.out.println("Cipher ASCII: "+cipher.toLowerCase());
+ System.out.print("Cipher dec: ");
+ for (int i=0;i<cipher.length();i++)
+ {
+ System.out.print((int)cipher.charAt(i)+" ");
+ }
+ System.out.println();
+ System.out.print("Cipher hex: ");
+ for (int i=0;i<cipher.length();i++)
+ {
+ System.out.print(Integer.toHexString((int)cipher.charAt(i))+" ");
+ }
+ System.out.println();
+ System.out.println("Decrypted: "+decrypt(config,init,cipher).toUpperCase());*/
+ }
+
+}
diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.projects/p3/.indexes/e4/2b/history.index b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.projects/p3/.indexes/e4/2b/history.index Binary files differnew file mode 100644 index 0000000..801b789 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.projects/p3/.indexes/e4/2b/history.index diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.projects/p3/.indexes/e4/history.index b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.projects/p3/.indexes/e4/history.index Binary files differnew file mode 100644 index 0000000..7dff250 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.projects/p3/.indexes/e4/history.index diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.projects/p3/org.eclipse.jdt.core/state.dat b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.projects/p3/org.eclipse.jdt.core/state.dat Binary files differnew file mode 100644 index 0000000..b85000a --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.projects/p3/org.eclipse.jdt.core/state.dat diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version new file mode 100644 index 0000000..25cb955 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index Binary files differnew file mode 100644 index 0000000..2ff09c6 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version new file mode 100644 index 0000000..6b2aaa7 --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/2.tree b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/2.tree Binary files differnew file mode 100644 index 0000000..7f2026f --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.root/2.tree diff --git a/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources Binary files differnew file mode 100644 index 0000000..7da038d --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources |
