LAMPIRAN A : LISTING PROGRAM
1. Form Home(FormImage.java)
/** To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * and open the template in the editor.
*/
package cryptoimage; import java.awt.Toolkit;
import java.awt.event.WindowEvent; import javax.swing.JFrame;
/** *
* @author hyunsang */
public class FormImage extends javax.swing.JFrame { /**
* Creates new form FormImage */
//FormImage page;
public FormImage() { initComponents(); }
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor. */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
menuHome = new javax.swing.JMenu(); menuProg = new javax.swing.JMenu(); menuHelp = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CL OSE);
setBackground(new java.awt.Color(255, 250, 250)); setPreferredSize(new java.awt.Dimension(921, 386)); jLabel1.setIcon(new
javax.swing.ImageIcon("/home/hyunsang/NetBeansProjects/CryptoIm age/lg.png")); // NOI18N
jLabel1.setText("jLabel1"); jLabel2.setIcon(new
javax.swing.ImageIcon("/home/hyunsang/NetBeansProjects/CryptoIm age/logo.png")); // NOI18N
jLabel2.setVerifyInputWhenFocusTarget(false);
jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
jLabel3.setText("SKRIPSI");
jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
jLabel4.setText("IMPLEMENTASI ALGORITMA ADVANCED ENCRYPTION STANDARD (AES) ");
jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
jLabel5.setText("UNTUK MENGAMANKAN FILE GAMBAR");
jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
jLabel6.setText("NURUL PUTRI YANTI");
jLabel7.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
jLabel7.setText("111401076");
jLabel8.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
jLabel8.setText("PROGRAM STUDI S1 ILMU KOMPUTER"); jLabel9.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
jLabel9.setText("FAKULTAS ILMU KOMPUTER DAN TEKNOLOGI INFORMASI");
jLabel10.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
jLabel10.setText("UNIVERSITAS SUMATERA UTARA");
jLabel11.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
jLabel12.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
jLabel12.setText("2015"); jMenuBar1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenuBar1MouseClicked(evt); }
});
menuHome.setBorder(javax.swing.BorderFactory.createLineBorder(n ew java.awt.Color(245, 243, 243), 2));
menuHome.setText("Home");
menuHome.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
menuHomeMouseClicked(evt); }
});
jMenuBar1.add(menuHome);
menuProg.setBorder(javax.swing.BorderFactory.createLineBorder(n ew java.awt.Color(245, 243, 243), 2));
menuProg.setText("Program");
menuProg.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
menuProgMouseClicked(evt); }
});
jMenuBar1.add(menuProg);
menuHelp.setBorder(javax.swing.BorderFactory.createLineBorder(n ew java.awt.Color(245, 243, 243), 2));
menuHelp.setText("Help");
menuHelp.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
menuHelpMouseClicked(evt); }
});
jMenuBar1.add(menuHelp); setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
.addGap(101, 101, 101)
.addGroup(layout.createParallelGro up(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLay out.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel4) .addGap(18, 18, 18))
.addGroup(javax.swing.GroupLay out.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createPar allelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel8) .addComponent(jLabel5)) .addGap(126, 126, 126)))) .addGroup(javax.swing.GroupLayout.Alig nment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGro up(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLay out.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel3) .addGap(240, 240, 240)) .addGroup(javax.swing.GroupLay out.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel6) .addGap(196, 196, 196)) .addGroup(javax.swing.GroupLay out.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel7) .addGap(234, 234, 234))))) .addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup() .addGap(257, 257, 257)
.addComponent(jLabel2))
.addGroup(layout.createSequentialGroup() .addGap(155, 155, 155)
.addGroup(layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addGroup(layout.createSequentialGroup ()
.addGap(89, 89, 89)
.addComponent(jLabel10)))) .addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup ()
.addGap(12, 12, 12) .addComponent(jLabel12)) .addComponent(jLabel11))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE))
); .addGap(33, 33, 33)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup() .addGap(50, 50, 50)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.C omponentPlacement.RELATED)
.addComponent(jLabel5) .addGap(18, 18, 18) .addComponent(jLabel3) .addGap(18, 18, 18) .addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.C omponentPlacement.RELATED)
.addComponent(jLabel7) .addGap(26, 26, 26) .addComponent(jLabel2))) .addGap(18, 18, 18)
.addComponent(jLabel8) IZE, Short.MAX_VALUE))
); pack();
private void jMenuBar1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here: //dispose();
}
private void menuHomeMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here: }
private void menuProgMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here: dispose();
Framee page2 = new Framee(); page2.setVisible(true);
page2.setLocationRelativeTo(null); }
private void menuHelpMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here: dispose();
HelpFrame page3 = new HelpFrame(); page3.setVisible(true);
page3.setLocationRelativeTo(null); }
/**
* @param args the command line arguments */
public static void main(String args[]) { /* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/ plaf.html
*/ try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName()); break;
} }
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FormImage.class.getName()).l og(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(FormImage.class.getName()).l og(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FormImage.class.getName()).l og(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(FormImage.class.getName()).l og(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
FormImage f = new FormImage(); f.setVisible(true);
f.setSize(710, 700);
f.setLocationRelativeTo(null); }
}); }
// Variables declaration - do not modify private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenu menuHelp; private javax.swing.JMenu menuHome; private javax.swing.JMenu menuProg; // End of variables declaration }
2. Form Program (Framee.java)
/** To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * and open the template in the editor.
*/
package cryptoimage;
import java.awt.image.BufferedImage;
import java.util.Random; import javax.swing.*; import java.io.*;
import java.security.Key;
import java.security.SecureRandom; import java.text.DecimalFormat; import java.text.NumberFormat; import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec; import javax.imageio.ImageIO;
/** *
* @author hyunsang */
public class Framee extends javax.swing.JFrame { /**
* Creates new form Framee */
public Framee() { initComponents(); }
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor. */
@SuppressWarnings("unchecked") JLabel jlab = new JLabel (); JLabel jEnc = new JLabel (); JLabel jDec = new JLabel ();
BufferedImage image,encImage,decImage,normalImage,NormalImage; int width;
int height;
public String dataAwal="",dataAkhir="";
byte[] encVal,decVal,val,Pix,tempEnc,tempDec; byte ImagePix[],pixels[],acak[];
int A[] , tempKey; byte RandomNumber[] ; File out,output;
String namaFile,set,namEnc,namDec,K; int setNum = 0;
SecureRandom random ;
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
ButDec = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); valKey = new javax.swing.JTextField();
jDesktopPane1 = new javax.swing.JDesktopPane(); encTime = new javax.swing.JTextField();
decTime = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jMenuBar1 = new javax.swing.JMenuBar(); menu1 = new javax.swing.JMenu();
menu2 = new javax.swing.JMenu(); menu3 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CL OSE);
setBackground(new java.awt.Color(248, 244, 244)); setForeground(java.awt.Color.white);
ButFile.setText("BROWSE"); ButFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButFileActionPerformed(evt); }
});
jLabel1.setBackground(new java.awt.Color(225, 88, 88)); jLabel1.setForeground(new java.awt.Color(33, 38, 208)); jLabel1.setText("NORMAL IMAGE");
ButEnc.setText("ENCRYPT"); ButEnc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButEncActionPerformed(evt); }
});
ButDec.setText("DECRYPT"); ButDec.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButDecActionPerformed(evt); }
});
jLabel2.setForeground(new java.awt.Color(13, 45, 238)); jLabel2.setText("ENCRYPT IMAGE");
jLabel3.setForeground(new java.awt.Color(32, 13, 223)); jLabel3.setText("DECRYPT IMAGE");
jLabel4.setText("KEY LENGTH :");
jLabel5.setBackground(new java.awt.Color(32, 76, 248)); jLabel5.setForeground(new java.awt.Color(30, 55, 222)); jLabel5.setText("ENCRYPT TIME :");
jLabel6.setForeground(new java.awt.Color(23, 19, 248)); jLabel6.setText("DECRYPT TIME");
menu1.setText("Home");
menu1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) {
menu1MouseClicked(evt); }
});
jMenuBar1.add(menu1); menu2.setText("Program");
menu2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) {
menu2MouseClicked(evt); }
});
jMenuBar1.add(menu2); menu3.setText("Help");
menu3.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) {
menu3MouseClicked(evt); }
});
jMenuBar1.add(menu3); setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGap(63, 63, 63)
.addComponent(ButFile, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(162, 162, 162) .addComponent(ButEnc, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ButDec, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup() .addGap(68, 68, 68)
.addComponent(jLabel1) .addGap(153, 153, 153) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(132, 132, 132) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup() .addContainerGap()
.addComponent(Pane,
javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(35, 35, 35) .addComponent(PANEE,
javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(37, 37, 37) .addComponent(PANED,
javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.C omponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.C omponentPlacement.RELATED, 15, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax. javax.swing.GroupLayout.PREFERRED_SIZE, 118,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(encTime, javax.swing.GroupLayout.PREFERRED_SIZE, 118,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 45, Short.MAX_VALUE)))) ); .addGap(77, 77, 77)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax. .addGap(17, 17, 17)
.addComponent(encTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.C omponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel6) .addGap(30, 30, 30) .addComponent(decTime, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.D EFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
.addComponent(Pane, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(PANEE, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(PANED, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
.addGroup(layout.createParallelGroup(javax.swi ng.GroupLayout.Alignment.BASELINE)
.addComponent(ButEnc) .addComponent(ButDec)) .addComponent(ButFile, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap())
); pack();
}// </editor-fold>
private void ButFileActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: //try{
if(valKey.getText().equals("128") || valKey.getText().equals("192") ||
valKey.getText().equals("256")){
//if((tempKey/8) == 16 || (tempKey/8) == 24 || (tempKey/8) == 32){
JFileChooser s = new JFileChooser (); if (s.showOpenDialog(ButFile) == JFileChooser.APPROVE_OPTION){
File f = s.getSelectedFile(); try{
image = ImageIO.read(f); namaFile = f.getName(); }
catch(Exception e){ }
jlab.setIcon(new ImageIcon(f.toString())); jlab.setHorizontalAlignment(JLabel.CENTER); Pane.getViewport().add(jlab);
}
//catch(Exception e) {
}
//NormalImage = ImageIO.read(f); else{
JOptionPane.showMessageDialog(null,"Key doesn't Match,Please Write 128 ,192 or 256");
} }
public void generateKey(){ K = valKey.getText();
tempKey = Integer.parseInt(K); this.random = new SecureRandom(); this.acak = new byte[tempKey/8]; random.nextBytes(acak);
}
public void getPixel() { generateKey();
try{
width = 0; height = 0;
set = Integer.toString(setNum); setNum++;
//File input = new File("T.jpg"); //image = ImageIO.read(input); width += image.getWidth(); height += image.getHeight(); //System.out.println(width); //System.out.println(height); int index = width*height; int count = 0;
this.pixels = new byte[width*height]; this.A = new int[width*height];
this.ImagePix = new byte [width*height]; //A = null;
//ImagePix = null; //pixels = null;
//byte[] DataImage = new byte[width*height]; try{
for (int i=0 ; i<width; i++){ for (int j=0; j<height; j++){
//A[count]=0;
A[count]=((image.getRGB(i, j)) / 256); //pixels[count] = 0;
pixels[count] =(byte) image.getRGB(i, j); //ImagePix[count] = 0;
ImagePix[count] = pixels[count]; //System.out.println(A[count]+" = "+ImagePix[count]);
//dataAwal += Integer.toString(pixels[count]);
} } }
catch(Exception e){
System.out.println("For Salah"); System.out.println(e.getMessage()); }
System.out.println("Pengambilan Nilai Pixel Berhasil Alhamdulillah");
}
catch (Exception e){
System.out.println("Ini Salah"); System.out.println(e.getMessage()); }
}
public void encrypt () throws Exception{ getPixel();
//encVal = {(byte) 0}; namEnc = "Enc-"+set+".jpg"; try{
long start = System.currentTimeMillis(); byte k[]=acak;
String algo = "AES";
output = new File (namEnc); output.createNewFile();
//File normal = new File ("Normal.jpg"); encImage = new BufferedImage (width, height,TYPE_INT_RGB);
normalImage = new BufferedImage (width, height,TYPE_INT_RGB);
Key key = new SecretKeySpec (k, algo); Cipher c = Cipher.getInstance(algo); c.init(Cipher.ENCRYPT_MODE, key);
int index =0; try{
//val = Pix;
encVal = c.doFinal(ImagePix);
System.out.println("Encval did work"); }
catch(Exception q){
System.out.println(q.getMessage());
System.out.println("Encval didi not work"); }
try{
//System.out.println("Encval ke-"+index+" = "+encVal[index]);
//normalImage.setRGB(x, y, ImagePix[index]); //tempEnc[index] = 0;
//tempEnc[index] += encVal[index]; //encVal[index] = 0;
encImage.setRGB(x, y, encVal[index]); index++;
} }
System.out.println("Pass"); }
catch(Exception e){
System.out.println(e.getMessage());
System.out.println("Sepertinya For Salah"); }
try{
ImageIO.write(encImage, "JPG", output); long end = System.currentTimeMillis();
NumberFormat time = new DecimalFormat("#0.00000"); long t = end-start;
encTime.setText(String.valueOf(t/1000d)+" second"); System.out.print("Execution time is
"+time.format((end-start)/1000d)+"seconds");
//JOptionPane.showMessageDialog(null,"Enkripsi Berhasil ");
System.out.println("Gambar Enkripsi Selesai"); }
catch (Exception e){
System.out.println(e.getMessage());
System.out.println("Gambar Enkripsi tidak bisa Dicetak");
} /*try{
ImageIO.write(normalImage, "JPG", normal); System.out.println("Gambar Normal Selesai"); }
catch (Exception e){
System.out.println(e.getMessage());
System.out.println("Gambar Normal Tidak Bisa Dicetak");
}*/ }
catch (Exception e){
System.out.println(e.getMessage());
System.out.println("Enkripsi tidak bisa"); }
}
public void decrypt() throws Exception { namDec = "Dec-"+set+".jpg";
long first = System.currentTimeMillis(); byte k[]=acak;
int DecVal[] = new int[width*height]; String algo = "AES";
decImage = new BufferedImage (width, height,TYPE_INT_RGB);
Key key = new SecretKeySpec (k, algo); Cipher c = Cipher.getInstance(algo); c.init(Cipher.DECRYPT_MODE, key); int in =0;
decVal = c.doFinal(encVal); for (int x = 0; x<width; x++){
for (int y=0 ; y<height ; y++){ //System.out.println(decVal[in]); //String tex;
// tex = new String(decVal[in]); //dataAkhir += tex;
//tempDec[in] = 0;
//tempDec[in] += decVal[in]; //DecVal[in] += 0;
DecVal[in] = ((A[in]*256) + decVal[in]); decImage.setRGB(x, y, DecVal[in]);
in++; } }
out = new File(namDec); out.createNewFile();
ImageIO.write(decImage, "JPG", out); long last = System.currentTimeMillis();
NumberFormat time = new DecimalFormat("#0.00000"); long ti = last-first;
decTime.setText(String.valueOf(ti/1000d)+" second"); System.out.print("Execution time is
"+time.format((last-first)/1000d)+"seconds");
System.out.println("Gambar Dekripsi Selesai"); }
catch(Exception ex){
System.out.println(ex.getMessage());
System.out.println("Gambar Dekripsi tidak bisa Dicetak");
} }
private void ButEncActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: try{
encrypt(); }
jEnc.setIcon(new ImageIcon(output.toString())); jEnc.setHorizontalAlignment(JLabel.CENTER); PANEE.getViewport().add(jEnc);
}
private void ButDecActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: try{
decrypt(); }
catch(Exception e){ }
jDec.setIcon(new ImageIcon(out.toString())); jDec.setHorizontalAlignment(JLabel.CENTER); PANED.getViewport().add(jDec);
}
private void menu1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here: dispose();
FormImage HomePage = new FormImage(); HomePage.setVisible(true);
HomePage.setSize(710, 700);
HomePage.setLocationRelativeTo(null); setNum = 0;
//FormImage HomePage = new FormImage(); //HomePage.show();
}
private void menu2MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here: //Framee programPage = new Framee(); //programPage.show();
}
private void menu3MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here: dispose();
HelpFrame helpPage = new HelpFrame(); helpPage.setVisible(true);
helpPage.setLocationRelativeTo(null); setNum = 0;
} /**
* @param args the command line arguments */
public static void main(String args[]) { /* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/ plaf.html
*/ try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName()); break;
} }
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Framee.class.getName()).log( java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Framee.class.getName()).log( java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Framee.class.getName()).log( java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Framee.class.getName()).log( java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
new Framee().setVisible(true); }
}); }
// Variables declaration - do not modify private javax.swing.JButton ButDec; private javax.swing.JButton ButEnc; private javax.swing.JButton ButFile; public javax.swing.JScrollPane PANED; public javax.swing.JScrollPane PANEE; public javax.swing.JScrollPane Pane; private javax.swing.JTextField decTime; private javax.swing.JTextField encTime;
private javax.swing.JDesktopPane jDesktopPane1; private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenu menu1;
private javax.swing.JMenu menu3;
private javax.swing.JTextField valKey; // End of variables declaration
}
3. Form Help (HelpFrame.java)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * and open the template in the editor.
*/
package cryptoimage;
/** *
* @author hyunsang */
public class HelpFrame extends javax.swing.JFrame {
/**
* Creates new form HelpFrame */
public HelpFrame() { initComponents(); }
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor. */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel();
jTextField7 = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton();
jTextField9 = new javax.swing.JTextField(); jTextField10 = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jButton3 = new javax.swing.JButton();
jTextField11 = new javax.swing.JTextField(); jMenuBar1 = new javax.swing.JMenuBar(); Home = new javax.swing.JMenu();
Program = new javax.swing.JMenu(); Help = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON _CLOSE);
jLabel1.setBackground(new java.awt.Color(255, 245, 245));
jLabel1.setFont(new java.awt.Font("Courier 10 Pitch", 0, 14)); // NOI18N
jLabel1.setText("PROSEDUR PENGGUNAAN HALAMAN PROGRAM :");
jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder (new java.awt.Color(108, 120, 193), 3));
jTextField1.setText("1. Klik Tombol Browse, Lalu Pilih Gambar yang akan Dienkripsi ");
jTextField2.setText("2. Gambar yang dipilih akan tampil di layar");
jTextField3.setText("3. Ketikkan besar kunci yang akan digunakan");
jTextField4.setText("4. Klik Tombol Encrypt untuk mengubah gambar menjadi sandi gambar");
jTextField5.setText("5. Sandi gambar hasil enkripsi akan muncul di layar ");
jTextField6.setText("6. Klik Tombol Decrypt untuk mengubah sandi gambar menjadi gambar asli");
jTextField7.addActionListener(new java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent evt) { jTextField7ActionPerformed(evt); }
});
jLabel2.setFont(new java.awt.Font("Courier New", 0, 12)); // NOI18N
jLabel2.setText("PROSEDUR PENGGUNAAN HALAMAN UTAMA :");
jLabel2.setBorder(javax.swing.BorderFactory.createLineBorder (new java.awt.Color(108, 120, 193), 3));
jButton1.setText("PROGRAM");
jButton2.setText("HELP");
jButton2.setPreferredSize(new java.awt.Dimension(72, 29));
jTextField9.setText("Menu untuk menampilkan halaman program");
jTextField10.setText("Menu untuk menampilkan halaman help");
jLabel3.setFont(new java.awt.Font("Courier New", 0, 14)); // NOI18N
jLabel3.setText("PROSEDUR PENGGUNAAN HALAMAN HELP :");
jLabel3.setBorder(javax.swing.BorderFactory.createLineBorder (new java.awt.Color(108, 120, 193), 3));
jTextArea1.setColumns(20); jTextArea1.setRows(5);
jTextArea1.setText("Halaman Ini menampilkan prosedur penggunaan setiap halaman yang terdapat\ndi dalam program ini, yaitu Home, Program dan Help.\n");
jScrollPane2.setViewportView(jTextArea1);
jButton3.setText("HOME");
jButton3.setPreferredSize(new java.awt.Dimension(72, 29));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Al ignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap()
.addComponent(jLabel2))
.addGroup(jPanel1Layout.createSequentialGroup() .addGap(40, 40, 40)
.addGroup(jPanel1Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton3,
javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE) .addComponent(jButton1,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton2,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createParallelGr oup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField9) .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, 297,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2)
.addGroup(jPanel1Layout.createSequential Group()
.addGroup(jPanel1Layout.createParall elGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createPa rallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jTextField6) .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField3, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField4) .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField5) .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 478,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel3)) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Al ignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAI LING, jPanel1Layout.createSequentialGroup()
.addGap(49, 49, 49) .addComponent(jLabel2) .addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jTextField11))
.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1) .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.RELATED)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.RELATED)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.RELATED)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.RELATED)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.RELATED)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.RELATED)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.RELATED, 43, Short.MAX_VALUE)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.Com ponentPlacement.UNRELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(22, 22, 22)) );
Home.addMouseListener(new java.awt.event.MouseAdapter() {
public void
mouseClicked(java.awt.event.MouseEvent evt) { HomeMouseClicked(evt);
} });
jMenuBar1.add(Home);
Program.setText("Program"); Program.addMouseListener(new java.awt.event.MouseAdapter() {
public void
mouseClicked(java.awt.event.MouseEvent evt) { ProgramMouseClicked(evt); }
});
jMenuBar1.add(Program);
Help.setText("Help"); Help.addMouseListener(new java.awt.event.MouseAdapter() {
public void
mouseClicked(java.awt.event.MouseEvent evt) { HelpMouseClicked(evt);
} });
jMenuBar1.add(Help);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment. LEADING)
.addGroup(layout.createSequentialGroup() .addComponent(jPanel1,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 44, Short.MAX_VALUE)) );
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment. LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())
);
pack();
}// </editor-fold>
private void
jTextField7ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
}
private void HomeMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here: dispose();
FormImage Home = new FormImage(); Home.setVisible(true);
Home.setSize(710, 700);
Home.setLocationRelativeTo(null); //FormImage Home = new FormImage(); //Home.show();
}
private void
ProgramMouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here:
dispose();
Framee Program = new Framee();
Program.setLocationRelativeTo(null); Program.setVisible(true);
}
private void HelpMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here: // HelpFrame Help = new HelpFrame();
//Help.show(); }
/**
* @param args the command line arguments */
public static void main(String args[]) { /* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfe el/plaf.html
*/ try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName()); break;
} }
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(HelpFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(HelpFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(HelpFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(HelpFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
new HelpFrame().setVisible(true); }
}); }
// Variables declaration - do not modify private javax.swing.JMenu Help;
private javax.swing.JMenuBar jMenuBar1; private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField10; private javax.swing.JTextField jTextField11; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField5; private javax.swing.JTextField jTextField6; private javax.swing.JTextField jTextField7; private javax.swing.JTextField jTextField9; // End of variables declaration