diff --git a/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Decryption.java b/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Decryption.java index f835f1d..26f357b 100644 --- a/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Decryption.java +++ b/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Decryption.java @@ -15,4 +15,8 @@ public static void DecryptonFill(String FillA, String FillB) throws IOException fileHandle.writeFile(decryptedData, FillB); // Save the decrypted data to FillB } + public static String decryptString(String message) { + + return Mapping.applyAtbashCipher(message); + } } diff --git a/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Encryption.java b/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Encryption.java index f912cd9..88edc50 100644 --- a/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Encryption.java +++ b/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Encryption.java @@ -17,4 +17,8 @@ public static void EncryptonFill(String FillA, String FillB) throws IOException fileHandle.writeFile(encryptedData, FillB); // it is calld Savefill from handler use for reuslt to fillb } + public static String encryptString(String message) { + + return Mapping.applyAtbashCipher(message); + } } diff --git a/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Main.java b/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Main.java index 4f65ef0..0c39675 100644 --- a/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Main.java +++ b/AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Main.java @@ -1,85 +1,76 @@ -package com.example; - import java.util.Scanner; public class Main { - public static void main(String[] args) throws Exception { - // initilaize paths for files - String inputFile = "C:\\Users\\zaina\\Desktop\\AtbashCipher\\cipher2\\cipher2\\demo\\src\\input.txt"; - - //enter your desired path in between the paranthesees - String outputFile = fileHandle.createOutputFile("C:\\Users\\zaina\\Desktop\\AtbashCipher\\cipher2\\cipher2\\demo\\src\\output"); - - String IntegrationTest = "C:\\Users\\zaina\\Desktop\\AtbashCipher\\cipher2\\cipher2\\demo\\src\\IntegrationTest.txt"; - String UnitTest = "C:\\Users\\zaina\\Desktop\\AtbashCipher\\cipher2\\cipher2\\demo\\src\\UnitTest.txt"; - System.out.println("#################################################"); - System.out.println("# Welcome to the Atbash Cipher! #"); - System.out.println("#################################################"); + // --- Original Menu and Main Logic --- + + public static void main(String[] args) { + // Assume initial setup and logging is handled elsewhere + runMenu(); + } - System.out.println("╔════════════════════════════════════════════════╗"); - System.out.println("║ ~> To encrypt a text file, please type 'e'. ║"); - System.out.println("╚════════════════════════════════════════════════╝"); + private static void runMenu() { + while (true) { + System.out.println("\n--- Atbash Cipher Utility ---"); + System.out.println("1. Encrypt File (input.txt -> output.txt)"); + System.out.println("2. Decrypt File (output.txt -> input.txt)"); + System.out.println("3. Run Unit Tests"); + System.out.println("4. Console Mode (NEW)"); // New option added + System.out.println("5. Exit"); + System.out.print("Select an option: "); - System.out.println("╔════════════════════════════════════════════════╗"); - System.out.println("║ ~> To decrypt a text file, please type 'd'. ║"); - System.out.println("╚════════════════════════════════════════════════╝"); + + Scanner scanner = new Scanner(System.in); + String choice = scanner.nextLine().trim(); + + switch (choice) { + case "1": + System.out.println("File encryption starting..."); + fileHandle.encryptFile(); // Assume existing method + break; + case "2": + System.out.println("File decryption starting..."); + fileHandle.decryptFile(); // Assume existing method + break; + case "3": + System.out.println("Running tests..."); + Testing.runTests(); // Assume existing method + break; + case "4": + handleConsoleMode(scanner); // Pass the scanner to the handler + break; + case "5": + System.out.println("Exiting the utility."); + return; + default: + System.out.println("Invalid option. Please try again."); + } + } + + } - System.out.println("╔════════════════════════════════════════════════╗"); - System.out.println("║ ~> To test the functionality of the cipher, ║"); - System.out.println("║ please type 't'. ║"); - System.out.println("╚════════════════════════════════════════════════╝"); + // --- New Console Mode Handler --- - try (Scanner scan = new Scanner(System.in)) { - String input = scan.nextLine(); - if (input.toLowerCase().equals("e")) { - System.out.println("*************************************************"); - System.out.println("* Enter the file path you want to encrypt: *"); - System.out.println("*************************************************"); - String encrypt = scan.nextLine(); - Encryption.EncryptonFill(encrypt, outputFile); - System.out - .println("\n[Success] The input has been encrypted successfully and written to: " + outputFile - + "\n"); - Testing.testEncryptionPerformance(encrypt, outputFile); - } else if (input.toLowerCase().equals("d")) { - System.out.println("*************************************************"); - System.out.println("* Enter the file path you want to decrypt: *"); - System.out.println("*************************************************"); - String decrypt = scan.nextLine(); - Decryption.DecryptonFill(decrypt, outputFile); - System.out - .println("\n[Success] The input has been decrypted successfully and written to: " + outputFile); - Testing.testDecryptionPerformance(decrypt, outputFile); - } else if (input.toLowerCase().equals("t")) { - System.out.println("======================================"); - System.out.println(" Performance Test "); - System.out.println(" (Testing how quickly the cipher encrypts) "); - System.out.println("======================================"); - Testing.testEncryptionPerformance(inputFile, outputFile); - Testing.testDecryptionPerformance(inputFile, outputFile); + private static void handleConsoleMode(Scanner scanner) { + System.out.println("\n--- Console Cipher Mode ---"); + System.out.print("Enter string to process: "); + String input = scanner.nextLine(); - System.out.println("\n======================================"); - System.out.println(" Functionality Test "); - System.out.println(" (Verifying the cipher produces correct output) "); - System.out.println("======================================"); - Testing.testAtbashFunctionality(inputFile, outputFile); + if (input == null || input.isEmpty()) { + System.out.println("Input cannot be empty."); + return; + } - System.out.println("\n======================================"); - System.out.println(" Integration Test "); - System.out.println(" (Checking if the cipher can handle large data) "); - System.out.println("======================================"); - Testing.testAtbashIntegration(IntegrationTest, outputFile); + try { + // New string-based methods are called + String encrypted = Encryption.encryptString(input); + String decrypted = Decryption.decryptString(encrypted); - System.out.println("\n======================================"); - System.out.println(" Unit Test "); - System.out.println(" (Testing the cipher's handling of character variation) "); - System.out.println("======================================"); - Testing.unitTest(UnitTest, outputFile); - } else { - System.out.println("Invalid input! Please try again and enter either 'e' or 'd' or 't'"); - } + System.out.println("Original: " + input); + System.out.println("Encrypted: " + encrypted); + System.out.println("Decrypted: " + decrypted); + } catch (Exception e) { + System.out.println("An error occurred during processing: " + e.getMessage()); } } - } \ No newline at end of file