From 59161114e97ae54c16e96950edd43e1291f67c44 Mon Sep 17 00:00:00 2001 From: BKrauel <83715813+BKrauel@users.noreply.github.com> Date: Wed, 5 May 2021 16:59:51 -0400 Subject: [PATCH 1/2] Update Main.java --- Crypto/src/Main.java | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/Crypto/src/Main.java b/Crypto/src/Main.java index f257802..a7e64c9 100644 --- a/Crypto/src/Main.java +++ b/Crypto/src/Main.java @@ -7,14 +7,40 @@ public class Main { - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws IOException { + Scanner input = new Scanner(System.in); + System.out.printf("Please enter the key. (How many places you want each letter to shift):"); //Added custom number shift + String key = input.nextLine(); + try { + Integer.parseInt(key); + try { + if ((Integer.parseInt(key) > 26) || 0 > (Integer.parseInt(key))) { + System.out.println("Invalid Range"); + System.exit(0); + } + } catch (NumberFormatException e) { + System.out.println("It needs to be a number. "); + } + }catch (Exception e) { + System.out.println("An unknown error has occured"); + } + + + int keys = Integer.parseInt(key); + + InputStream in = new FileInputStream("sonnet18.txt"); String body = IOUtils.toString(in, StandardCharsets.UTF_8.name()); - System.out.println(body); + System.out.printf("\n\nNormal: \n\n%s\n\n", body); // Added formatting for user accessibility PrintStream out = new PrintStream(new FileOutputStream("sonnet18.enc")); - ROT13 rot13 = new ROT13(); + ROT13 rot13 = new ROT13(keys); String output = rot13.encrypt(body); + System.out.printf("Encrypted:\n\n%s\n\n", output); // Shows the output/ result of the encryption out.append(output); out.flush(); - } -} + + + + + +}} From 0a24d6f7933c91b76398392cb16d9cddc789af81 Mon Sep 17 00:00:00 2001 From: BKrauel <83715813+BKrauel@users.noreply.github.com> Date: Wed, 5 May 2021 17:00:45 -0400 Subject: [PATCH 2/2] Update ROT13.java --- Crypto/src/ROT13.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Crypto/src/ROT13.java b/Crypto/src/ROT13.java index d50b32f..c4b736e 100644 --- a/Crypto/src/ROT13.java +++ b/Crypto/src/ROT13.java @@ -10,9 +10,9 @@ public class ROT13 { this.shift = temp; } - ROT13() { - this.shift = 13; - } + ROT13(int key) { + this.shift = key; + } //Takes in a user number for how many places the letter should shift public String crypt(String text) throws UnsupportedOperationException { return crypt(text, shift);