|
111
|
Programación / Java / [Aporte] Copiador de bytes en un mismo medio
|
en: 29 Noviembre 2009, 19:53 pm
|
Hola a todos, hoy investigando y dando uso de la logica, he llegado a la siguiente conclusion sobre manipulacion directa de bytes: ES como interepretar una hoja de calculo. Y aqui el codigo fruto de mi mini-investigacion: package archivos; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author debci */ public class ManipulacionArchivos { public static void main (String args []) { try { // Se abre el fichero para lectura y escritura. // Nos situamos en el byte 100 del fichero. int longitud = (int) fichero.length(); fichero.seek(0); byte[] matrizBytes = new byte[longitud]; for (int i = 0; i< fichero.length(); i++) { try { fichero.seek(i); matrizBytes[i] = fichero.readByte(); Logger.getLogger(ManipulacionArchivos.class.getName()).log(Level.SEVERE, null, ex); } } for (int x=0; x < fichero.length();x++){ System. out. println(matrizBytes [x ]); } int doblePosicion = (int) (fichero.length() * 2); if(fichero.length() == 0){ fichero.setLength(1); } fichero.setLength(doblePosicion); for(int o = 0; o < 100; o++) { //Bucle que copia bytes segun su posicion paralela con intervalos //de x2 for(int y = 0; y < fichero.length() / 2 ; y++){ if(fichero.length() == 0){ fichero.seek(0); fichero.writeByte(98); } fichero.seek(fichero.length()/2 + y); fichero.writeByte(matrizBytes[y]); int progreso = (int) fichero.length() / 2; System. out. println("Quedan " + (progreso - y ) + " bytes por copiar."); } } Logger.getLogger(ManipulacionArchivos.class.getName()).log(Level.SEVERE, null, ex); } } }
Creo que no esta mal para haberlo sacado usando solamente mi logica y una duda que consulte en el foro. Vereis que el algoritmo es rebuscado de coj**** pero servira para que muchos entiendan como funciona esto. Saludos
|
|
|
112
|
Programación / Java / Guardar bytes de un archivo en una matriz
|
en: 29 Noviembre 2009, 12:27 pm
|
Hola a todos, estoy intentando guardar un archivo (todos sus bytes) en una matriz, pero no lo consigo, mirad mi codigo: package archivos; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author debci */ public class ManipulacionArchivos { public static void main (String args []) { try { // Se abre el fichero para lectura y escritura. // Nos situamos en el byte 100 del fichero. int longitud = (int) fichero.length(); fichero.seek(100); byte matrizBytes[] = new byte[longitud]; for(int i = 0; i< fichero.length(); i++) { matrizBytes[i] = fichero.readByte(); System. out. println(matrizBytes ); }
Pero no lo consigo, quizas será porque el metodo readByte();
no es aumentativo, no lo se, solo se que no lo consigo. Un saludo a todos
|
|
|
113
|
Programación / Java / Problema con el detecion de Teclado
|
en: 28 Noviembre 2009, 16:16 pm
|
Hola a todos, estoy mejorando mi RAT en java que pronto acabare pero se me presenta una duda, a partir del siguiente codigo: ackage robot; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.*; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFrame; /** * * @author debci */ public static void main (String args []){ TestTeclado teclado = new TestTeclado(); teclado.Teclas(); try { Logger.getLogger(TestTeclado.class.getName()).log(Level.SEVERE, null, ex); } } while(true) { System. out. println("Se oprimió tecla: " + evento. getKeyText( evento. getKeyCode() )); } } while(true) { System. out. println("Se oprimió tecla: " + evento. getKeyText( evento. getKeyCode() )); } } public void keyPressed (KeyEvent evento ) { while(true) { System. out. println("Se oprimió tecla: " + evento. getKeyText( evento. getKeyCode() )); } } public void keyReleased (KeyEvent evento ) { while(true) { System. out. println("Se oprimió tecla: " + evento. getKeyText( evento. getKeyCode() )); } } private void Teclas() { TestTeclado tecladito = new TestTeclado(); tecladito.setVisible(true); addKeyListener(this); } }
La cosa, que diga cosas, es que se me presentan dos dudas: 1- Puedo agregar un keyListener a algo que no sea un frame? Es decir una simple aplicacion de shell. 2- Aunque lo haga con un jframe no me detecta las teclas, como es esto? Saludos
|
|
|
114
|
Programación / Java / Problema con algoritmo encriptador y matriz
|
en: 22 Noviembre 2009, 12:11 pm
|
Hola a todos, hoy estaba diseñando un algoritmo que cifra cadenas, cuando me dio un error extraño (puede que sea por mi autodidactia) que no soy capaz de resolver: public void cifra() { cadenaIntroducida.toUpperCase(); char[] matrizCaracteres = cadenaIntroducida.toCharArray(); int numeroCaracteres = matrizCaracteres.length; System. out. println("La cadena tiene " + numeroCaracteres +" caracteres." ); for(int i = 0; i < numeroCaracteres; i++){ matrizCaracteres[i] = matrizCaracteres[i+1]; } for(int x = 0; x < numeroCaracteres; x++){ System. out. println(matrizCaracteres [x ]); } }
La cosa, es que mi algoritmo hace lo siguiente, transforma todos los valores del array en el siguiente del indice, es decir, el valor que este en 0, sera transformado por el que este en 1, el de uno sera el 2, basicamente corre hacia un lado los indices. Me da un error raro al ejecutar: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at encriptacion.Encriptador.cifra(Encriptador.java:23) at encriptacion.Encriptador.main(Encriptador.java:32) La cadena tiene 5 caracteres. Java Result: 1
A que se debe? Saludos
|
|
|
115
|
Programación / Ingeniería Inversa / OllyDbg para Linux?
|
en: 20 Noviembre 2009, 18:11 pm
|
Hola a todos, estaba investigando sobre el cracking, y me vino a la cabeza una duda existencial de las mias.... Existe algun debugger bueno para Linux? Con interfaz grafica si pudiese ser xD He estado intentando compilar el EDB pero no hay pelotas, me da muchos errores y no genera binarios. Saludos
|
|
|
116
|
Programación / Java / [APORTE] Solucionador de ecuaciones de 2o Grado
|
en: 20 Noviembre 2009, 16:50 pm
|
Hola a todos, aqui os dejo, la plantilla, que he creado para solucionar ecuaciones de segundo grado con las dos raizes, como resultado: /* * Programa que resuelve ecuaciones de segundo grado * con capacidad ilimitada. */ /* * Main.java * * Created on 20-nov-2009, 15:53:49 */ package ecuaciones; /** * * @author debci */ public class Main extends javax. swing. JFrame { /** Creates new form Main */ public Main() { initComponents(); } /** Definicion de los mtodo y datos para la interfaz */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { Muestra = new javax. swing. JLabel(); jLabel1 = new javax. swing. JLabel(); jLabel2 = new javax. swing. JLabel(); XCuadrado = new javax. swing. JLabel(); jLabel3 = new javax. swing. JLabel(); jLabel4 = new javax. swing. JLabel(); jLabel5 = new javax. swing. JLabel(); btnResolver = new javax. swing. JButton(); setTitle("Resolucion de ecuaciones de 2o Grado"); Muestra.setToolTipText("Muestra de la ecuacion de segundo grado"); jLabel1.setText("Resolucion de una ecuacion de segundo grado"); jTextField1.setText("0"); jLabel2.setText("="); jLabel3.setText("+"); public void actionPerformed (java. awt. event. ActionEvent evt ) { bActionPerformed(evt); } }); jLabel4.setText("X"); jLabel5.setText("+"); Consola.setColumns(20); Consola.setEditable(false); Consola.setRows(5); Consola.setText("--Solventador de ecuaciones sencillo--\n--Version beta--\n--Andoni Diaz <andoni94@gmail.com>--\n----------------------------------------------------\n_____________________________________\n----------------------------------------------------\n"); Consola.setToolTipText("Consola de resolucion de ecuaciones"); Consola.setAutoscrolls(true); jScrollPane1.setViewportView(Consola); btnResolver.setText("Resolver Ecuacion"); public void actionPerformed (java. awt. event. ActionEvent evt ) { btnResolverActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(68, 68, 68) .addComponent(jLabel1) . addContainerGap(84, Short. MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() . addContainerGap(167, Short. MAX_VALUE) .addComponent(Muestra, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(164, 164, 164)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(3, 3, 3) .addComponent(XCuadrado, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(b, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(4, 4, 4) .addComponent(jLabel4) .addGap(18, 18, 18) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(c, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) . addContainerGap(174, Short. MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE) . addContainerGap(55, Short. MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() . addContainerGap(306, Short. MAX_VALUE) .addComponent(btnResolver) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(15, 15, 15) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Muestra, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2) .addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3) .addComponent(b, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4) .addComponent(c, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(4, 4, 4) .addComponent(XCuadrado, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE) . addPreferredGap(javax. swing. LayoutStyle. ComponentPlacement. RELATED, 28, Short. MAX_VALUE) .addComponent(btnResolver) .addContainerGap()) ); pack(); }// </editor-fold> private void bActionPerformed (java. awt. event. ActionEvent evt ) { // TODO add your handling code here: } private void btnResolverActionPerformed (java. awt. event. ActionEvent evt ) { int a_i; int b_i; int c_i; int x; int y; //Transformacion de valores a entero a_i = Integer. parseInt(a. getText()); b_i = Integer. parseInt(b. getText()); c_i = Integer. parseInt(c. getText()); //Calculo del primer coeficiente, este es positivo x =(int) ((-b_i + Math. sqrt(b_i ^ 2 - 4 * a_i * c_i )) / (2 * a_i )); //Calculo del segundo coeficiente, este es negativo y =(int) ((-b_i - Math. sqrt(b_i ^ 2 - 4 * a_i * c_i )) / (2 * a_i )); Consola.append("Resultados de la ecuacion obtenidos:\n"); Consola.append("X = "+ ResultadoX + "\n"); Consola.append("Y = "+ ResultadoY + "\n"); Consola.append("La dos raizes de la ecuacion son X y Y\n\n"); Consola.append("--------------------------------------\n\n"); } /** * @param args the command line arguments */ public static void main (String args []) { public void run() { new Main().setVisible(true); Muestra.setText("a*x^2+b*x+c"); XCuadrado.setText("X²"); } }); } // Variables declaration - do not modify private static javax. swing. JLabel Muestra ; private static javax. swing. JLabel XCuadrado ; private javax. swing. JButton btnResolver ; 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 ; // End of variables declaration }
Si, esta hecho con netbeans, al que no le guste que no mire xDDD Sinceramente, diseñar interfaces con netbeans es mas rapido y ahorra tiempo de programacion, y mas os aseguro que antes programaba interfaces con la clase Swing y era un toston. Bueno disfrutadlo ^^ Saludos
|
|
|
117
|
Programación / Java / Problema de construcion de tabla
|
en: 17 Noviembre 2009, 18:29 pm
|
Hola a todos, tengo una duda existencial (con la de cosas chungas que he pasado y me quedo aqui XDD) Bueno mirad, os explico, he hecho un programita en java que hace graficas a partir de funciones, y lecturas en un db, la cosa es que doy la opcion de mostrarlo en forma de grafica y en forma de tabla de valores, la cosa esta en que la tabla de valores, se jode cuando hay un numero de mas de 1 una cifra, observad vosotros: X | f(X) _______|__________ 1 | 200 2 | 45 3 | 215 4 | 80 5 | 80 6 | 50 7 | 30 8 | 35 9 | 40 10 | 40 11 | 40 12 | 100 13 | 400
Esta desalineada, asi que no sale bien, y no se en que estoy fallando :s Mirad el codigo que genera la tabla de valores: public static void getDatos(){ String sql = "Select x as meses, y as sesion from sesiones"; try{ statement = con.createStatement(); rs= statement.executeQuery(sql); System. out. println(" X | f(X) "); System. out. println(" _______|__________"); while(rs.next()) System. out. println(" "+rs. getInt(1)+" "+"| "+" "+rs. getInt(2)); rs.close(); System. err. println("Error: "+e ); } }
Haber si me podeis orientar un poco. Saludos a todos!
|
|
|
118
|
Programación / Java / Problema con JFreeChart
|
en: 16 Noviembre 2009, 19:24 pm
|
Hola todos, he compuesto el siguiente codigo: package ventana; import java.awt.Frame; import org.jfree.data.*; import org.jfree.chart.*; import org.jfree.chart.plot.*; import java.awt.image.*; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.jdbc.JDBCCategoryDataset; import org.jfree.data.jdbc.JDBCXYDataset; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import java.sql.*; /** * * @author Administrador */ public class VentanaGrafica extends java. awt. Frame { /** Creates new form VentanaGrafica */ public VentanaGrafica() { super("Ejemplos usando JFreeChart."); initComponents(); } // <editor-fold defaultstate="collapsed" desc=" Generated Code "> private void initComponents() { public void windowClosing (java. awt. event. WindowEvent evt ) { exitForm(evt); } }); pack(); } // </editor-fold> /** Exit the Application */ private void exitForm (java. awt. event. WindowEvent evt ) { } // Variables declaration - do not modify // End of variables declaration try{ String sql = "Select x as meses, y as ventas from sesiones"; JDBCXYDataset xyDataset = new JDBCXYDataset(con,sql); JFreeChart chart = ChartFactory.createLineChart("Grafica de Ventas", "Meses","Ventas %",(CategoryDataset) xyDataset,PlotOrientation.VERTICAL, true, true, true // Show legend ); //JFreeChart chart1 = ChartFactory. image = chart.createBufferedImage(600,400); return image; System. err. println("Error al obtener datos de la BDD: "+e ); } return image; } public void paint (java. awt. Graphics g ) { if(grafica == null) { grafica = this.creaImagen(Conexion.con); } g.drawImage(grafica,40,80,null); } }
Pero al ejecutarlo, me salta un error, y no me crea la grafica, asi que os pongo el error que tira: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: org.jfree.data.jdbc.JDBCXYDataset cannot be cast to org.jfree.data.category.CategoryDataset at ventana.VentanaGrafica.creaImagen(VentanaGrafica.java:65) at ventana.VentanaGrafica.paint(VentanaGrafica.java:82) at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248) at sun.awt.X11.XRepaintArea.paintComponent(XRepaintArea.java:56) at sun.awt.RepaintArea.paint(RepaintArea.java:224) at sun.awt.X11.XComponentPeer.handleEvent(XComponentPeer.java:688) at java.awt.Component.dispatchEventImpl(Component.java:4706) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Window.dispatchEventImpl(Window.java:2475) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) Java Result: 1 GENERACIÓN CORRECTA (total time: 29 seconds)
|
|
|
119
|
Programación / Java / 2o Problema, encriptador con GUI
|
en: 15 Noviembre 2009, 17:39 pm
|
HOla a todos, antes encontré una clase que encriptaba texto y le hice una gui, la cosa es que la gui cifra bien, pero no descifra! Codigo de la gui: package main; /** * * @author debci */ import encriptador.*; public class Main extends javax. swing. JFrame { public static String contraseñaEncriptada ; /** Creates new form Main */ public Main() { 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(); jLabel2 = new javax. swing. JLabel(); btnEncriptar = new javax. swing. JButton(); contraseEncr = new javax. swing. JLabel(); jLabel3 = new javax. swing. JLabel(); jPanel2 = new javax. swing. JPanel(); btnDesencriptar = new javax. swing. JButton(); jLabel4 = new javax. swing. JLabel(); jLabel5 = new javax. swing. JLabel(); jLabel6 = new javax. swing. JLabel(); clavedesencriptada = new javax. swing. JLabel(); jMenu1 = new javax. swing. JMenu(); jMenu2 = new javax. swing. JMenu(); setTitle("Encriptador Basico"); jLabel1.setText("Introduzca el texto que desea cifrar:"); jLabel2.setText("Introduzca la clave de cifrado:"); btnEncriptar.setText("cifrar"); public void actionPerformed (java. awt. event. ActionEvent evt ) { btnEncriptarActionPerformed(evt); } }); contraseEncr.setText("Contraseña cifrada"); contraseEncr.setToolTipText("Contraseña cifrada"); jLabel3.setText("Contraseña cifrada:"); 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() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(textoIntroducido, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2) .addComponent(claveIntroducida, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addComponent(contraseEncr) . addPreferredGap(javax. swing. LayoutStyle. ComponentPlacement. RELATED, 47, Short. MAX_VALUE) .addComponent(btnEncriptar)) .addComponent(jLabel3)) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(textoIntroducido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jLabel2) .addGap(7, 7, 7) .addComponent(claveIntroducida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel3) . addPreferredGap(javax. swing. LayoutStyle. ComponentPlacement. RELATED, javax. swing. GroupLayout. DEFAULT_SIZE, Short. MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnEncriptar) .addComponent(contraseEncr)) .addContainerGap()) ); contraseEncr.getAccessibleContext().setAccessibleParent(this); jTabbedPane1.addTab("cifrar", jPanel1); btnDesencriptar.setText("descifrar"); btnDesencriptar. addActionListener(new java. awt. event. ActionListener() { public void actionPerformed (java. awt. event. ActionEvent evt ) { btnDesencriptarActionPerformed(evt); } }); jLabel4.setText("Clave cifrada:"); jLabel5.setText("Clave de descifrado:"); jLabel6.setText("La clave descifrada es:"); clavedesencriptada.setText("Clave descifrada"); 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() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel4) . addContainerGap(167, Short. MAX_VALUE)) .addGroup(jPanel2Layout.createSequentialGroup() . addComponent(entradaHash, javax. swing. GroupLayout. DEFAULT_SIZE, 191, Short. MAX_VALUE) .addGap(87, 87, 87)) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel5) . addContainerGap(124, Short. MAX_VALUE)) .addGroup(jPanel2Layout.createSequentialGroup() . addComponent(entradaClave, javax. swing. GroupLayout. DEFAULT_SIZE, 191, Short. MAX_VALUE) .addGap(87, 87, 87)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addComponent(clavedesencriptada) . addPreferredGap(javax. swing. LayoutStyle. ComponentPlacement. RELATED, 50, Short. MAX_VALUE) .addComponent(btnDesencriptar)) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel6) . addContainerGap(108, Short. MAX_VALUE)))) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(entradaHash, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(entradaClave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel6) .addGap(7, 7, 7) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnDesencriptar) .addComponent(clavedesencriptada)) .addContainerGap()) ); jTabbedPane1.addTab("descifrar", jPanel2); jMenu1.setText("Archivo"); jMenuBar1.add(jMenu1); jMenu2.setText("Acerca de..."); public void actionPerformed (java. awt. event. ActionEvent evt ) { jMenu2ActionPerformed(evt); } }); jMenuItem1.setText("Ver creditos del programa"); public void actionPerformed (java. awt. event. ActionEvent evt ) { jMenuItem1ActionPerformed(evt); } }); jMenu2.add(jMenuItem1); jMenuBar1.add(jMenu2); 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(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE) . addContainerGap(javax. swing. GroupLayout. DEFAULT_SIZE, Short. MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING) ); pack(); }// </editor-fold> private void jMenu2ActionPerformed (java. awt. event. ActionEvent evt ) { } private void jMenuItem1ActionPerformed (java. awt. event. ActionEvent evt ) { Acerca acerca = new Acerca(); acerca.setVisible(true); } private void btnEncriptarActionPerformed (java. awt. event. ActionEvent evt ) { String palabraNormal = textoIntroducido. getText(); String ClaveIntroducida = claveIntroducida. getText(); encriptador encriptador = new encriptador(); contraseñaEncriptada = encriptador.codificar(palabraNormal, ClaveIntroducida).trim(); contraseEncr.setText(contraseñaEncriptada); contraseEncr.setVisible(true); } private void btnDesencriptarActionPerformed (java. awt. event. ActionEvent evt ) { String hashIntroducido = entradaHash. getText(); String claveDesencriptadora = entradaClave. getText(); entradaHash.setText(contraseñaEncriptada); encriptador encriptador = new encriptador(); String claveDesencriptadaLimpia = encriptador. decodificar(hashIntroducido ); clavedesencriptada.setText(claveDesencriptadaLimpia); } /** * @param args the command line arguments */ public static void main (String args []) { public void run() { new Main().setVisible(true); contraseEncr.setVisible(false); clavedesencriptada.setVisible(false); } }); } // Variables declaration - do not modify private javax. swing. JButton btnDesencriptar ; private javax. swing. JButton btnEncriptar ; private static javax. swing. JLabel clavedesencriptada ; private static javax. swing. JLabel contraseEncr ; 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. JMenu jMenu1 ; private javax. swing. JMenu jMenu2 ; private javax. swing. JPanel jPanel1 ; private javax. swing. JPanel jPanel2 ; // End of variables declaration }
Codigo de la clase encriptadora: import java.io.BufferedReader; import java.io.InputStreamReader; /** * * @author debci */ public class encriptador { //instance private String claveOriginal =""; private String textoOriginal =""; private String claveActual =""; private char[][] matriz; //reader //methods int repeticiones=0; int jSize= claveActual.length(); while (repeticiones<jSize) { boolean cambio=false; int i=repeticiones; claveActual=""; for (int j=0; j<jSize;j++) claveActual=claveActual+matriz[0][j]; while ((!cambio)&&(i<jSize)) { if (claveOriginal.charAt(repeticiones)==claveActual.charAt(i)){ modificarArreglo(i,repeticiones); cambio=!cambio; } else i++; } repeticiones++; } for (int i=1; i<matriz.length;i++) for (int j=0; j<matriz[0].length;j++) output=output + matriz[i][j]; return output; } claveOriginal=clave; textoOriginal=texto; int jSize= claveOriginal.length(); int iSize= (textoOriginal.length()/jSize)+1; if ((textoOriginal.length()%jSize)!=0) iSize++; System. out. println("Filas :" + iSize + " Columnas: "+jSize ); matriz= new char[iSize][jSize]; int charPos=0; int keyPos=0; for (int i=0; i<claveOriginal.length();i++) { matriz[0][i]=claveOriginal.charAt(i); } for (int i=1; i<iSize;i++) { for (int j=0;j<jSize;j++) { try { matriz[i][j]=textoOriginal.charAt(charPos); charPos++; } catch (Exception e ) {matriz [i ][j ]=' '; charPos ++;} } } /*debug for (int i=0; i<iSize;i++) { for (int j=0; j<jSize;j++) { System.out.print(matriz[i][j]); } } */ int repeticiones=0; while (repeticiones<jSize) { char[] filaCero= new char[jSize-repeticiones]; for (int j=repeticiones; j<jSize; j++) { filaCero[j-repeticiones]=matriz[0][j]; } int i=0; boolean cambio=false; //tamaño de filaCero while ((i<jSize-repeticiones)&&(!cambio)){ if (esElMenor(filaCero,filaCero[i])){ modificarArreglo(i+repeticiones,repeticiones); cambio=!cambio; } i++; } repeticiones++; } /*debug for (int i=0; i<iSize;i++) { for (int j=0; j<jSize;j++) { System.out.print(matrizAuxiliar[i][j]); } } */ for (int j=0; j<jSize;j++) { for (int i=0; i<iSize;i++) { if (i==0) claveActual=claveActual + matriz[i][j]; output=output+matriz[i][j]; } } return output; /*debug for (int j=0; j<jSize;j++) { for (int i=0; i<iSize;i++) { System.out.print(matrizFinal[j][i]); } System.out.println(); } */ } public void modificarArreglo(int colActual, int rep) { //intercambia las columnas que pasan como param /*for (int i=0; i<matriz.length;i++) matrizAuxiliar[i][rep]=matriz[i][colActual];*/ char[]aux = new char[matriz.length]; for (int i=0; i<matriz.length;i++){ aux[i]=matriz[i][rep]; matriz[i][rep]=matriz[i][colActual]; matriz[i][colActual]=aux[i]; } } public boolean esElMenor(char[] arreglo, char car) { boolean menor=true; //asume que es el menor. int i =0; if (car==' ') menor = false; else { while ((i<arreglo.length)&&(menor)) { if ((arreglo[i]!=' ')&&(car!=' ')&&(arreglo[i]<car)) menor=!menor; else i++; } } return menor; }
Al introducir una clave de descifrado falla, la cosa es que la clase de encriptacion no trae un argumento concreto, es decir hay que itnroducir una palabra pero no la clave de cifrado, asi que ya me dirán que hago XDDDD Saludos
|
|
|
120
|
Seguridad Informática / Nivel Web / Problema con XSS
|
en: 15 Noviembre 2009, 15:18 pm
|
Hola amigos, he llegado a la conclusion, por scaner, de que un servidor es vulnerable a injecion html, me dice que ejecute lo siguiente: /k4KX2kZIUbAKEoyVDYVni3REhNfDl2MZJ69toj5WOCSLG9JQadQWH2HdZ9vrxAD01LvJIivIdZhLcEJUBddfBVi0tGWNFa0P3F4NsgtePjkC8vDbf3DmKfmlyYeBmhJvMiVNtjv0yVmNqkx7V5HHIbs0o59lMP4i2DgQPc0H94Pf0ROFuXFMwJHiI7LUluaVrViT29otAu5hXvq3H27e15TBX2fyMjP<font%20size=50>DEFACED<!--//--: MyWebServer 1.0.2 is vulnerable to HTML injection como directorio (supongo), pero al ejecutarlo obetngo lo siguiente: Forbidden
You don't have permission to access /k4KX2kZIUbAKEoyVDYVni3REhNfDl2MZJ69toj5WOCSLG9JQadQWH2HdZ9vrxAD01LvJIivIdZhLcEJUBddfBVi0tGWNFa0P3F4NsgtePjkC8vDbf3DmKfmlyYeBmhJvMiVNtjv0yVmNqkx7V5HHIbs0o59lMP4i2DgQPc0H94Pf0ROFuXFMwJHiI7LUluaVrViT29otAu5hXvq3H27e15TBX2fyMjP<font size=50>DEFACED<!--//--: MyWebServer 1.0.2 is vulnerable to HTML injection on this server. Apache/2.2.8 (Win32) PHP/5.2.6 Server at *****.com Port 80
que estoy haciendo mal? ES uno de los conocidos fallos del servidor? Saludos
|
|
|
|
|
|
|