-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add Console Input/Output Mode #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,16 +3,19 @@ | |
| import java.io.IOException; | ||
|
|
||
| public class Decryption { | ||
| // method to decrpyt file | ||
| public static void DecryptonFill(String FillA, String FillB) throws IOException { | ||
| // FillA is for input file that contains encrypted data | ||
| // FillB is output file to store decrypted data | ||
| String encryptedData = fileHandle.readFile(FillA); | ||
| // Load the content of the encrypted file | ||
| String decryptedData = Mapping.applyAtbashCipher(encryptedData); | ||
| // Decrypt the data using Atbash cipher (Atbash is symmetric, so we use the same | ||
| // method) | ||
| fileHandle.writeFile(decryptedData, FillB); | ||
| // Save the decrypted data to FillB | ||
|
|
||
| // Assume existing file-based methods like decryptFile() are here | ||
|
|
||
| /** | ||
| * Decrypts a message string using the Atbash cipher. | ||
| * This method bypasses file I/O for direct string processing. | ||
| * | ||
| * @param message The string to be decrypted. | ||
| * @return The Atbash-decoded string. | ||
| */ | ||
| public static String decryptString(String message) { | ||
|
|
||
| return Mapping.applyAtbashCipher(message); | ||
| } | ||
|
Comment on lines
+16
to
19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Removing the original Prompt To Fix With AIThis is a comment left during a code review.
Path: AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Decryption.java
Line: 16:19
Comment:
**logic:** Removing the original `DecryptonFill()` method is a breaking change. Consider keeping both file-based and string-based methods for backward compatibility.
How can I resolve this? If you propose a fix, please make it concise. |
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,19 @@ | ||
| package com.example; | ||
|
|
||
| import java.io.IOException; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: IOException import is no longer needed since file operations were removed Prompt To Fix With AIThis is a comment left during a code review.
Path: AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Encryption.java
Line: 3:3
Comment:
**style:** IOException import is no longer needed since file operations were removed
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| public class Encryption { | ||
| // method to encrypt the file with letters | ||
| public static void EncryptonFill(String FillA, String FillB) throws IOException { | ||
| // contant method for encryption | ||
| // FillA is for input fill come from user to encryption | ||
| // FillB is output to decrption | ||
| // use throws IOException | ||
| // this method for handel read and write errors for encrypton and deycrption | ||
| String data = fileHandle.readFile(FillA); | ||
| // it is calld handler to data to read the contect | ||
| String encryptedData = Mapping.applyAtbashCipher(data); | ||
| // it will store the encrypted content ouyput | ||
| fileHandle.writeFile(encryptedData, FillB); | ||
| // it is calld Savefill from handler use for reuslt to fillb | ||
|
|
||
| // Assume existing file-based methods like encryptFile() are here | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Comment claims file-based methods should exist but they were completely removed from this class Prompt To Fix With AIThis is a comment left during a code review.
Path: AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Encryption.java
Line: 6:6
Comment:
**logic:** Comment claims file-based methods should exist but they were completely removed from this class
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| /** | ||
| * Encrypts a message string using the Atbash cipher. | ||
| * This method bypasses file I/O for direct string processing. | ||
| * | ||
| * @param message The string to be encrypted. | ||
| * @return The Atbash-encoded string. | ||
| */ | ||
| public static String encryptString(String message) { | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Extra blank line should be removed for consistent formatting Prompt To Fix With AIThis is a comment left during a code review.
Path: AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Encryption.java
Line: 16:16
Comment:
**style:** Extra blank line should be removed for consistent formatting
How can I resolve this? If you propose a fix, please make it concise. |
||
| return Mapping.applyAtbashCipher(message); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,85 +1,76 @@ | ||
| package com.example; | ||
|
|
||
| import java.util.Scanner; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: Missing package declaration - should be Prompt To Fix With AIThis is a comment left during a code review.
Path: AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Main.java
Line: 1:1
Comment:
**syntax:** Missing package declaration - should be `package com.example;`
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| 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(); | ||
|
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Scanner resource leak - creating new Scanner in each loop iteration without closing. Move Scanner creation outside the loop. Prompt To Fix With AIThis is a comment left during a code review.
Path: AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Main.java
Line: 23:24
Comment:
**logic:** Scanner resource leak - creating new Scanner in each loop iteration without closing. Move Scanner creation outside the loop.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| 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()); | ||
| } | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Comment claims file-based methods exist but they're missing from implementation. Either add the methods or remove misleading comment.
Prompt To Fix With AI