From b59c7bcdce9cbd9dbb41f9a01a5dbe42bb064745 Mon Sep 17 00:00:00 2001 From: Shubham25104 <117568702+Shubham25104@users.noreply.github.com> Date: Sat, 24 Feb 2024 13:57:33 +0530 Subject: [PATCH 01/10] Basic text editor #8 Basic text editor --- Texteditor.java | 268 ++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 45 ++++++++ 2 files changed, 313 insertions(+) create mode 100644 Texteditor.java create mode 100644 readme.md diff --git a/Texteditor.java b/Texteditor.java new file mode 100644 index 0000000..e60bece --- /dev/null +++ b/Texteditor.java @@ -0,0 +1,268 @@ +// Java Program to create a text editor using java + +import javax.swing.*; +import java.io.*; +import java.awt.event.*; +import javax.swing.plaf.metal.*; + +class Texteditor extends JFrame implements ActionListener { + // Text component + + JTextArea t; + private JFrame[] frames; + private JTextArea[] textAreas; + private int numOpenFiles; + + // Frame + JFrame f; + + // Constructor + Texteditor() { + // Create a frame + f = new JFrame("editor"); + + try { + // Set metal look and feel + UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); + + // Set theme to ocean + MetalLookAndFeel.setCurrentTheme(new OceanTheme()); + } catch (Exception e) { + } + + // Text component + t = new JTextArea(); + // Initialize arrays + frames = new JFrame[10]; // Assuming a maximum of 10 open files + textAreas = new JTextArea[10]; + numOpenFiles = 0; + + // Create a menubar + JMenuBar mb = new JMenuBar(); + + // Create amenu for menu + JMenu m1 = new JMenu("File"); + + // Create menu items + JMenuItem mi1 = new JMenuItem("New"); + JMenuItem mi2 = new JMenuItem("Open"); + JMenuItem mi3 = new JMenuItem("Save"); + JMenuItem mi9 = new JMenuItem("Print"); + + // Add action listener + mi1.addActionListener(this); + mi2.addActionListener(this); + mi3.addActionListener(this); + mi9.addActionListener(this); + + m1.add(mi1); + m1.add(mi2); + m1.add(mi3); + m1.add(mi9); + + // Create amenu for menu + JMenu m2 = new JMenu("Edit"); + + // Create menu items + JMenuItem mi4 = new JMenuItem("cut"); + JMenuItem mi5 = new JMenuItem("copy"); + JMenuItem mi6 = new JMenuItem("paste"); + + // Add action listener + mi4.addActionListener(this); + mi5.addActionListener(this); + mi6.addActionListener(this); + + m2.add(mi4); + m2.add(mi5); + m2.add(mi6); + + JMenuItem mc = new JMenuItem("close"); + + mc.addActionListener(this); + + mb.add(m1); + mb.add(m2); + mb.add(mc); + + f.setJMenuBar(mb); + f.add(t); + f.setSize(500, 500); + f.show(); + } + + // If a button is pressed + public void actionPerformed(ActionEvent e) { + String s = e.getActionCommand(); + + if (s.equals("cut")) { + t.cut(); + } else if (s.equals("copy")) { + t.copy(); + } else if (s.equals("paste")) { + t.paste(); + } else if (s.equals("Save")) { + // Create an object of JFileChooser class + JFileChooser j = new JFileChooser("f:"); + + // Invoke the showsSaveDialog function to show the save dialog + int r = j.showSaveDialog(null); + + if (r == JFileChooser.APPROVE_OPTION) { + + // Set the label to the path of the selected directory + File fi = new File(j.getSelectedFile().getAbsolutePath()); + + try { + // Create a file writer + FileWriter wr = new FileWriter(fi, false); + + // Create buffered writer to write + BufferedWriter w = new BufferedWriter(wr); + + // Write + w.write(t.getText()); + + w.flush(); + w.close(); + } catch (Exception evt) { + JOptionPane.showMessageDialog(f, evt.getMessage()); + } + } // If the user cancelled the operation + else { + JOptionPane.showMessageDialog(f, "the user cancelled the operation"); + } + } else if (s.equals("Print")) { + try { + // print the file + t.print(); + } catch (Exception evt) { + JOptionPane.showMessageDialog(f, evt.getMessage()); + } + } else if (s.equals("Open")) { + // Create an object of JFileChooser class + JFileChooser j = new JFileChooser("f:"); + + // Invoke the showsOpenDialog function to show the save dialog + int r = j.showOpenDialog(null); + + // If the user selects a file + if (r == JFileChooser.APPROVE_OPTION) { + // Set the label to the path of the selected directory + File fi = new File(j.getSelectedFile().getAbsolutePath()); + + try { + // String + String s1 = "", sl = ""; + + // File reader + FileReader fr = new FileReader(fi); + + // Buffered reader + BufferedReader br = new BufferedReader(fr); + + // Initialize sl + sl = br.readLine(); + + // Take the input from the file + while ((s1 = br.readLine()) != null) { + sl = sl + "\n" + s1; + } + + // Set the text + t.setText(sl); + } catch (Exception evt) { + JOptionPane.showMessageDialog(f, evt.getMessage()); + } + } // If the user cancelled the operation + else { + JOptionPane.showMessageDialog(f, "the user cancelled the operation"); + } + } else if (s.equals("New")) { + t.setText(""); + createNewFile(); + } else if (s.equals("close")) { + f.setVisible(false); + } + } + + private void createNewFile() { + JFrame frame = new JFrame("Untitled-" + (numOpenFiles + 1)); + JTextArea textArea = new JTextArea(); + JScrollPane scrollPane = new JScrollPane(textArea); + frame.add(scrollPane); + + // Create a menubar + JMenuBar mb = new JMenuBar(); + + // Create a menu for File + JMenu m1 = new JMenu("File"); + + // Create menu items for File + JMenuItem mi1 = new JMenuItem("New"); + JMenuItem mi2 = new JMenuItem("Open"); + JMenuItem mi3 = new JMenuItem("Save"); + JMenuItem mi9 = new JMenuItem("Print"); + + // Add action listeners to menu items + mi1.addActionListener(this); + mi2.addActionListener(this); + mi3.addActionListener(this); + mi9.addActionListener(this); + + // Add menu items to the File menu + m1.add(mi1); + m1.add(mi2); + m1.add(mi3); + m1.add(mi9); + + // Create a menu for Edit + JMenu m2 = new JMenu("Edit"); + + // Create menu items for Edit + JMenuItem mi4 = new JMenuItem("cut"); + JMenuItem mi5 = new JMenuItem("copy"); + JMenuItem mi6 = new JMenuItem("paste"); + + // Add action listeners to menu items + mi4.addActionListener(this); + mi5.addActionListener(this); + mi6.addActionListener(this); + + // Add menu items to the Edit menu + m2.add(mi4); + m2.add(mi5); + m2.add(mi6); + + // Create a menu item for Close + JMenuItem mc = new JMenuItem("close"); + + // Add action listener to the Close menu item + mc.addActionListener(this); + + // Add File and Edit menus to the menubar + mb.add(m1); + mb.add(m2); + + // Add Close menu item to the menubar + mb.add(mc); + + // Set the menubar for the frame + frame.setJMenuBar(mb); + + // Set frame size and visibility + frame.setSize(500, 500); + frame.setVisible(true); + + // Store references to JFrame and JTextArea + frames[numOpenFiles] = frame; + textAreas[numOpenFiles] = textArea; + numOpenFiles++; +} + + + // Main class + public static void main(String args[]) { + Texteditor e = new Texteditor(); + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..df5d9d5 --- /dev/null +++ b/readme.md @@ -0,0 +1,45 @@ +# Simple Text Editor + +This is a simple text editor application created using Java Swing. + +## Features + +- Create new text files. +- Open existing text files. +- Save text files. +- Print text files. +- Cut, copy, and paste text. +- Close files. + +## 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 editor.java + ``` +6. Run the compiled Java program using the following command: + ```bash + java editor + ``` + +## Usage + +- **Creating a New File**: Click on the "File" menu and select "New". +- **Opening an Existing File**: Click on the "File" menu and select "Open". +- **Saving a File**: Click on the "File" menu and select "Save". +- **Printing a File**: Click on the "File" menu and select "Print". +- **Editing Operations**: Use the "Edit" menu for cut, copy, and paste operations. +- **Cutting Text**: Select the text you want to cut, then click on the "Edit" menu and select "Cut". +- **Copying Text**: Select the text you want to copy, then click on the "Edit" menu and select "Copy". +- **Pasting Text**: Place the cursor where you want to paste the text, then click on the "Edit" menu and select "Paste". +- **Closing a File**: Click on the "File" menu and select "Close" to close the current file window. + +## Notes + +- This text editor supports editing multiple text files simultaneously. +- The application uses Java Swing for the graphical user interface. + From 358148a5bd6902b7001f0d8ea30418435f5ec689 Mon Sep 17 00:00:00 2001 From: Shubham25104 <117568702+Shubham25104@users.noreply.github.com> Date: Sat, 24 Feb 2024 13:59:12 +0530 Subject: [PATCH 02/10] Update README.md --- README.md | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a0c609..27cf3a9 100644 --- a/README.md +++ b/README.md @@ -1 +1,45 @@ -JAVA/CPP repo for OPENHACK. +# Simple Text Editor + +This is a simple text editor application created using Java Swing. + +## Features + +- Create new text files. +- Open existing text files. +- Save text files. +- Print text files. +- Cut, copy, and paste text. +- Close files. + +## 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 editor.java + ``` +6. Run the compiled Java program using the following command: + ```bash + java editor + ``` + +## Usage + +- **Creating a New File**: Click on the "File" menu and select "New". +- **Opening an Existing File**: Click on the "File" menu and select "Open". +- **Saving a File**: Click on the "File" menu and select "Save". +- **Printing a File**: Click on the "File" menu and select "Print". +- **Editing Operations**: Use the "Edit" menu for cut, copy, and paste operations. +- **Cutting Text**: Select the text you want to cut, then click on the "Edit" menu and select "Cut". +- **Copying Text**: Select the text you want to copy, then click on the "Edit" menu and select "Copy". +- **Pasting Text**: Place the cursor where you want to paste the text, then click on the "Edit" menu and select "Paste". +- **Closing a File**: Click on the "File" menu and select "Close" to close the current file window. + +## Notes + +- This text editor supports editing multiple text files simultaneously. +- The application uses Java Swing for the graphical user interface. + From 7dff2c071de5b6bba9a17ed2ba06a2be6aa1cf08 Mon Sep 17 00:00:00 2001 From: Shubham25104 <117568702+Shubham25104@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:30:01 +0530 Subject: [PATCH 03/10] Delete README.md --- README.md | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 27cf3a9..0000000 --- a/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Simple Text Editor - -This is a simple text editor application created using Java Swing. - -## Features - -- Create new text files. -- Open existing text files. -- Save text files. -- Print text files. -- Cut, copy, and paste text. -- Close files. - -## 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 editor.java - ``` -6. Run the compiled Java program using the following command: - ```bash - java editor - ``` - -## Usage - -- **Creating a New File**: Click on the "File" menu and select "New". -- **Opening an Existing File**: Click on the "File" menu and select "Open". -- **Saving a File**: Click on the "File" menu and select "Save". -- **Printing a File**: Click on the "File" menu and select "Print". -- **Editing Operations**: Use the "Edit" menu for cut, copy, and paste operations. -- **Cutting Text**: Select the text you want to cut, then click on the "Edit" menu and select "Cut". -- **Copying Text**: Select the text you want to copy, then click on the "Edit" menu and select "Copy". -- **Pasting Text**: Place the cursor where you want to paste the text, then click on the "Edit" menu and select "Paste". -- **Closing a File**: Click on the "File" menu and select "Close" to close the current file window. - -## Notes - -- This text editor supports editing multiple text files simultaneously. -- The application uses Java Swing for the graphical user interface. - From 5eb2bc76e6a269e8e7a5e255855b881f6cabd6c9 Mon Sep 17 00:00:00 2001 From: Shubham25104 <117568702+Shubham25104@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:31:02 +0530 Subject: [PATCH 04/10] Delete Texteditor.java --- Texteditor.java | 268 ------------------------------------------------ 1 file changed, 268 deletions(-) delete mode 100644 Texteditor.java diff --git a/Texteditor.java b/Texteditor.java deleted file mode 100644 index e60bece..0000000 --- a/Texteditor.java +++ /dev/null @@ -1,268 +0,0 @@ -// Java Program to create a text editor using java - -import javax.swing.*; -import java.io.*; -import java.awt.event.*; -import javax.swing.plaf.metal.*; - -class Texteditor extends JFrame implements ActionListener { - // Text component - - JTextArea t; - private JFrame[] frames; - private JTextArea[] textAreas; - private int numOpenFiles; - - // Frame - JFrame f; - - // Constructor - Texteditor() { - // Create a frame - f = new JFrame("editor"); - - try { - // Set metal look and feel - UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); - - // Set theme to ocean - MetalLookAndFeel.setCurrentTheme(new OceanTheme()); - } catch (Exception e) { - } - - // Text component - t = new JTextArea(); - // Initialize arrays - frames = new JFrame[10]; // Assuming a maximum of 10 open files - textAreas = new JTextArea[10]; - numOpenFiles = 0; - - // Create a menubar - JMenuBar mb = new JMenuBar(); - - // Create amenu for menu - JMenu m1 = new JMenu("File"); - - // Create menu items - JMenuItem mi1 = new JMenuItem("New"); - JMenuItem mi2 = new JMenuItem("Open"); - JMenuItem mi3 = new JMenuItem("Save"); - JMenuItem mi9 = new JMenuItem("Print"); - - // Add action listener - mi1.addActionListener(this); - mi2.addActionListener(this); - mi3.addActionListener(this); - mi9.addActionListener(this); - - m1.add(mi1); - m1.add(mi2); - m1.add(mi3); - m1.add(mi9); - - // Create amenu for menu - JMenu m2 = new JMenu("Edit"); - - // Create menu items - JMenuItem mi4 = new JMenuItem("cut"); - JMenuItem mi5 = new JMenuItem("copy"); - JMenuItem mi6 = new JMenuItem("paste"); - - // Add action listener - mi4.addActionListener(this); - mi5.addActionListener(this); - mi6.addActionListener(this); - - m2.add(mi4); - m2.add(mi5); - m2.add(mi6); - - JMenuItem mc = new JMenuItem("close"); - - mc.addActionListener(this); - - mb.add(m1); - mb.add(m2); - mb.add(mc); - - f.setJMenuBar(mb); - f.add(t); - f.setSize(500, 500); - f.show(); - } - - // If a button is pressed - public void actionPerformed(ActionEvent e) { - String s = e.getActionCommand(); - - if (s.equals("cut")) { - t.cut(); - } else if (s.equals("copy")) { - t.copy(); - } else if (s.equals("paste")) { - t.paste(); - } else if (s.equals("Save")) { - // Create an object of JFileChooser class - JFileChooser j = new JFileChooser("f:"); - - // Invoke the showsSaveDialog function to show the save dialog - int r = j.showSaveDialog(null); - - if (r == JFileChooser.APPROVE_OPTION) { - - // Set the label to the path of the selected directory - File fi = new File(j.getSelectedFile().getAbsolutePath()); - - try { - // Create a file writer - FileWriter wr = new FileWriter(fi, false); - - // Create buffered writer to write - BufferedWriter w = new BufferedWriter(wr); - - // Write - w.write(t.getText()); - - w.flush(); - w.close(); - } catch (Exception evt) { - JOptionPane.showMessageDialog(f, evt.getMessage()); - } - } // If the user cancelled the operation - else { - JOptionPane.showMessageDialog(f, "the user cancelled the operation"); - } - } else if (s.equals("Print")) { - try { - // print the file - t.print(); - } catch (Exception evt) { - JOptionPane.showMessageDialog(f, evt.getMessage()); - } - } else if (s.equals("Open")) { - // Create an object of JFileChooser class - JFileChooser j = new JFileChooser("f:"); - - // Invoke the showsOpenDialog function to show the save dialog - int r = j.showOpenDialog(null); - - // If the user selects a file - if (r == JFileChooser.APPROVE_OPTION) { - // Set the label to the path of the selected directory - File fi = new File(j.getSelectedFile().getAbsolutePath()); - - try { - // String - String s1 = "", sl = ""; - - // File reader - FileReader fr = new FileReader(fi); - - // Buffered reader - BufferedReader br = new BufferedReader(fr); - - // Initialize sl - sl = br.readLine(); - - // Take the input from the file - while ((s1 = br.readLine()) != null) { - sl = sl + "\n" + s1; - } - - // Set the text - t.setText(sl); - } catch (Exception evt) { - JOptionPane.showMessageDialog(f, evt.getMessage()); - } - } // If the user cancelled the operation - else { - JOptionPane.showMessageDialog(f, "the user cancelled the operation"); - } - } else if (s.equals("New")) { - t.setText(""); - createNewFile(); - } else if (s.equals("close")) { - f.setVisible(false); - } - } - - private void createNewFile() { - JFrame frame = new JFrame("Untitled-" + (numOpenFiles + 1)); - JTextArea textArea = new JTextArea(); - JScrollPane scrollPane = new JScrollPane(textArea); - frame.add(scrollPane); - - // Create a menubar - JMenuBar mb = new JMenuBar(); - - // Create a menu for File - JMenu m1 = new JMenu("File"); - - // Create menu items for File - JMenuItem mi1 = new JMenuItem("New"); - JMenuItem mi2 = new JMenuItem("Open"); - JMenuItem mi3 = new JMenuItem("Save"); - JMenuItem mi9 = new JMenuItem("Print"); - - // Add action listeners to menu items - mi1.addActionListener(this); - mi2.addActionListener(this); - mi3.addActionListener(this); - mi9.addActionListener(this); - - // Add menu items to the File menu - m1.add(mi1); - m1.add(mi2); - m1.add(mi3); - m1.add(mi9); - - // Create a menu for Edit - JMenu m2 = new JMenu("Edit"); - - // Create menu items for Edit - JMenuItem mi4 = new JMenuItem("cut"); - JMenuItem mi5 = new JMenuItem("copy"); - JMenuItem mi6 = new JMenuItem("paste"); - - // Add action listeners to menu items - mi4.addActionListener(this); - mi5.addActionListener(this); - mi6.addActionListener(this); - - // Add menu items to the Edit menu - m2.add(mi4); - m2.add(mi5); - m2.add(mi6); - - // Create a menu item for Close - JMenuItem mc = new JMenuItem("close"); - - // Add action listener to the Close menu item - mc.addActionListener(this); - - // Add File and Edit menus to the menubar - mb.add(m1); - mb.add(m2); - - // Add Close menu item to the menubar - mb.add(mc); - - // Set the menubar for the frame - frame.setJMenuBar(mb); - - // Set frame size and visibility - frame.setSize(500, 500); - frame.setVisible(true); - - // Store references to JFrame and JTextArea - frames[numOpenFiles] = frame; - textAreas[numOpenFiles] = textArea; - numOpenFiles++; -} - - - // Main class - public static void main(String args[]) { - Texteditor e = new Texteditor(); - } -} From 3c890bda2bf64de53729d3c639db3f45e90c20f3 Mon Sep 17 00:00:00 2001 From: Shubham25104 <117568702+Shubham25104@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:31:15 +0530 Subject: [PATCH 05/10] Delete readme.md --- readme.md | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 readme.md diff --git a/readme.md b/readme.md deleted file mode 100644 index df5d9d5..0000000 --- a/readme.md +++ /dev/null @@ -1,45 +0,0 @@ -# Simple Text Editor - -This is a simple text editor application created using Java Swing. - -## Features - -- Create new text files. -- Open existing text files. -- Save text files. -- Print text files. -- Cut, copy, and paste text. -- Close files. - -## 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 editor.java - ``` -6. Run the compiled Java program using the following command: - ```bash - java editor - ``` - -## Usage - -- **Creating a New File**: Click on the "File" menu and select "New". -- **Opening an Existing File**: Click on the "File" menu and select "Open". -- **Saving a File**: Click on the "File" menu and select "Save". -- **Printing a File**: Click on the "File" menu and select "Print". -- **Editing Operations**: Use the "Edit" menu for cut, copy, and paste operations. -- **Cutting Text**: Select the text you want to cut, then click on the "Edit" menu and select "Cut". -- **Copying Text**: Select the text you want to copy, then click on the "Edit" menu and select "Copy". -- **Pasting Text**: Place the cursor where you want to paste the text, then click on the "Edit" menu and select "Paste". -- **Closing a File**: Click on the "File" menu and select "Close" to close the current file window. - -## Notes - -- This text editor supports editing multiple text files simultaneously. -- The application uses Java Swing for the graphical user interface. - From a6e5f8591966755f7a91f047725b51712f3e4178 Mon Sep 17 00:00:00 2001 From: Shubham25104 <117568702+Shubham25104@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:44:05 +0530 Subject: [PATCH 06/10] Encoder Decoder Application #1 Encoder Decoder Application --- EncoderDecoder.java | 159 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 EncoderDecoder.java diff --git a/EncoderDecoder.java b/EncoderDecoder.java new file mode 100644 index 0000000..ad226ba --- /dev/null +++ b/EncoderDecoder.java @@ -0,0 +1,159 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.util.Base64; + +public class EncoderDecoder extends JFrame implements ActionListener { + private JTextArea inputTextArea, outputTextArea; + private JComboBox algorithmComboBox; + private JButton encodeButton, decodeButton; + + public EncoderDecoder() { + setTitle("Encoder Decoder"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(500, 300); + setLocationRelativeTo(null); + + JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BorderLayout()); + + 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"); + buttonPanel.add(encodeButton); + buttonPanel.add(decodeButton); + + 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); + + mainPanel.add(inputPanel, BorderLayout.NORTH); + mainPanel.add(outputPanel, BorderLayout.CENTER); + mainPanel.add(buttonPanel, BorderLayout.SOUTH); + mainPanel.add(algorithmPanel, BorderLayout.WEST); + + encodeButton.addActionListener(this); + decodeButton.addActionListener(this); + + add(mainPanel); + setVisible(true); + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == encodeButton) { + // Get selected algorithm + String selectedAlgorithm = (String) algorithmComboBox.getSelectedItem(); + // Encode input text + String encodedText = encode(inputTextArea.getText(), selectedAlgorithm); + // Display encoded text + outputTextArea.setText(encodedText); + } else if (e.getSource() == decodeButton) { + // Get selected algorithm + String selectedAlgorithm = (String) algorithmComboBox.getSelectedItem(); + // Decode input text + String decodedText = decode(inputTextArea.getText(), selectedAlgorithm); + // Display decoded text + outputTextArea.setText(decodedText); + } + } + + 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 (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 { + // 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); + } + + return encodedText.toString(); +} + + + private String decode(String input, String algorithm) { + StringBuilder decodedText = new StringBuilder(); + + 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'; + decodedText.append((char) (((c - base - shift + 26) % 26) + base)); + } else { + decodedText.append(c); + } + } + } else if (algorithm.equals("Base64 Encoding")) { + try { + byte[] decodedBytes = Base64.getDecoder().decode(input); + decodedText.append(new String(decodedBytes)); + } catch (IllegalArgumentException e) { + decodedText.append("Invalid Base64 encoded string."); + } + } 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); + } + + return decodedText.toString(); +} + + + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> new EncoderDecoder()); + } +} From a0f77491f17b1405ba3897962e5fc7649a837f7f Mon Sep 17 00:00:00 2001 From: Shubham25104 <117568702+Shubham25104@users.noreply.github.com> Date: Sat, 24 Feb 2024 17:06:29 +0530 Subject: [PATCH 07/10] Add files via upload --- readme.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 readme.md diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..4f2c709 --- /dev/null +++ b/readme.md @@ -0,0 +1,42 @@ +# Encoder Decoder Application + +The Encoder Decoder application is a Java program with a graphical user interface (GUI) that allows users to encode plaintext messages into ciphertext and decode ciphertext back into plaintext using various encoding algorithms. + +## Features + +- Encode plaintext messages into ciphertext using different encoding algorithms. +- Decode ciphertext back into plaintext. +- Support for multiple encoding algorithms such as Caesar cipher, Base64 encoding, and custom substitution ciphers. +- User-friendly graphical interface for inputting messages, selecting encoding algorithms, and viewing the encoded or decoded output. + +## 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 + ``` + +## Usage + +**Input Message:** Enter the message you want to encode/decode into the input text area. +**Select Algorithm:** Choose the encoding algorithm from the dropdown menu. +**Encode:** Click the "Encode" button to encode the input message using the selected algorithm. +**Decode:** Click the "Decode" button to decode the input message using the selected algorithm. +**Output Message:** View the encoded or decoded message in the output text area. + +## Supported Algorithms +**Caesar Cipher:** Shifts each letter in the message by a fixed number of positions. +**Base64 Encoding:** Converts binary data into ASCII text format. +## Notes + + +- The application uses Java Swing for the graphical user interface. + From 3377d11db3e38aec453f7c92460f686a172afa84 Mon Sep 17 00:00:00 2001 From: Shubham25104 <117568702+Shubham25104@users.noreply.github.com> Date: Sat, 24 Feb 2024 17:40:18 +0530 Subject: [PATCH 08/10] Update readme.md --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 4f2c709..fffc89f 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,4 @@ +![E D](https://github.com/Shubham25104/OH24-CPP-Java/assets/117568702/80e98f33-e877-4cd0-b7b8-1b0d4b87162a) # Encoder Decoder Application The Encoder Decoder application is a Java program with a graphical user interface (GUI) that allows users to encode plaintext messages into ciphertext and decode ciphertext back into plaintext using various encoding algorithms. From b5b6986297935d02df6dd3690cdf199ae59a8b9c Mon Sep 17 00:00:00 2001 From: Shubham25104 <117568702+Shubham25104@users.noreply.github.com> Date: Sun, 20 Apr 2025 16:58:54 +0530 Subject: [PATCH 09/10] Create gradle-publish.yml --- .github/workflows/gradle-publish.yml | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/gradle-publish.yml diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml new file mode 100644 index 0000000..20d17dc --- /dev/null +++ b/.github/workflows/gradle-publish.yml @@ -0,0 +1,44 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle + +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: Build with Gradle + run: ./gradlew build + + # 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 }} From 9207ae2318a59c3149e7bc32bf9da3a2796e16cd Mon Sep 17 00:00:00 2001 From: Shubham25104 <117568702+Shubham25104@users.noreply.github.com> Date: Sun, 20 Apr 2025 11:35:44 +0000 Subject: [PATCH 10/10] revert some changes --- .github/workflows/gradle-publish.yml | 44 ---------------------------- 1 file changed, 44 deletions(-) delete mode 100644 .github/workflows/gradle-publish.yml diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml deleted file mode 100644 index 20d17dc..0000000 --- a/.github/workflows/gradle-publish.yml +++ /dev/null @@ -1,44 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle - -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: Build with Gradle - run: ./gradlew build - - # 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 }}