Implementasi Algoritma Advanced Encryption Standard (AES) untuk Mengamankan File Gambar
A-1
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")
//
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
A-2
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
jLabel11.setText("MEDAN");
A-3
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());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
A-4
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G
roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup
()
.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()
.addGap(327, 327, 327)
A-5
.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))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G
roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.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)
.addPreferredGap(javax.swing.LayoutStyle.Component
Placement.RELATED)
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.Component
Placement.RELATED)
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.Component
Placement.RELATED)
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.Component
Placement.RELATED)
.addComponent(jLabel12)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S
IZE, Short.MAX_VALUE))
);
pack();
}//
A-6
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 */
//
/* 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);
} catch (InstantiationException ex) {
A-7
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);
}
//
/* 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 static java.awt.image.BufferedImage.TYPE_INT_RGB;
A-8
import
import
import
import
import
import
import
import
import
import
java.util.Random;
javax.swing.*;
java.io.*;
java.security.Key;
java.security.SecureRandom;
java.text.DecimalFormat;
java.text.NumberFormat;
javax.crypto.Cipher;
javax.crypto.spec.SecretKeySpec;
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 ;
//
private void initComponents() {
ButFile = new javax.swing.JButton();
Pane = new javax.swing.JScrollPane();
jLabel1 = new javax.swing.JLabel();
PANEE = new javax.swing.JScrollPane();
PANED = new javax.swing.JScrollPane();
ButEnc = new javax.swing.JButton();
A-9
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.setForeground(new java.awt.Color(36, 7, 244));
A-10
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)
.addGap(169, 169, 169)
A-11
.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.
swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addGroup(layout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(decTime,
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(jLabel5)
.addComponent(valKey,
javax.swing.GroupLayout.PREFERRED_SIZE, 114,
javax.swing.GroupLayout.PREFERRED_SIZE)
A-12
.addComponent(jLabel4,
javax.swing.GroupLayout.PREFERRED_SIZE, 94,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 45, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G
roupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGap(77, 77, 77)
.addComponent(jLabel4,
javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.C
omponentPlacement.RELATED)
.addComponent(valKey,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.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(jLabel2,
javax.swing.GroupLayout.PREFERRED_SIZE, 15,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.C
omponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING)
A-13
.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();
}//
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) {
//JOptionPane.showMessageDialog(null,"Key doesn't
Match,Please Write 128 ,192 or 256");
A-14
}
//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
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")
//
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
A-2
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
jLabel11.setText("MEDAN");
A-3
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());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
A-4
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G
roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup
()
.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()
.addGap(327, 327, 327)
A-5
.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))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G
roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.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)
.addPreferredGap(javax.swing.LayoutStyle.Component
Placement.RELATED)
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.Component
Placement.RELATED)
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.Component
Placement.RELATED)
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.Component
Placement.RELATED)
.addComponent(jLabel12)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S
IZE, Short.MAX_VALUE))
);
pack();
}//
A-6
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 */
//
/* 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);
} catch (InstantiationException ex) {
A-7
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);
}
//
/* 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 static java.awt.image.BufferedImage.TYPE_INT_RGB;
A-8
import
import
import
import
import
import
import
import
import
import
java.util.Random;
javax.swing.*;
java.io.*;
java.security.Key;
java.security.SecureRandom;
java.text.DecimalFormat;
java.text.NumberFormat;
javax.crypto.Cipher;
javax.crypto.spec.SecretKeySpec;
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 ;
//
private void initComponents() {
ButFile = new javax.swing.JButton();
Pane = new javax.swing.JScrollPane();
jLabel1 = new javax.swing.JLabel();
PANEE = new javax.swing.JScrollPane();
PANED = new javax.swing.JScrollPane();
ButEnc = new javax.swing.JButton();
A-9
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.setForeground(new java.awt.Color(36, 7, 244));
A-10
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)
.addGap(169, 169, 169)
A-11
.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.
swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addGroup(layout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(decTime,
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(jLabel5)
.addComponent(valKey,
javax.swing.GroupLayout.PREFERRED_SIZE, 114,
javax.swing.GroupLayout.PREFERRED_SIZE)
A-12
.addComponent(jLabel4,
javax.swing.GroupLayout.PREFERRED_SIZE, 94,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 45, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G
roupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGap(77, 77, 77)
.addComponent(jLabel4,
javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.C
omponentPlacement.RELATED)
.addComponent(valKey,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.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(jLabel2,
javax.swing.GroupLayout.PREFERRED_SIZE, 15,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.C
omponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING)
A-13
.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();
}//
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) {
//JOptionPane.showMessageDialog(null,"Key doesn't
Match,Please Write 128 ,192 or 256");
A-14
}
//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