A-7
java.util.loooino.Loooer.oetLoooerFormImaoe.class.oetName.l oojava.util.loooino.Level.SEVERE, null, ex;
} catch IlleoalAccessException ex { java.util.loooino.Loooer.oetLoooerFormImaoe.class.oetName.l
oojava.util.loooino.Level.SEVERE, null, ex; } catch javax.swino.UnsupportedLookAndFeelException ex {
java.util.loooino.Loooer.oetLoooerFormImaoe.class.oetName.l oojava.util.loooino.Level.SEVERE, null, ex;
} editor-fold
Create and display the form java.awt.EventQueue.invokeLaternew Runnable {
public void run { FormImaoe f = new FormImaoe;
f.setVisibletrue; f.setSize710, 700;
f.setLocationRelativeTonull; }
}; }
Variables declaration - do not modify private javax.swino.JLabel jLabel1;
private javax.swino.JLabel jLabel10; private javax.swino.JLabel jLabel11;
private javax.swino.JLabel jLabel12; private javax.swino.JLabel jLabel2;
private javax.swino.JLabel jLabel3; private javax.swino.JLabel jLabel4;
private javax.swino.JLabel jLabel5; private javax.swino.JLabel jLabel6;
private javax.swino.JLabel jLabel7; private javax.swino.JLabel jLabel8;
private javax.swino.JLabel jLabel9; private javax.swino.JMenuBar jMenuBar1;
private javax.swino.JMenu menuHelp; private javax.swino.JMenu menuHome;
private javax.swino.JMenu menuProo; End of variables declaration
}
2. Form Program Framee.java
To chanoe this license header, choose License Headers in Project Properties.
To chanoe this template file, choose Tools | Templates and open the template in the editor.
packaoe cryptoimaoe; import java.awt.imaoe.BufferedImaoe;
import static java.awt.imaoe.BufferedImaoe.TYPE_INT_RGB;
A-8
import java.util.Random; import javax.swino.;
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.imaoeio.ImaoeIO;
author hyunsano public class Framee extends javax.swino.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
reoenerated by the Form Editor. SuppressWarninosunchecked
JLabel jlab = new JLabel ; JLabel jEnc = new JLabel ;
JLabel jDec = new JLabel ; BufferedImaoe imaoe,encImaoe,decImaoe,normalImaoe,NormalImaoe;
int width; int heioht;
public Strino dataAwal=,dataAkhir=; byte[] encVal,decVal,val,Pix,tempEnc,tempDec;
byte ImaoePix[],pixels[],acak[]; int A[] , tempKey;
byte RandomNumber[] ; File out,output;
Strino namaFile,set,namEnc,namDec,K; int setNum = 0;
SecureRandom random ; editor-fold defaultstate=collapsed desc=Generated
Code private void initComponents {
ButFile = new javax.swino.JButton; Pane = new javax.swino.JScrollPane;
jLabel1 = new javax.swino.JLabel; PANEE = new javax.swino.JScrollPane;
PANED = new javax.swino.JScrollPane; ButEnc = new javax.swino.JButton;
A-9
ButDec = new javax.swino.JButton; jLabel2 = new javax.swino.JLabel;
jLabel3 = new javax.swino.JLabel; jLabel4 = new javax.swino.JLabel;
valKey = new javax.swino.JTextField; jDesktopPane1 = new javax.swino.JDesktopPane;
encTime = new javax.swino.JTextField; decTime = new javax.swino.JTextField;
jLabel5 = new javax.swino.JLabel; jLabel6 = new javax.swino.JLabel;
jMenuBar1 = new javax.swino.JMenuBar; menu1 = new javax.swino.JMenu;
menu2 = new javax.swino.JMenu; menu3 = new javax.swino.JMenu;
setDefaultCloseOperationjavax.swino.WindowConstants.EXIT_ON_CL OSE;
setBackoroundnew java.awt.Color248, 244, 244; setForeoroundjava.awt.Color.white;
ButFile.setTextBROWSE; ButFile.addActionListenernew
java.awt.event.ActionListener { public void actionPerformedjava.awt.event.ActionEvent
evt { ButFileActionPerformedevt;
} };
jLabel1.setBackoroundnew java.awt.Color225, 88, 88; jLabel1.setForeoroundnew java.awt.Color33, 38, 208;
jLabel1.setTextNORMAL IMAGE; ButEnc.setTextENCRYPT;
ButEnc.addActionListenernew java.awt.event.ActionListener {
public void actionPerformedjava.awt.event.ActionEvent evt {
ButEncActionPerformedevt; }
}; ButDec.setTextDECRYPT;
ButDec.addActionListenernew java.awt.event.ActionListener {
public void actionPerformedjava.awt.event.ActionEvent evt {
ButDecActionPerformedevt; }
}; jLabel2.setForeoroundnew java.awt.Color13, 45, 238;
jLabel2.setTextENCRYPT IMAGE; jLabel3.setForeoroundnew java.awt.Color32, 13, 223;
jLabel3.setTextDECRYPT IMAGE; jLabel4.setForeoroundnew java.awt.Color36, 7, 244;
A-10
jLabel4.setTextKEY LENGTH :; jLabel5.setBackoroundnew java.awt.Color32, 76, 248;
jLabel5.setForeoroundnew java.awt.Color30, 55, 222; jLabel5.setTextENCRYPT TIME :;
jLabel6.setForeoroundnew java.awt.Color23, 19, 248; jLabel6.setTextDECRYPT TIME;
menu1.setTextHome; menu1.addMouseListenernew java.awt.event.MouseAdapter {
public void mouseClickedjava.awt.event.MouseEvent evt {
menu1MouseClickedevt; }
}; jMenuBar1.addmenu1;
menu2.setTextProoram; menu2.addMouseListenernew java.awt.event.MouseAdapter {
public void mouseClickedjava.awt.event.MouseEvent evt {
menu2MouseClickedevt; }
}; jMenuBar1.addmenu2;
menu3.setTextHelp; menu3.addMouseListenernew java.awt.event.MouseAdapter {
public void mouseClickedjava.awt.event.MouseEvent evt {
menu3MouseClickedevt; }
}; jMenuBar1.addmenu3;
setJMenuBarjMenuBar1; javax.swino.GroupLayout layout = new
javax.swino.GroupLayoutoetContentPane; oetContentPane.setLayoutlayout;
layout.setHorizontalGroup layout.createParallelGroupjavax.swino.GroupLayout.Alionment.LE
ADING .addGrouplayout.createSequentialGroup
.addGrouplayout.createParallelGroupjavax.swino.G roupLayout.Alionment.LEADING
.addGrouplayout.createSequentialGroup .addGap63, 63, 63
.addComponentButFile, javax.swino.GroupLayout.PREFERRED_SIZE, 88,
javax.swino.GroupLayout.PREFERRED_SIZE .addGap162, 162, 162
.addComponentButEnc, javax.swino.GroupLayout.PREFERRED_SIZE, 88,
javax.swino.GroupLayout.PREFERRED_SIZE .addGap169, 169, 169
A-11
.addComponentButDec, javax.swino.GroupLayout.PREFERRED_SIZE, 88,
javax.swino.GroupLayout.PREFERRED_SIZE .addGrouplayout.createSequentialGroup
.addGap68, 68, 68 .addComponentjLabel1
.addGap153, 153, 153 .addComponentjLabel2,
javax.swino.GroupLayout.PREFERRED_SIZE, 111, javax.swino.GroupLayout.PREFERRED_SIZE
.addGap132, 132, 132 .addComponentjLabel3,
javax.swino.GroupLayout.PREFERRED_SIZE, 117, javax.swino.GroupLayout.PREFERRED_SIZE
.addContainerGapjavax.swino.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE
.addGrouplayout.createSequentialGroup .addContainerGap
.addComponentPane, javax.swino.GroupLayout.PREFERRED_SIZE, 210,
javax.swino.GroupLayout.PREFERRED_SIZE .addGap35, 35, 35
.addComponentPANEE, javax.swino.GroupLayout.PREFERRED_SIZE, 210,
javax.swino.GroupLayout.PREFERRED_SIZE .addGap37, 37, 37
.addComponentPANED, javax.swino.GroupLayout.PREFERRED_SIZE, 210,
javax.swino.GroupLayout.PREFERRED_SIZE .addGrouplayout.createParallelGroupjavax.swino.G
roupLayout.Alionment.LEADING .addGrouplayout.createSequentialGroup
.addPreferredGapjavax.swino.LayoutStyle.C omponentPlacement.RELATED, javax.swino.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE .addComponentjDesktopPane1,
javax.swino.GroupLayout.PREFERRED_SIZE, javax.swino.GroupLayout.DEFAULT_SIZE,
javax.swino.GroupLayout.PREFERRED_SIZE .addGap31, 31, 31
.addGrouplayout.createSequentialGroup .addPreferredGapjavax.swino.LayoutStyle.C
omponentPlacement.RELATED, 15, Short.MAX_VALUE .addGrouplayout.createParallelGroupjavax.
swino.GroupLayout.Alionment.LEADING .addComponentjLabel6
.addGrouplayout.createParallelGroupj avax.swino.GroupLayout.Alionment.TRAILING
.addComponentdecTime, javax.swino.GroupLayout.PREFERRED_SIZE, 118,
javax.swino.GroupLayout.PREFERRED_SIZE .addComponentencTime,
javax.swino.GroupLayout.PREFERRED_SIZE, 118, javax.swino.GroupLayout.PREFERRED_SIZE
.addComponentjLabel5 .addComponentvalKey,
javax.swino.GroupLayout.PREFERRED_SIZE, 114, javax.swino.GroupLayout.PREFERRED_SIZE
A-12
.addComponentjLabel4, javax.swino.GroupLayout.PREFERRED_SIZE, 94,
javax.swino.GroupLayout.PREFERRED_SIZE .addGap0, 45, Short.MAX_VALUE
; layout.setVerticalGroup
layout.createParallelGroupjavax.swino.GroupLayout.Alionment.LE ADING
.addGroupjavax.swino.GroupLayout.Alionment.TRAILING, layout.createSequentialGroup
.addGrouplayout.createParallelGroupjavax.swino.G roupLayout.Alionment.TRAILING
.addGrouplayout.createSequentialGroup .addGap77, 77, 77
.addComponentjLabel4, javax.swino.GroupLayout.PREFERRED_SIZE, 27,
javax.swino.GroupLayout.PREFERRED_SIZE .addPreferredGapjavax.swino.LayoutStyle.C
omponentPlacement.RELATED .addComponentvalKey,
javax.swino.GroupLayout.PREFERRED_SIZE, javax.swino.GroupLayout.DEFAULT_SIZE,
javax.swino.GroupLayout.PREFERRED_SIZE .addGap34, 34, 34
.addGrouplayout.createParallelGroupjavax. swino.GroupLayout.Alionment.LEADING
.addComponentjDesktopPane1, javax.swino.GroupLayout.PREFERRED_SIZE,
javax.swino.GroupLayout.DEFAULT_SIZE, javax.swino.GroupLayout.PREFERRED_SIZE
.addComponentjLabel5 .addGap17, 17, 17
.addComponentencTime, javax.swino.GroupLayout.PREFERRED_SIZE,
javax.swino.GroupLayout.DEFAULT_SIZE, javax.swino.GroupLayout.PREFERRED_SIZE
.addPreferredGapjavax.swino.LayoutStyle.C omponentPlacement.RELATED, javax.swino.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE .addComponentjLabel6
.addGap30, 30, 30 .addComponentdecTime,
javax.swino.GroupLayout.PREFERRED_SIZE, 25, javax.swino.GroupLayout.PREFERRED_SIZE
.addGrouplayout.createSequentialGroup .addContainerGapjavax.swino.GroupLayout.D
EFAULT_SIZE, Short.MAX_VALUE .addGrouplayout.createParallelGroupjavax.
swino.GroupLayout.Alionment.BASELINE .addComponentjLabel2,
javax.swino.GroupLayout.PREFERRED_SIZE, 15, javax.swino.GroupLayout.PREFERRED_SIZE
.addComponentjLabel3 .addComponentjLabel1
.addPreferredGapjavax.swino.LayoutStyle.C omponentPlacement.RELATED
.addGrouplayout.createParallelGroupjavax. swino.GroupLayout.Alionment.LEADING
A-13
.addComponentPane, javax.swino.GroupLayout.PREFERRED_SIZE, 300,
javax.swino.GroupLayout.PREFERRED_SIZE .addComponentPANEE,
javax.swino.GroupLayout.PREFERRED_SIZE, 300, javax.swino.GroupLayout.PREFERRED_SIZE
.addComponentPANED, javax.swino.GroupLayout.PREFERRED_SIZE, 300,
javax.swino.GroupLayout.PREFERRED_SIZE .addPreferredGapjavax.swino.LayoutStyle.Component
Placement.UNRELATED .addGrouplayout.createParallelGroupjavax.swino.G
roupLayout.Alionment.LEADING, false .addGrouplayout.createParallelGroupjavax.swi
no.GroupLayout.Alionment.BASELINE .addComponentButEnc
.addComponentButDec .addComponentButFile,
javax.swino.GroupLayout.DEFAULT_SIZE, javax.swino.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE
.addContainerGap ;
pack; } editor-fold
private void ButFileActionPerformedjava.awt.event.ActionEvent evt {
TODO add your handlino code here: try{
ifvalKey.oetText.equals128 || valKey.oetText.equals192 ||
valKey.oetText.equals256{
iftempKey8 == 16 || tempKey8 == 24 || tempKey8 == 32{
JFileChooser s = new JFileChooser ; if s.showOpenDialooButFile ==
JFileChooser.APPROVE_OPTION{ File f = s.oetSelectedFile;
try{ imaoe = ImaoeIO.readf;
namaFile = f.oetName; }
catchException e{ }
jlab.setIconnew ImaoeIconf.toStrino; jlab.setHorizontalAlionmentJLabel.CENTER;
Pane.oetViewport.addjlab; }
catchException e { JOptionPane.showMessaoeDialoonull,Key doesnt
Match,Please Write 128 ,192 or 256;
A-14
} NormalImaoe = ImaoeIO.readf;
else{ JOptionPane.showMessaoeDialoonull,Key doesnt
Match,Please Write 128 ,192 or 256; }
} public void oenerateKey{
K = valKey.oetText; tempKey = Inteoer.parseIntK;
this.random = new SecureRandom; this.acak = new byte[tempKey8];
random.nextBytesacak; }
public void oetPixel { oenerateKey;
try{ width = 0;
heioht = 0; set = Inteoer.toStrinosetNum;
setNum++; File input = new FileT.jpo;
imaoe = ImaoeIO.readinput; width += imaoe.oetWidth;
heioht += imaoe.oetHeioht; System.out.printlnwidth;
System.out.printlnheioht; int index = widthheioht;
int count = 0; this.pixels = new byte[widthheioht];
this.A = new int[widthheioht]; this.ImaoePix = new byte [widthheioht];
A = null; ImaoePix = null;
pixels = null; byte[] DataImaoe = new byte[widthheioht];
try{ for int i=0 ; iwidth; i++{
for int j=0; jheioht; j++{ A[count]=0;
A[count]=imaoe.oetRGBi, j 256; pixels[count] = 0;
pixels[count] =byte imaoe.oetRGBi, j; ImaoePix[count] = 0;
ImaoePix[count] = pixels[count]; System.out.printlnA[count]+ =
+ImaoePix[count]; dataAwal +=
Inteoer.toStrinopixels[count]; count++;
A-15
} }
} catchException e{
System.out.printlnFor Salah; System.out.printlne.oetMessaoe;
} System.out.printlnPenoambilan Nilai Pixel
Berhasil Alhamdulillah; }
catch Exception e{ System.out.printlnIni Salah;
System.out.printlne.oetMessaoe; }
} public void encrypt throws Exception{
oetPixel; encVal = {byte 0};
namEnc = Enc-+set+.jpo; try{
lono start = System.currentTimeMillis; byte k[]=acak;
Strino aloo = AES; output = new File namEnc;
output.createNewFile; File normal = new File Normal.jpo;
encImaoe = new BufferedImaoe width, heioht,TYPE_INT_RGB;
normalImaoe = new BufferedImaoe width, heioht,TYPE_INT_RGB;
Key key = new SecretKeySpec k, aloo; Cipher c = Cipher.oetInstancealoo;
c.initCipher.ENCRYPT_MODE, key; int index =0;
try{ val = Pix;
encVal = c.doFinalImaoePix; System.out.printlnEncval did work;
} catchException q{
System.out.printlnq.oetMessaoe; System.out.printlnEncval didi not work;
} try{
for int x = 0; xwidth; x++{ for int y=0 ; yheioht ; y++{
A-16
System.out.printlnEncval ke-+index+ = +encVal[index];
normalImaoe.setRGBx, y, ImaoePix[index]; tempEnc[index] = 0;
tempEnc[index] += encVal[index]; encVal[index] = 0;
encImaoe.setRGBx, y, encVal[index]; index++;
} }
System.out.printlnPass; }
catchException e{ System.out.printlne.oetMessaoe;
System.out.printlnSepertinya For Salah; }
try{ ImaoeIO.writeencImaoe, JPG, output;
lono end = System.currentTimeMillis; NumberFormat time = new DecimalFormat0.00000;
lono t = end-start; encTime.setTextStrino.valueOft1000d+ second;
System.out.printExecution time is +time.formatend-start1000d+seconds;
JOptionPane.showMessaoeDialoonull,Enkripsi Berhasil ;
System.out.printlnGambar Enkripsi Selesai; }
catch Exception e{ System.out.printlne.oetMessaoe;
System.out.printlnGambar Enkripsi tidak bisa Dicetak;
} try{
ImaoeIO.writenormalImaoe, JPG, normal; System.out.printlnGambar Normal Selesai;
} catch Exception e{
System.out.printlne.oetMessaoe; System.out.printlnGambar Normal Tidak Bisa
Dicetak; }
} catch Exception e{
System.out.printlne.oetMessaoe; System.out.printlnEnkripsi tidak bisa;
} }
public void decrypt throws Exception { namDec = Dec-+set+.jpo;
try{
A-17
lono first = System.currentTimeMillis; byte k[]=acak;
int DecVal[] = new int[widthheioht]; Strino aloo = AES;
decImaoe = new BufferedImaoe width, heioht,TYPE_INT_RGB;
Key key = new SecretKeySpec k, aloo; Cipher c = Cipher.oetInstancealoo;
c.initCipher.DECRYPT_MODE, key; int in =0;
decVal = c.doFinalencVal; for int x = 0; xwidth; x++{
for int y=0 ; yheioht ; y++{ System.out.printlndecVal[in];
Strino tex; tex = new StrinodecVal[in];
dataAkhir += tex; tempDec[in] = 0;
tempDec[in] += decVal[in]; DecVal[in] += 0;
DecVal[in] = A[in]256 + decVal[in]; decImaoe.setRGBx, y, DecVal[in];
in++; }
} out = new FilenamDec;
out.createNewFile; ImaoeIO.writedecImaoe, JPG, out;
lono last = System.currentTimeMillis; NumberFormat time = new DecimalFormat0.00000;
lono ti = last-first; decTime.setTextStrino.valueOfti1000d+ second;
System.out.printExecution time is +time.formatlast-first1000d+seconds;
System.out.printlnGambar Dekripsi Selesai; }
catchException ex{ System.out.printlnex.oetMessaoe;
System.out.printlnGambar Dekripsi tidak bisa Dicetak;
} }
private void ButEncActionPerformedjava.awt.event.ActionEvent evt {
TODO add your handlino code here: try{
encrypt; }
catchException e{ }
A-18
jEnc.setIconnew ImaoeIconoutput.toStrino; jEnc.setHorizontalAlionmentJLabel.CENTER;
PANEE.oetViewport.addjEnc; }
private void ButDecActionPerformedjava.awt.event.ActionEvent evt {
TODO add your handlino code here: try{
decrypt; }
catchException e{ }
jDec.setIconnew ImaoeIconout.toStrino; jDec.setHorizontalAlionmentJLabel.CENTER;
PANED.oetViewport.addjDec; }
private void menu1MouseClickedjava.awt.event.MouseEvent evt {
TODO add your handlino code here: dispose;
FormImaoe HomePaoe = new FormImaoe; HomePaoe.setVisibletrue;
HomePaoe.setSize710, 700; HomePaoe.setLocationRelativeTonull;
setNum = 0; FormImaoe HomePaoe = new FormImaoe;
HomePaoe.show; }
private void menu2MouseClickedjava.awt.event.MouseEvent evt {
TODO add your handlino code here: Framee prooramPaoe = new Framee;
prooramPaoe.show; }
private void menu3MouseClickedjava.awt.event.MouseEvent evt {
TODO add your handlino code here: dispose;
HelpFrame helpPaoe = new HelpFrame; helpPaoe.setVisibletrue;
helpPaoe.setLocationRelativeTonull; setNum = 0;
} param aros the command line arouments
public static void mainStrino aros[] { Set the Nimbus look and feel
editor-fold defaultstate=collapsed desc= Look and feel settino code optional
If Nimbus introduced in Java SE 6 is not available, stay with the default look and feel.
A-19
For details see http:download.oracle.comjavasetutorialuiswinolookandfeel
plaf.html try {
for javax.swino.UIManaoer.LookAndFeelInfo info : javax.swino.UIManaoer.oetInstalledLookAndFeels {
if Nimbus.equalsinfo.oetName { javax.swino.UIManaoer.setLookAndFeelinfo.oetClassName;
break; }
} } catch ClassNotFoundException ex {
java.util.loooino.Loooer.oetLoooerFramee.class.oetName.loo java.util.loooino.Level.SEVERE, null, ex;
} catch InstantiationException ex { java.util.loooino.Loooer.oetLoooerFramee.class.oetName.loo
java.util.loooino.Level.SEVERE, null, ex; } catch IlleoalAccessException ex {
java.util.loooino.Loooer.oetLoooerFramee.class.oetName.loo java.util.loooino.Level.SEVERE, null, ex;
} catch javax.swino.UnsupportedLookAndFeelException ex { java.util.loooino.Loooer.oetLoooerFramee.class.oetName.loo
java.util.loooino.Level.SEVERE, null, ex; }
editor-fold Create and display the form
java.awt.EventQueue.invokeLaternew Runnable { public void run {
new Framee.setVisibletrue; }
}; }
Variables declaration - do not modify private javax.swino.JButton ButDec;
private javax.swino.JButton ButEnc; private javax.swino.JButton ButFile;
public javax.swino.JScrollPane PANED; public javax.swino.JScrollPane PANEE;
public javax.swino.JScrollPane Pane; private javax.swino.JTextField decTime;
private javax.swino.JTextField encTime; private javax.swino.JDesktopPane jDesktopPane1;
private javax.swino.JLabel jLabel1; private javax.swino.JLabel jLabel2;
private javax.swino.JLabel jLabel3; private javax.swino.JLabel jLabel4;
private javax.swino.JLabel jLabel5; private javax.swino.JLabel jLabel6;
private javax.swino.JMenuBar jMenuBar1; private javax.swino.JMenu menu1;
private javax.swino.JMenu menu2;
A-20
private javax.swino.JMenu menu3; private javax.swino.JTextField valKey;
End of variables declaration }
3. Form Help HelpFrame.java