Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java code for image encryption & decryption

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import java.awt.Font;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class ImageOperation {

    public static void operate(int key)
    {

        JFileChooser fileChooser=new JFileChooser();
        fileChooser.showOpenDialog(null);
        File file=fileChooser.getSelectedFile();
        //file FileInputStream
        try
        {

            FileInputStream fis=new FileInputStream(file);

            byte []data=new byte[fis.available()];
            fis.read(data);
            int i=0;
            for(byte b:data)
            {
                System.out.println(b);
                data[i]=(byte)(b^key);
                i++;
            }

            FileOutputStream fos=new FileOutputStream(file);
            fos.write(data);
            fos.close();
            fis.close();
            JOptionPane.showMessageDialog(null, "Done");

        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        
        System.out.println("this is testing");

        JFrame f=new JFrame();
        f.setTitle("Image Operation");
        f.setSize(400,400);
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Font font=new Font("Roboto",Font.BOLD,25);
        //creating button
        JButton button=new JButton();
        button.setText("Open Image");
        button.setFont(font);

        //creating text field

        JTextField textField=new JTextField(10);
        textField.setFont(font);

        
        button.addActionListener(e->{
            System.out.println("button clicked");
            String text=textField.getText();
            int temp=Integer.parseInt(text);
            operate(temp);
        });

        f.setLayout(new FlowLayout());

        f.add(button);
        f.add(textField);
        f.setVisible(true);

    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: zebra zpl print java 
Java :: Java 8 merge multiple collections. 
Java :: Class inheritance and encapsulation 
Java :: how to wirte an XPlane Plugin 
Java :: codding loop 
Java :: ggt euklidischer algorithmus java 
Java :: v2ray 
Java :: using ..replace() in jShell/java 
Java :: Accept Integer only in if else statement 
Java :: mostrar divisores java 
Java :: java scanner use all symbols as delimiter 
Java :: implicit type casting in java 
Java :: Fomating .json 
Java :: franchiseRulesTemp 
Java :: how to return custom value in api spring boot 
Java :: Java Method for Code Reusability 
Java :: converting temperature from fahrenheit to celsius 
Java :: Java Constructor invocations 
Java :: buat tetris dari java 
Java :: barcode design in postgresql 
Java :: @Controller 
Java :: Removing Elements in java map 
Java :: create generator hibernate 
Java :: on offline event spigot example 
Java :: Static And Public Methods 
Java :: unmappable character java 
Java :: compiling and running program in terminal 
Java :: adding Executable Jars to Spring Maven Project 
Java :: programically set data source properties in spring 
Java :: Lists - removing with iterator 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =