java - How to fix error `StringIndexOutOfBoundsException`? -


i learning rc4 encryption , try execute script java when run debug on eclipse kepler have error this:

exception in thread "awt-eventqueue-0" java.lang.stringindexoutofboundsexception: string index out of range: 4944     @ java.lang.string.charat(unknown source)     @ rc4.rc4.enkripsi(rc4.java:309)     @ rc4.rc4.jbutton3actionperformed(rc4.java:364)     @ rc4.rc4.access$4(rc4.java:362)     @ rc4.rc4$5.actionperformed(rc4.java:152)     @ javax.swing.abstractbutton.fireactionperformed(unknown source)     @ javax.swing.abstractbutton$handler.actionperformed(unknown source)     @ javax.swing.defaultbuttonmodel.fireactionperformed(unknown source)     @ javax.swing.defaultbuttonmodel.setpressed(unknown source)     @ javax.swing.plaf.basic.basicbuttonlistener.mousereleased(unknown source)     @ java.awt.component.processmouseevent(unknown source)     @ javax.swing.jcomponent.processmouseevent(unknown source)     @ java.awt.component.processevent(unknown source)     @ java.awt.container.processevent(unknown source)     @ java.awt.component.dispatcheventimpl(unknown source)     @ java.awt.container.dispatcheventimpl(unknown source)     @ java.awt.component.dispatchevent(unknown source)     @ java.awt.lightweightdispatcher.retargetmouseevent(unknown source)     @ java.awt.lightweightdispatcher.processmouseevent(unknown source)     @ java.awt.lightweightdispatcher.dispatchevent(unknown source)     @ java.awt.container.dispatcheventimpl(unknown source)     @ java.awt.window.dispatcheventimpl(unknown source)     @ java.awt.component.dispatchevent(unknown source)     @ java.awt.eventqueue.dispatcheventimpl(unknown source)     @ java.awt.eventqueue.access$500(unknown source)     @ java.awt.eventqueue$3.run(unknown source)     @ java.awt.eventqueue$3.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(unknown source)     @ java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(unknown source)     @ java.awt.eventqueue$4.run(unknown source)     @ java.awt.eventqueue$4.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(unknown source)     @ java.awt.eventqueue.dispatchevent(unknown source)     @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source)     @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source)     @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source)     @ java.awt.eventdispatchthread.pumpevents(unknown source)     @ java.awt.eventdispatchthread.pumpevents(unknown source)     @ java.awt.eventdispatchthread.run(unknown source) 

what wrong that? how can fix that? should install something, or what?

/*  * change license header, choose license headers in project properties.  * change template file, choose tools | templates  * , open template in editor.  */ package rc4;  import java.io.bufferedreader; import java.io.bufferedwriter; import java.io.file; import java.io.fileinputstream; import java.io.filereader; import java.io.filewriter; import java.io.ioexception; import java.io.inputstreamreader; import java.util.arraylist; import java.util.logging.level; import java.util.logging.logger; import javax.swing.jfilechooser;  /**  *  * @author user  */ public class rc4 extends javax.swing.jframe {  /**  * creates new form mainframe  */ public rc4() { initcomponents(); }  /**  * method called within constructor initialize form.  * warning: not modify code. content of method  * regenerated form editor.  */ @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code">//gen-begin:initcomponents private void initcomponents() {  jlabel3 = new javax.swing.jlabel(); filechooser = new javax.swing.jfilechooser(); buttongroup1 = new javax.swing.buttongroup(); jlabel1 = new javax.swing.jlabel(); jseparator1 = new javax.swing.jseparator(); jpanel1 = new javax.swing.jpanel(); jlabel2 = new javax.swing.jlabel(); radioenkripsi = new javax.swing.jradiobutton(); radiodekripsi = new javax.swing.jradiobutton(); jpanel2 = new javax.swing.jpanel(); jlabel4 = new javax.swing.jlabel(); buttoninputtext = new javax.swing.jbutton(); buttoninputkey = new javax.swing.jbutton(); jbutton3 = new javax.swing.jbutton();  jlabel3.settext("jlabel3");  setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close);  jlabel1.setfont(new java.awt.font("tahoma", 0, 36)); // noi18n jlabel1.sethorizontalalignment(javax.swing.swingconstants.center); jlabel1.settext("rc4");  jlabel2.settext("metode  ");  buttongroup1.add(radioenkripsi); radioenkripsi.setselected(true); radioenkripsi.settext("enkripsi"); radioenkripsi.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { radioenkripsiactionperformed(evt); } });  buttongroup1.add(radiodekripsi); radiodekripsi.settext("dekripsi"); radiodekripsi.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { radiodekripsiactionperformed(evt); } });  javax.swing.grouplayout jpanel1layout = new javax.swing.grouplayout(jpanel1); jpanel1.setlayout(jpanel1layout); jpanel1layout.sethorizontalgroup( jpanel1layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(jpanel1layout.createsequentialgroup() .addcontainergap() .addcomponent(jlabel2, javax.swing.grouplayout.preferred_size, 90, javax.swing.grouplayout.preferred_size) .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated) .addcomponent(radioenkripsi) .addgap(63, 63, 63) .addcomponent(radiodekripsi) .addcontainergap(javax.swing.grouplayout.default_size, short.max_value)) ); jpanel1layout.setverticalgroup( jpanel1layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(jpanel1layout.createsequentialgroup() .addcontainergap() .addgroup(jpanel1layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jlabel2) .addcomponent(radioenkripsi) .addcomponent(radiodekripsi)) .addcontainergap(12, short.max_value)) );  jlabel4.settext("pilih file input   ");  buttoninputtext.settext("plaintext"); buttoninputtext.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { buttoninputtextactionperformed(evt); } });  buttoninputkey.settext("key"); buttoninputkey.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { buttoninputkeyactionperformed(evt); } });  javax.swing.grouplayout jpanel2layout = new javax.swing.grouplayout(jpanel2); jpanel2.setlayout(jpanel2layout); jpanel2layout.sethorizontalgroup( jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(jpanel2layout.createsequentialgroup() .addcontainergap() .addcomponent(jlabel4, javax.swing.grouplayout.preferred_size, 90, javax.swing.grouplayout.preferred_size) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(buttoninputtext, javax.swing.grouplayout.preferred_size, 110, javax.swing.grouplayout.preferred_size) .addgap(18, 18, 18) .addcomponent(buttoninputkey, javax.swing.grouplayout.preferred_size, 110, javax.swing.grouplayout.preferred_size) .addcontainergap()) ); jpanel2layout.setverticalgroup( jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(jpanel2layout.createsequentialgroup() .addcontainergap() .addgroup(jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jlabel4) .addcomponent(buttoninputtext) .addcomponent(buttoninputkey)) .addcontainergap(javax.swing.grouplayout.default_size, short.max_value)) );  jbutton3.settext("proses"); jbutton3.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton3actionperformed(evt); } });  javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(javax.swing.grouplayout.alignment.trailing, layout.createsequentialgroup() .addcontainergap() .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing) .addcomponent(jbutton3, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jpanel2, javax.swing.grouplayout.alignment.leading, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jpanel1, javax.swing.grouplayout.alignment.leading, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jlabel1, javax.swing.grouplayout.alignment.leading, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jseparator1, javax.swing.grouplayout.alignment.leading)) .addcontainergap()) ); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(7, 7, 7) .addcomponent(jlabel1) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(jseparator1, javax.swing.grouplayout.preferred_size, 10, javax.swing.grouplayout.preferred_size) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(jpanel1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size) .addgap(18, 18, 18) .addcomponent(jpanel2, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related, 20, short.max_value) .addcomponent(jbutton3, javax.swing.grouplayout.preferred_size, 51, javax.swing.grouplayout.preferred_size) .addcontainergap()) );  pack(); }// </editor-fold>//gen-end:initcomponents  private void radioenkripsiactionperformed(java.awt.event.actionevent evt) {//gen-first:event_radioenkripsiactionperformed buttoninputtext.settext("plaintext"); }//gen-last:event_radioenkripsiactionperformed  private void buttoninputtextactionperformed(java.awt.event.actionevent evt) {//gen-first:event_buttoninputtextactionperformed bufferedreader bf; int returnval = filechooser.showopendialog(this); if (returnval == jfilechooser.approve_option) { file file = filechooser.getselectedfile(); try { bf = new bufferedreader(new inputstreamreader(new fileinputstream(file.getabsolutepath()))); string temp = bf.readline(); //merubah input ke biner disimpan dalam variabel keybiner (int = 0; < temp.length(); a++) { string biner = integer.tobinarystring((int) temp.charat(a)); while (biner.length() < 8) { biner = "0" + biner; } inputtext += biner; } } catch (exception ex) { system.out.println("problem accessing file" + file.getabsolutepath()); } } else { system.out.println("file access cancelled user."); } //system.out.println(inputtext); }//gen-last:event_buttoninputtextactionperformed  private void buttoninputkeyactionperformed(java.awt.event.actionevent evt) {//gen-first:event_buttoninputkeyactionperformed  bufferedreader bf; int returnval = filechooser.showopendialog(this); if (returnval == jfilechooser.approve_option) { file file = filechooser.getselectedfile(); //get output path outputpath = file.getabsolutepath(); int b = outputpath.length()-1; while(outputpath.charat(b)!='\\'){ b--; } outputpath = outputpath.substring(0, b+1); //end of output path try { bf = new bufferedreader(new inputstreamreader(new fileinputstream(file.getabsolutepath()))); string temp = bf.readline(); keystring = temp; //merubah input ke biner disimpan dalam variabel keybiner (int = 0; < temp.length(); a++) { string biner = integer.tobinarystring((int) temp.charat(a)); while (biner.length() < 8) { biner = "0" + biner; } keybiner += biner; } } catch (exception ex) { system.out.println("problem accessing file" + file.getabsolutepath()); } } else { system.out.println("file access cancelled user."); } //system.out.println(keybiner); }//gen-last:event_buttoninputkeyactionperformed  private static void enkripsi() { //initialization (int = 0; <= 255; i++) { s[i] = i; t[i] = (int) keystring.charat(i % keystring.length()); } //end of initialization  //initial permutation int = 0, j = 0; (i = 0; <= 255; i++) { j = (j + s[i] + t[i]) % 256; //swap int temp = s[i]; s[i] = s[j]; s[j] = temp; } //end of initial permutation  //write output output1 += "tabel s setelah permutasi awal\n"; for(int = 0; <= 255; a++){ output1 +="s["+ + "] = " + s[a] + "\n"; }  //stream generation = 0; j = 0; (int = 0; < inputtext.length() / 8; a++) { = (i + 1) % 256; j = (j + s[i]) % 256; //swap int temp = s[i]; s[i] = s[j]; s[j] = temp; //////  int t = (s[i] + s[j]) % 256; string biner = integer.tobinarystring(s[t]); while (biner.length() < 8) { biner = "0" + biner; } //system.out.println(integer.tohexstring(integer.valueof(biner, 2))); keystreambiner += biner; } //end of stream generation  //write output output1 += "\ntabel s setelah enkripsi\n"; for(int = 0; <= 255; a++){ output1 += "s[" +a + "] = " + s[a] + "\n"; }  //xor keystream(biner) plaintext(biner) (int = 0; < inputtext.length(); a++) { string temp = ""; if (keystreambiner.charat(a) == inputtext.charat(a)) { temp = "0"; } else { temp = "1"; } chipertextbiner += temp; }  (int = 0; < chipertextbiner.length(); += 8) { system.out.print(integer.tohexstring(integer.valueof(chipertextbiner.substring(a, + 8), 2)) + " "); chipertexthexa += integer.tohexstring(integer.valueof(chipertextbiner.substring(a, + 8), 2)); chipertextstring += "" + (char) (int) integer.valueof(chipertextbiner.substring(a,a+8), 2); } output2 += "chipertext dalam biner :\n" + chipertextbiner; output2 += "\nchipertext dalam hexa :\n" + chipertexthexa; output2 += "\nchipertext dalam ascii :\n" + chipertextstring;  writehasilenkripsitofile(); }  static void writehasilenkripsitofile() { //system.out.println(outputpath);  try { file file1 = new file(outputpath + "output1.txt"); file file2 = new file(outputpath + "output2.txt");  // if file doesnt exists, create  try { file1.createnewfile(); file2.createnewfile(); } catch (ioexception ex) { logger.getlogger(rc4.class.getname()).log(level.severe, null, ex); }   filewriter fw1 = new filewriter(file1.getabsolutefile()); filewriter fw2 = new filewriter(file2.getabsolutefile()); bufferedwriter bw = new bufferedwriter(fw1); bw.write(output1); bw.close(); bw = new bufferedwriter(fw2); bw.write(output2); bw.close(); } catch (ioexception ex) { logger.getlogger(rc4.class.getname()).log(level.severe, null, ex); } }  private static void dekripsi() { }  private void jbutton3actionperformed(java.awt.event.actionevent evt) {//gen-first:event_jbutton3actionperformed if (radioenkripsi.isselected()) { enkripsi(); } else { dekripsi(); } }//gen-last:event_jbutton3actionperformed  private void radiodekripsiactionperformed(java.awt.event.actionevent evt) {//gen-first:event_radiodekripsiactionperformed buttoninputtext.settext("chipertext"); }//gen-last:event_radiodekripsiactionperformed  private static int[] s = new int[256]; private static int[] t = new int[256]; private static string keybiner = "", inputtext = "", keystreambiner = "", keystring = "", chipertextbiner = "", chipertextstring = "", chipertexthexa = ""; private static string outputpath = "", output1 = "",  output2 = ""; //private static int  j = 0;  /**  * @param args command line arguments  */ public static void main(string args[]) { //system.out.println(integer.tohexstring(integer.valueof("1110000", 2))); //system.out.println(integer.valueof("a",16)); //system.out.println(integer.tohexstring(16)); //system.out.println(integer.tobinarystring(255)); //system.out.println((int)'p'); //system.out.println(integer.tobinarystring((int) 'p')); //system.out.println(3 ^ 1); system.out.println(integer.valueof("01110000", 2)); //system.out.println((char) 65); /* set nimbus , feel */ //<editor-fold defaultstate="collapsed" desc=" , feel setting code (optional) "> /* if nimbus (introduced in java se 6) not available, stay default , feel.  * details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html   */ try { (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(rc4.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (instantiationexception ex) { java.util.logging.logger.getlogger(rc4.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (illegalaccessexception ex) { java.util.logging.logger.getlogger(rc4.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (javax.swing.unsupportedlookandfeelexception ex) { java.util.logging.logger.getlogger(rc4.class.getname()).log(java.util.logging.level.severe, null, ex); } //</editor-fold>  /* create , display form */ java.awt.eventqueue.invokelater(new runnable() { public void run() { new rc4().setvisible(true); } }); }  // variables declaration - not modify//gen-begin:variables private javax.swing.buttongroup buttongroup1; private javax.swing.jbutton buttoninputkey; private javax.swing.jbutton buttoninputtext; private javax.swing.jfilechooser filechooser; private javax.swing.jbutton jbutton3; private javax.swing.jlabel jlabel1; private javax.swing.jlabel jlabel2; private javax.swing.jlabel jlabel3; private javax.swing.jlabel jlabel4; private javax.swing.jpanel jpanel1; private javax.swing.jpanel jpanel2; private javax.swing.jseparator jseparator1; private javax.swing.jradiobutton radiodekripsi; private javax.swing.jradiobutton radioenkripsi; // end of variables declaration//gen-end:variables } 

that code try execute...


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -