Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package demo;
- import java.math.BigInteger;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import javax.swing.JOptionPane;
- /**
- *
- * @author leo
- */
- public class mahoa2lanMD5 extends javax.swing.JFrame {
- /**
- * Creates new form demoMD5
- */
- public mahoa2lanMD5() {
- 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() {
- tfInput = new javax.swing.JTextField();
- tfOutput = new javax.swing.JTextField();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- cbbType = new javax.swing.JComboBox();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- cbbNumber = new javax.swing.JComboBox();
- btStart = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jMenuBar1 = new javax.swing.JMenuBar();
- jMenu1 = new javax.swing.JMenu();
- jMenuItem1 = new javax.swing.JMenuItem();
- jMenu2 = new javax.swing.JMenu();
- jMenuItem2 = new javax.swing.JMenuItem();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
- jLabel1.setText("MD5 Decrypter tool");
- jLabel2.setText("Input");
- jLabel3.setText("Output");
- cbbType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "a b c", "A B C", "1 2 3", "! @ #", "All" }));
- jLabel4.setText("Type");
- jLabel5.setText("Number");
- cbbNumber.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9" }));
- btStart.setText("Start");
- btStart.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btStartActionPerformed(evt);
- }
- });
- jButton2.setText("btClear");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jMenu1.setText("File");
- jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.ALT_MASK));
- jMenuItem1.setText("Exit");
- jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem1ActionPerformed(evt);
- }
- });
- jMenu1.add(jMenuItem1);
- jMenuBar1.add(jMenu1);
- jMenu2.setText("Help");
- jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
- jMenuItem2.setText("About");
- jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem2ActionPerformed(evt);
- }
- });
- jMenu2.add(jMenuItem2);
- 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()
- .addGap(52, 52, 52)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2)
- .addComponent(jLabel3)
- .addComponent(jLabel4))
- .addGap(34, 34, 34)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(tfInput)
- .addComponent(tfOutput)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(cbbType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(btStart))
- .addGap(89, 89, 89)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel5)
- .addGap(65, 65, 65)
- .addComponent(cbbNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(jButton2))
- .addGap(0, 96, Short.MAX_VALUE)))
- .addContainerGap())
- .addGroup(layout.createSequentialGroup()
- .addGap(194, 194, 194)
- .addComponent(jLabel1)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(20, 20, 20)
- .addComponent(jLabel1)
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(tfInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel2))
- .addGap(29, 29, 29)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(tfOutput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel3))
- .addGap(26, 26, 26)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel4)
- .addComponent(cbbType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel5)
- .addComponent(cbbNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(44, 44, 44)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton2)
- .addComponent(btStart))
- .addContainerGap(27, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
- JOptionPane.showMessageDialog(null, "Bye bye...");
- System.exit(0);
- }
- private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
- JOptionPane.showMessageDialog(null, "Author: Thieu Mao - KSEC");
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- tfInput.setText("");
- tfOutput.setText("");
- }
- private void btStartActionPerformed(java.awt.event.ActionEvent evt) {
- String strInput = tfInput.getText().toString();
- int iNumber = cbbNumber.getSelectedIndex() + 1;
- int iType = cbbType.getSelectedIndex();
- String kq = "";
- if (iType == 0) {
- System.out.println("a b c");
- kq = tim(strInput,iNumber, 'a', 'z');
- }
- if (iType == 1) {
- System.out.println("A B C");
- kq = tim(strInput,iNumber, 'A', 'Z');
- }
- if (iType == 2) {
- System.out.println("0 1 2");
- kq = tim(strInput,iNumber, '0', '9');
- }
- if (iType == 3) {
- System.out.println("! @ #");
- kq = tim(strInput,iNumber, ' ', '@');
- }
- if (iType == 4) {
- System.out.println("All");
- kq = tim(strInput,iNumber, ' ', '~');
- }
- if (!kq.isEmpty()) {
- System.out.println("Ket qua: " + kq);
- tfOutput.setText(kq);
- JOptionPane.showMessageDialog(null, "Success --> " + kq);
- } else {
- System.out.println("Khong tim thay");
- JOptionPane.showMessageDialog(null, "Failure...");
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(mahoa2lanMD5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(mahoa2lanMD5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(mahoa2lanMD5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(mahoa2lanMD5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new mahoa2lanMD5().setVisible(true);
- }
- });
- }
- private static String tim(String dich, int n, char chStart, char chEnd) {
- char a[] = new char[n];
- int last = 0;
- String str = "";
- for (int i = 0; i < n; i++) {
- a[i] = chStart;
- }
- while (last < n) {
- // in ra dãy bit
- str = "";
- for (int i = 0; i < n; i++) {
- str += String.valueOf(a[i]);
- }
- if (encryptMD5(encryptMD5(str)).equals(dich)) {
- // System.out.println(str);
- return str;
- }
- // System.out.print(str);
- // nếu bit ở vị trí last chuyển thành z thì nhảy lên một bước.
- if (a[last] == chEnd) {
- last += 1;
- }
- for (int i = n - 1; i >= 0; i--) {
- if (a[i] != chEnd) {
- a[i]++;
- break;
- } else {
- a[i] = chStart;
- }
- }
- }
- return "";
- }
- private static String encryptMD5(String input) {
- try {
- MessageDigest md = MessageDigest.getInstance("MD5");
- byte[] messageDigest = md.digest(input.getBytes());
- BigInteger number = new BigInteger(1, messageDigest);
- String hashtext = number.toString(16);
- while (hashtext.length() < 32) {
- hashtext = "0" + hashtext;
- }
- return hashtext;
- } catch (NoSuchAlgorithmException e) {
- throw new RuntimeException(e);
- }
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btStart;
- private javax.swing.JComboBox cbbNumber;
- private javax.swing.JComboBox cbbType;
- private javax.swing.JButton jButton2;
- 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.JMenu jMenu1;
- private javax.swing.JMenu jMenu2;
- private javax.swing.JMenuBar jMenuBar1;
- private javax.swing.JMenuItem jMenuItem1;
- private javax.swing.JMenuItem jMenuItem2;
- private javax.swing.JTextField tfInput;
- private javax.swing.JTextField tfOutput;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment