Skip to content

Encoder decoder application by debugger#12

Open
Shubham25104 wants to merge 10 commits intoTech-Bizz-Devs:mainfrom
Shubham25104:Encoder-Decoder-Application
Open

Encoder decoder application by debugger#12
Shubham25104 wants to merge 10 commits intoTech-Bizz-Devs:mainfrom
Shubham25104:Encoder-Decoder-Application

Conversation

@Shubham25104
Copy link

@Shubham25104 Shubham25104 commented Feb 24, 2024

#1 Encoder decoder application

Summary by CodeRabbit

  • New Features
    • Introduced a Java Swing application with a graphical interface for encoding and decoding text using algorithms like Caesar Cipher and Base64.
  • Documentation
    • Added a new README with instructions and details about the Encoder Decoder application.
    • Removed the previous README content.
  • Chores
    • Added a GitHub Actions workflow to automate building and publishing Java packages on release.

@Shubham25104 Shubham25104 changed the title Encoder decoder application Encoder decoder application by debugger Feb 24, 2024
@coderabbitai
Copy link

coderabbitai bot commented Apr 20, 2025

Walkthrough

This update introduces a new Java Swing application, EncoderDecoder, which provides a graphical interface for encoding and decoding text using algorithms such as Caesar Cipher and Base64. The application includes user interface components for input, output, algorithm selection, and action buttons. A new README file is added to document the application's features, usage, and supported algorithms. Additionally, a GitHub Actions workflow is introduced to automate Gradle package publishing upon release creation, and the original README.md file content is removed, leaving it empty.

Changes

File(s) Change Summary
EncoderDecoder.java Added a new Java Swing GUI application for encoding and decoding text using selectable algorithms.
readme.md Added a new README file detailing the Encoder Decoder application's features, usage, and supported algorithms.
.github/workflows/gradle-publish.yml Introduced a GitHub Actions workflow for building and publishing the package via Gradle when a release is created.
README.md Removed all content from the original README, leaving the file empty.

Poem

In a garden of code, a new tool appears,
Encoding and decoding, dispelling all fears.
With Caesar and Base64, the secrets unwind,
A GUI for messages, both clever and kind.
Workflows now publish, the README renewed—
A bunny’s delight, with features imbued!
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🔭 Outside diff range comments (1)
readme.md (1)

1-44: 🛠️ Refactor suggestion

Add missing documentation about building with Gradle

The README mentions manual compilation but doesn't include instructions about building with Gradle, which is supported by the repository according to the workflow file.

Add a new section after the "How to Run" section:

 ## How to Run
 
 1. Ensure you have Java installed on your PC. If not, download and install Java from [here](https://www.java.com/en/download/).
 2. Download the `editor.java` file from this repository.
 3. Open Command Prompt (on Windows) or Terminal (on macOS/Linux).
 4. Navigate to the directory where the `editor.java` file is located.
 5. Compile the Java source file using the following command:
     ```bash
     javac EncoderDecoder.java
     ```
 6. Run the compiled Java program using the following command:
     ```bash
     java EncoderDecoder
     ```
+
+## Building with Gradle
+
+This project supports building with Gradle:
+
+1. Ensure you have JDK 17 or later installed
+2. Clone the repository
+3. Navigate to the project directory
+4. Run:
+   ```bash
+   ./gradlew build
+   ```
+5. To run the application:
+   ```bash
+   ./gradlew run
+   ```
+
 ## Usage
🧹 Nitpick comments (5)
.github/workflows/gradle-publish.yml (1)

1-44: Good implementation of GitHub Actions workflow for Gradle publishing

The workflow is well structured and follows best practices by:

  • Triggering only on release creation
  • Setting appropriate permissions
  • Using a specific commit hash for the Gradle action (security best practice)
  • Configuring JDK 17 with the Temurin distribution

Consider adding these improvements for better reliability and performance:

  1. Add a verification step to ensure the build is successful before publishing
  2. Implement caching for Gradle dependencies
 name: Gradle Package

 on:
   release:
     types: [created]

 jobs:
   build:

     runs-on: ubuntu-latest
     permissions:
       contents: read
       packages: write

     steps:
     - uses: actions/checkout@v4
     - name: Set up JDK 17
       uses: actions/setup-java@v4
       with:
         java-version: '17'
         distribution: 'temurin'
         server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
         settings-path: ${{ github.workspace }} # location for the settings.xml file

     - name: Setup Gradle
       uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
+
+    - name: Cache Gradle packages
+      uses: actions/cache@v3
+      with:
+        path: |
+          ~/.gradle/caches
+          ~/.gradle/wrapper
+        key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
+        restore-keys: |
+          ${{ runner.os }}-gradle-

     - name: Build with Gradle
       run: ./gradlew build

+    - name: Verify build success
+      run: |
+        if [ ! -d "build" ]; then
+          echo "Build directory not found, build may have failed"
+          exit 1
+        fi

     # The USERNAME and TOKEN need to correspond to the credentials environment variables used in
     # the publishing section of your build.gradle
     - name: Publish to GitHub Packages
       run: ./gradlew publish
       env:
         USERNAME: ${{ github.actor }}
         TOKEN: ${{ secrets.GITHUB_TOKEN }}
readme.md (1)

39-43: Expand or remove the empty Notes section

The Notes section contains only a single bullet point about Java Swing, with empty lines around it. Consider either expanding this section with more useful information or removing it if unnecessary.

 ## Notes
-
-
 - The application uses Java Swing for the graphical user interface.
+- The Caesar Cipher uses a fixed shift of 3 characters
+- Error handling is implemented for invalid Base64 decoding attempts
EncoderDecoder.java (3)

11-61: Improve the GUI layout for better usability

The current layout places the algorithm selection panel on the west side of the frame, which is not intuitive. Consider reorganizing the components for better user experience.

     public EncoderDecoder() {
         setTitle("Encoder Decoder");
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setSize(500, 300);
         setLocationRelativeTo(null);
 
         JPanel mainPanel = new JPanel();
         mainPanel.setLayout(new BorderLayout());
+        
+        // Create a panel for algorithm selection at the top
+        JPanel controlPanel = new JPanel();
+        controlPanel.setLayout(new FlowLayout());
+        
+        algorithmComboBox = new JComboBox<>();
+        algorithmComboBox.addItem("Caesar Cipher");
+        algorithmComboBox.addItem("Base64 Encoding");
+        // Add more encoding algorithms as needed
+        controlPanel.add(new JLabel("Select Algorithm:"));
+        controlPanel.add(algorithmComboBox);
 
         inputTextArea = new JTextArea(5, 20);
         JScrollPane inputScrollPane = new JScrollPane(inputTextArea);
 
         outputTextArea = new JTextArea(5, 20);
         JScrollPane outputScrollPane = new JScrollPane(outputTextArea);
         outputTextArea.setEditable(false);
 
         JPanel inputPanel = new JPanel();
         inputPanel.setLayout(new GridLayout(1, 2));
         inputPanel.add(new JLabel("Input:"));
         inputPanel.add(inputScrollPane);
 
         JPanel outputPanel = new JPanel();
         outputPanel.setLayout(new GridLayout(1, 2));
         outputPanel.add(new JLabel("Output:"));
         outputPanel.add(outputScrollPane);
 
         JPanel buttonPanel = new JPanel();
         encodeButton = new JButton("Encode");
         decodeButton = new JButton("Decode");
+        JButton clearButton = new JButton("Clear");
         buttonPanel.add(encodeButton);
         buttonPanel.add(decodeButton);
+        buttonPanel.add(clearButton);
 
-        JPanel algorithmPanel = new JPanel();
-        algorithmComboBox = new JComboBox<>();
-        algorithmComboBox.addItem("Caesar Cipher");
-        algorithmComboBox.addItem("Base64 Encoding");
-        // Add more encoding algorithms as needed
-        algorithmPanel.add(new JLabel("Select Algorithm:"));
-        algorithmPanel.add(algorithmComboBox);
-
+        JPanel contentPanel = new JPanel(new BorderLayout());
+        contentPanel.add(inputPanel, BorderLayout.NORTH);
+        contentPanel.add(outputPanel, BorderLayout.CENTER);
+        
-        mainPanel.add(inputPanel, BorderLayout.NORTH);
-        mainPanel.add(outputPanel, BorderLayout.CENTER);
+        mainPanel.add(controlPanel, BorderLayout.NORTH);
+        mainPanel.add(contentPanel, BorderLayout.CENTER);
         mainPanel.add(buttonPanel, BorderLayout.SOUTH);
-        mainPanel.add(algorithmPanel, BorderLayout.WEST);
 
         encodeButton.addActionListener(this);
         decodeButton.addActionListener(this);
+        clearButton.addActionListener(e -> {
+            inputTextArea.setText("");
+            outputTextArea.setText("");
+        });
 
         add(mainPanel);
         setVisible(true);
     }

130-135: Add similar error handling for Base64 encoding

You've implemented good error handling for Base64 decoding, but there's no equivalent error handling for encoding. While Base64 encoding rarely fails, it could fail if there are issues with the encoding of the input string.

 } else if (algorithm.equals("Base64 Encoding")) {
-    encodedText.append(Base64.getEncoder().encodeToString(input.getBytes()));
+    try {
+        encodedText.append(Base64.getEncoder().encodeToString(input.getBytes()));
+    } catch (Exception e) {
+        encodedText.append("Error encoding to Base64: " + e.getMessage());
+    }
 } else {

81-153: Extract common character manipulation into a reusable method

Both encode and decode methods contain similar code for manipulating characters based on whether they are letters. Consider extracting this functionality into a reusable method.

Create a helper method to process characters:

private char processChar(char c, int shift, boolean isEncode) {
    if (!Character.isLetter(c)) {
        return c;
    }
    
    char base = Character.isUpperCase(c) ? 'A' : 'a';
    int direction = isEncode ? 1 : -1;
    return (char) (((c - base + direction * shift + 26) % 26) + base);
}

Then simplify your encode and decode methods to use this helper:

 private String encode(String input, String algorithm) {
     StringBuilder encodedText = new StringBuilder();
 
     if (algorithm.equals("Caesar Cipher")) {
         int shift = 3; // Define the shift value for the Caesar Cipher
-        for (char c : input.toCharArray()) {
-            if (Character.isLetter(c)) {
-                char base = Character.isUpperCase(c) ? 'A' : 'a';
-                encodedText.append((char) (((c - base + shift) % 26) + base));
-            } else {
-                encodedText.append(c);
-            }
+        for (char c : input.toCharArray()) {
+            encodedText.append(processChar(c, shift, true));
         }
     } else if (algorithm.equals("Base64 Encoding")) {
         // ...

And similarly for the decode method.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db39502 and b5b6986.

📒 Files selected for processing (4)
  • .github/workflows/gradle-publish.yml (1 hunks)
  • EncoderDecoder.java (1 hunks)
  • README.md (0 hunks)
  • readme.md (1 hunks)
💤 Files with no reviewable changes (1)
  • README.md
🔇 Additional comments (2)
EncoderDecoder.java (2)

129-136: Good error handling for Base64 decoding

The implementation properly catches IllegalArgumentException when decoding invalid Base64 input and provides a helpful error message to the user.


156-158: Good use of SwingUtilities.invokeLater

Properly using SwingUtilities.invokeLater to ensure the UI is created on the Event Dispatch Thread is a good practice for Swing applications.

## How to Run

1. Ensure you have Java installed on your PC. If not, download and install Java from [here](https://www.java.com/en/download/).
2. Download the `editor.java` file from this repository.
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect filename in download instructions

The instruction mentions editor.java but the actual file name is EncoderDecoder.java as seen in the implementation.

-2. Download the `editor.java` file from this repository.
+2. Download the `EncoderDecoder.java` file from this repository.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
2. Download the `editor.java` file from this repository.
2. Download the `EncoderDecoder.java` file from this repository.

Comment on lines +84 to +96
if (algorithm.equals("Caesar Cipher")) {
int shift = 3; // Define the shift value for the Caesar Cipher (you can make it dynamic if needed)
for (char c : input.toCharArray()) {
if (Character.isLetter(c)) {
char base = Character.isUpperCase(c) ? 'A' : 'a';
encodedText.append((char) (((c - base + shift) % 26) + base));
} else {
encodedText.append(c);
}
}
} else if (algorithm.equals("Base64 Encoding")) {
encodedText.append(Base64.getEncoder().encodeToString(input.getBytes()));
} else {
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Make Caesar Cipher shift value configurable

The shift value for Caesar Cipher is hardcoded to 3, which limits the usefulness of this cipher algorithm. Consider making this value configurable through the UI.

Add a spinner or text field for the user to select the shift value:

 if (algorithm.equals("Caesar Cipher")) {
-    int shift = 3; // Define the shift value for the Caesar Cipher (you can make it dynamic if needed)
+    int shift = getCaesarShiftValue(); // Get the shift value from the UI
     for (char c : input.toCharArray()) {
         if (Character.isLetter(c)) {
             char base = Character.isUpperCase(c) ? 'A' : 'a';
             encodedText.append((char) (((c - base + shift) % 26) + base));
         } else {
             encodedText.append(c);
         }
     }
 } else if (algorithm.equals("Base64 Encoding")) {

And add a method to get the shift value:

private int getCaesarShiftValue() {
    // If you've added a spinner or text field for the shift value, get its value here
    // For now, return the default value
    return 3;
}

Comment on lines +97 to +110
// Handle custom encoding algorithms
// For example, let's say you have a custom substitution cipher where 'A' maps to 'X', 'B' maps to 'Y', etc.
StringBuilder customEncodedText = new StringBuilder();
for (char c : input.toCharArray()) {
if (Character.isLetter(c)) {
char base = Character.isUpperCase(c) ? 'A' : 'a';
char encodedChar = (char) (((c - base + 3) % 26) + base); // This is just an example custom encoding logic
customEncodedText.append(encodedChar);
} else {
customEncodedText.append(c);
}
}
encodedText.append(customEncodedText);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove redundant custom encoding implementation

The "custom" encoding implementation is identical to the Caesar Cipher with a shift of 3. This creates code duplication and confusion. Either remove this code or implement a truly different custom algorithm.

-    } else {
-        // Handle custom encoding algorithms
-        // For example, let's say you have a custom substitution cipher where 'A' maps to 'X', 'B' maps to 'Y', etc.
-        StringBuilder customEncodedText = new StringBuilder();
-        for (char c : input.toCharArray()) {
-            if (Character.isLetter(c)) {
-                char base = Character.isUpperCase(c) ? 'A' : 'a';
-                char encodedChar = (char) (((c - base + 3) % 26) + base); // This is just an example custom encoding logic
-                customEncodedText.append(encodedChar);
-            } else {
-                customEncodedText.append(c);
-            }
-        }
-        encodedText.append(customEncodedText);
+    } else {
+        // Handle any other algorithms that might be added in the future
+        encodedText.append("Unsupported algorithm: " + algorithm);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Handle custom encoding algorithms
// For example, let's say you have a custom substitution cipher where 'A' maps to 'X', 'B' maps to 'Y', etc.
StringBuilder customEncodedText = new StringBuilder();
for (char c : input.toCharArray()) {
if (Character.isLetter(c)) {
char base = Character.isUpperCase(c) ? 'A' : 'a';
char encodedChar = (char) (((c - base + 3) % 26) + base); // This is just an example custom encoding logic
customEncodedText.append(encodedChar);
} else {
customEncodedText.append(c);
}
}
encodedText.append(customEncodedText);
}
} else {
// Handle any other algorithms that might be added in the future
encodedText.append("Unsupported algorithm: " + algorithm);
}

Comment on lines +137 to +150
// Handle custom decoding algorithms
// For example, let's say you have a custom substitution cipher where 'X' maps to 'A', 'Y' maps to 'B', etc.
StringBuilder customDecodedText = new StringBuilder();
for (char c : input.toCharArray()) {
if (Character.isLetter(c)) {
char base = Character.isUpperCase(c) ? 'A' : 'a';
char decodedChar = (char) (((c - base - 3 + 26) % 26) + base); // This is just an example custom decoding logic
customDecodedText.append(decodedChar);
} else {
customDecodedText.append(c);
}
}
decodedText.append(customDecodedText);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove redundant custom decoding implementation

Similar to the encoding method, the "custom" decoding implementation is identical to the Caesar Cipher with a shift of 3. This creates code duplication and should be removed or replaced with a truly different algorithm.

-    } else {
-        // Handle custom decoding algorithms
-        // For example, let's say you have a custom substitution cipher where 'X' maps to 'A', 'Y' maps to 'B', etc.
-        StringBuilder customDecodedText = new StringBuilder();
-        for (char c : input.toCharArray()) {
-            if (Character.isLetter(c)) {
-                char base = Character.isUpperCase(c) ? 'A' : 'a';
-                char decodedChar = (char) (((c - base - 3 + 26) % 26) + base); // This is just an example custom decoding logic
-                customDecodedText.append(decodedChar);
-            } else {
-                customDecodedText.append(c);
-            }
-        }
-        decodedText.append(customDecodedText);
+    } else {
+        // Handle any other algorithms that might be added in the future
+        decodedText.append("Unsupported algorithm: " + algorithm);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Handle custom decoding algorithms
// For example, let's say you have a custom substitution cipher where 'X' maps to 'A', 'Y' maps to 'B', etc.
StringBuilder customDecodedText = new StringBuilder();
for (char c : input.toCharArray()) {
if (Character.isLetter(c)) {
char base = Character.isUpperCase(c) ? 'A' : 'a';
char decodedChar = (char) (((c - base - 3 + 26) % 26) + base); // This is just an example custom decoding logic
customDecodedText.append(decodedChar);
} else {
customDecodedText.append(c);
}
}
decodedText.append(customDecodedText);
}
} else {
// Handle any other algorithms that might be added in the future
decodedText.append("Unsupported algorithm: " + algorithm);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant