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

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
This is a comment left during a code review.
Path: AtbashCipher/cipher2/cipher2/demo/src/main/java/com/example/Decryption.java
Line: 7:7

Comment:
**logic:** Comment claims file-based methods exist but they're missing from implementation. Either add the methods or remove misleading comment.

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


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

Choose a reason for hiding this comment

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

logic: Removing the original DecryptonFill() method is a breaking change. Consider keeping both file-based and string-based methods for backward compatibility.

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

Choose a reason for hiding this comment

The 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 AI
This 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
Copy link

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 should exist but they were completely removed from this class

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: 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) {

Copy link

Choose a reason for hiding this comment

The 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 AI
This 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);
}
}
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;
Copy link

Choose a reason for hiding this comment

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

syntax: Missing package declaration - should be package com.example;

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

Choose a reason for hiding this comment

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

}