Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Inconsistent indentation - should align with other method declarations

Prompt To Fix With AI
This is a comment left during a code review.
Path: AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Decryption.java
Line: 18:18

Comment:
**style:** Inconsistent indentation - should align with other method declarations

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
Expand Up @@ -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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Inconsistent indentation - method should align with the existing method above

Prompt To Fix With AI
This is a comment left during a code review.
Path: AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Encryption.java
Line: 20:20

Comment:
**style:** Inconsistent indentation - method should align with the existing method above

How can I resolve this? If you propose a fix, please make it concise.


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Empty line not needed here

Prompt To Fix With AI
This is a comment left during a code review.
Path: AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Encryption.java
Line: 21:21

Comment:
**style:** Empty line not needed here

How can I resolve this? If you propose a fix, please make it concise.

return Mapping.applyAtbashCipher(message);
}
}
133 changes: 62 additions & 71 deletions AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Main.java
Original file line number Diff line number Diff line change
@@ -1,85 +1,76 @@
package com.example;

import java.util.Scanner;

public class Main {
Comment on lines 1 to 3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Package declaration was removed - this may cause compilation issues if other classes expect this to be in the com.example package

Prompt To Fix With AI
This is a comment left during a code review.
Path: AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Main.java
Line: 1:3

Comment:
**logic:** Package declaration was removed - this may cause compilation issues if other classes expect this to be in the com.example package

How can I resolve this? If you propose a fix, please make it concise.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Scanner is created inside the loop but never closed, causing resource leaks. Create one Scanner outside the loop and reuse it

Prompt To Fix With AI
This 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 is created inside the loop but never closed, causing resource leaks. Create one Scanner outside the loop and reuse it

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());
}
}

}