From ebb57b58553b9ca3d0a63df89ebc2383044d688c Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Mon, 11 Sep 2017 10:12:25 +0200 Subject: [PATCH] =?utf8?q?Programm=20besser=20strukturiert.=20Dabei=20ist?= =?utf8?q?=20aufgefallen,=20dass=20die=20Bedingungen=20f=C3=BCr=20ein=201-?= =?utf8?q?bit=20noch=20nicht=20hinhauen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/ScharedSecret.java | 50 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/ScharedSecret.java b/src/ScharedSecret.java index f38cbe3..0dd5fc7 100644 --- a/src/ScharedSecret.java +++ b/src/ScharedSecret.java @@ -1,3 +1,4 @@ +import java.io.IOException; import java.sql.Time; import java.util.Random; @@ -100,35 +101,46 @@ public class ScharedSecret { return result; } + private static String secret(String[] args){ + if (args != null && args.length > 0) return args[0]; + + try { + String secret = ""; + System.out.println("Please enter your secret:"); + int c; + while ((c = System.in.read()) != 10){ + secret+=(char)c; + } + return secret; + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + return null; + } + public static void main(String[] args) { - String secret="gnome-keyring"; - String code1=""; - String code2=""; - String code3=""; - String code4=""; - String code5=""; + String secret = secret(args); + String [] codes = { "", "", "", "", "" }; System.out.print(" Binary: "); for (int i=0; i(240+22)?1:0); + System.out.print((codes[0].charAt(i) + +codes[1].charAt(i) + +codes[2].charAt(i) + +codes[3].charAt(i) + +codes[4].charAt(i))>(240+22)?1:0); } } } -- 2.30.2