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 --- .../prakt3/prakt3WS/p3/src/otp/OTP.java | 167 +++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 Master/Kryptografie/prakt3/prakt3WS/p3/src/otp/OTP.java (limited to 'Master/Kryptografie/prakt3/prakt3WS/p3/src/otp/OTP.java') diff --git a/Master/Kryptografie/prakt3/prakt3WS/p3/src/otp/OTP.java b/Master/Kryptografie/prakt3/prakt3WS/p3/src/otp/OTP.java new file mode 100644 index 0000000..b020aad --- /dev/null +++ b/Master/Kryptografie/prakt3/prakt3WS/p3/src/otp/OTP.java @@ -0,0 +1,167 @@ +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<