thieumao

MD5 Decrypter tool 1.0 - Thieu Mao

Aug 14th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.70 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package demo;
  6.  
  7. import java.math.BigInteger;
  8. import java.security.MessageDigest;
  9. import java.security.NoSuchAlgorithmException;
  10. import javax.swing.JOptionPane;
  11.  
  12. /**
  13.  *
  14.  * @author Thieu Mao
  15.  */
  16. public class demoMD5 extends javax.swing.JFrame {
  17.  
  18.     /**
  19.      * Creates new form demoMD5
  20.      */
  21.     public demoMD5() {
  22.         initComponents();
  23.     }
  24.  
  25.     /**
  26.      * This method is called from within the constructor to initialize the form.
  27.      * WARNING: Do NOT modify this code. The content of this method is always
  28.      * regenerated by the Form Editor.
  29.      */
  30.     @SuppressWarnings("unchecked")
  31.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  32.     private void initComponents() {
  33.  
  34.         tfInput = new javax.swing.JTextField();
  35.         tfOutput = new javax.swing.JTextField();
  36.         jLabel1 = new javax.swing.JLabel();
  37.         jLabel2 = new javax.swing.JLabel();
  38.         jLabel3 = new javax.swing.JLabel();
  39.         cbbType = new javax.swing.JComboBox();
  40.         jLabel4 = new javax.swing.JLabel();
  41.         jLabel5 = new javax.swing.JLabel();
  42.         cbbNumber = new javax.swing.JComboBox();
  43.         btStart = new javax.swing.JButton();
  44.         jButton2 = new javax.swing.JButton();
  45.         jMenuBar1 = new javax.swing.JMenuBar();
  46.         jMenu1 = new javax.swing.JMenu();
  47.         jMenuItem1 = new javax.swing.JMenuItem();
  48.         jMenu2 = new javax.swing.JMenu();
  49.         jMenuItem2 = new javax.swing.JMenuItem();
  50.  
  51.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  52.  
  53.         jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
  54.         jLabel1.setText("MD5 Decrypter tool");
  55.  
  56.         jLabel2.setText("Input");
  57.  
  58.         jLabel3.setText("Output");
  59.  
  60.         cbbType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "a b c", "A B C", "1 2 3", "! @ #", "All" }));
  61.  
  62.         jLabel4.setText("Type");
  63.  
  64.         jLabel5.setText("Number");
  65.  
  66.         cbbNumber.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9" }));
  67.  
  68.         btStart.setText("Start");
  69.         btStart.addActionListener(new java.awt.event.ActionListener() {
  70.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  71.                 btStartActionPerformed(evt);
  72.             }
  73.         });
  74.  
  75.         jButton2.setText("btClear");
  76.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  77.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  78.                 jButton2ActionPerformed(evt);
  79.             }
  80.         });
  81.  
  82.         jMenu1.setText("File");
  83.  
  84.         jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.ALT_MASK));
  85.         jMenuItem1.setText("Exit");
  86.         jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
  87.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  88.                 jMenuItem1ActionPerformed(evt);
  89.             }
  90.         });
  91.         jMenu1.add(jMenuItem1);
  92.  
  93.         jMenuBar1.add(jMenu1);
  94.  
  95.         jMenu2.setText("Help");
  96.  
  97.         jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
  98.         jMenuItem2.setText("About");
  99.         jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
  100.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  101.                 jMenuItem2ActionPerformed(evt);
  102.             }
  103.         });
  104.         jMenu2.add(jMenuItem2);
  105.  
  106.         jMenuBar1.add(jMenu2);
  107.  
  108.         setJMenuBar(jMenuBar1);
  109.  
  110.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  111.         getContentPane().setLayout(layout);
  112.         layout.setHorizontalGroup(
  113.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  114.             .addGroup(layout.createSequentialGroup()
  115.                 .addGap(52, 52, 52)
  116.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  117.                     .addComponent(jLabel2)
  118.                     .addComponent(jLabel3)
  119.                     .addComponent(jLabel4))
  120.                 .addGap(34, 34, 34)
  121.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  122.                     .addComponent(tfInput)
  123.                     .addComponent(tfOutput)
  124.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  125.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  126.                             .addComponent(cbbType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  127.                             .addComponent(btStart))
  128.                         .addGap(89, 89, 89)
  129.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  130.                             .addGroup(layout.createSequentialGroup()
  131.                                 .addComponent(jLabel5)
  132.                                 .addGap(65, 65, 65)
  133.                                 .addComponent(cbbNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  134.                             .addComponent(jButton2))
  135.                         .addGap(0, 96, Short.MAX_VALUE)))
  136.                 .addContainerGap())
  137.             .addGroup(layout.createSequentialGroup()
  138.                 .addGap(194, 194, 194)
  139.                 .addComponent(jLabel1)
  140.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  141.         );
  142.         layout.setVerticalGroup(
  143.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  144.             .addGroup(layout.createSequentialGroup()
  145.                 .addGap(20, 20, 20)
  146.                 .addComponent(jLabel1)
  147.                 .addGap(18, 18, 18)
  148.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  149.                     .addComponent(tfInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  150.                     .addComponent(jLabel2))
  151.                 .addGap(29, 29, 29)
  152.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  153.                     .addComponent(tfOutput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  154.                     .addComponent(jLabel3))
  155.                 .addGap(26, 26, 26)
  156.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  157.                     .addComponent(jLabel4)
  158.                     .addComponent(cbbType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  159.                     .addComponent(jLabel5)
  160.                     .addComponent(cbbNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  161.                 .addGap(44, 44, 44)
  162.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  163.                     .addComponent(jButton2)
  164.                     .addComponent(btStart))
  165.                 .addContainerGap(27, Short.MAX_VALUE))
  166.         );
  167.  
  168.         pack();
  169.     }// </editor-fold>                        
  170.  
  171.     private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  172.         JOptionPane.showMessageDialog(null, "Bye bye...");
  173.         System.exit(0);
  174.     }                                          
  175.  
  176.     private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  177.         JOptionPane.showMessageDialog(null, "Author: Thieu Mao - KSEC");
  178.     }                                          
  179.  
  180.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  181.         tfInput.setText("");
  182.         tfOutput.setText("");
  183.     }                                        
  184.  
  185.     private void btStartActionPerformed(java.awt.event.ActionEvent evt) {                                        
  186.         String strInput = tfInput.getText().toString();
  187.         int iNumber = cbbNumber.getSelectedIndex() + 1;
  188.         int iType = cbbType.getSelectedIndex();
  189.         String kq = "";
  190.         if (iType == 0) {
  191.             System.out.println("a b c");
  192.             kq = tim(strInput,iNumber, 'a', 'z');
  193.         }
  194.         if (iType == 1) {
  195.             System.out.println("A B C");
  196.             kq = tim(strInput,iNumber, 'A', 'Z');
  197.         }
  198.         if (iType == 2) {
  199.             System.out.println("0 1 2");
  200.             kq = tim(strInput,iNumber, '0', '9');
  201.         }
  202.         if (iType == 3) {
  203.             System.out.println("! @ #");
  204.             kq = tim(strInput,iNumber, ' ', '@');
  205.         }
  206.         if (iType == 4) {
  207.             System.out.println("All");
  208.             kq = tim(strInput,iNumber, ' ', '~');
  209.         }
  210.         if (!kq.isEmpty()) {
  211.             System.out.println("Ket qua: " + kq);
  212.             tfOutput.setText(kq);
  213.             JOptionPane.showMessageDialog(null, "Success --> " + kq);
  214.         } else {
  215.             System.out.println("Khong tim thay");
  216.             JOptionPane.showMessageDialog(null, "Failure...");
  217.         }
  218.     }                                      
  219.  
  220.     /**
  221.      * @param args the command line arguments
  222.      */
  223.     public static void main(String args[]) {
  224.         /* Set the Nimbus look and feel */
  225.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  226.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  227.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  228.          */
  229.         try {
  230.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  231.                 if ("Nimbus".equals(info.getName())) {
  232.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  233.                     break;
  234.                 }
  235.             }
  236.         } catch (ClassNotFoundException ex) {
  237.             java.util.logging.Logger.getLogger(demoMD5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  238.         } catch (InstantiationException ex) {
  239.             java.util.logging.Logger.getLogger(demoMD5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  240.         } catch (IllegalAccessException ex) {
  241.             java.util.logging.Logger.getLogger(demoMD5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  242.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  243.             java.util.logging.Logger.getLogger(demoMD5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  244.         }
  245.         //</editor-fold>
  246.  
  247.         /* Create and display the form */
  248.         java.awt.EventQueue.invokeLater(new Runnable() {
  249.             public void run() {
  250.                 new demoMD5().setVisible(true);
  251.             }
  252.         });
  253.     }
  254.  
  255.     private static String tim(String dich, int n, char chStart, char chEnd) {
  256.         char a[] = new char[n];
  257.         int last = 0;
  258.         String str = "";
  259.  
  260.         for (int i = 0; i < n; i++) {
  261.             a[i] = chStart;
  262.         }
  263.  
  264.         while (last < n) {
  265.             // in ra dãy bit
  266.             str = "";
  267.             for (int i = 0; i < n; i++) {
  268.                 str += String.valueOf(a[i]);
  269.             }
  270.             if (encryptMD5(str).equals(dich)) {
  271. //                System.out.println(str);
  272.                 return str;
  273.             }
  274. //            System.out.print(str);
  275.  
  276.             // nếu bit ở vị trí last chuyển thành z thì nhảy lên một bước.
  277.             if (a[last] == chEnd) {
  278.                 last += 1;
  279.             }
  280.  
  281.             for (int i = n - 1; i >= 0; i--) {
  282.                 if (a[i] != chEnd) {
  283.                     a[i]++;
  284.                     break;
  285.                 } else {
  286.                     a[i] = chStart;
  287.                 }
  288.             }
  289.         }
  290.         return "";
  291.     }
  292.  
  293.     private static String encryptMD5(String input) {
  294.         try {
  295.             MessageDigest md = MessageDigest.getInstance("MD5");
  296.             byte[] messageDigest = md.digest(input.getBytes());
  297.             BigInteger number = new BigInteger(1, messageDigest);
  298.             String hashtext = number.toString(16);
  299.             while (hashtext.length() < 32) {
  300.                 hashtext = "0" + hashtext;
  301.             }
  302.             return hashtext;
  303.         } catch (NoSuchAlgorithmException e) {
  304.             throw new RuntimeException(e);
  305.         }
  306.     }
  307.     // Variables declaration - do not modify                    
  308.     private javax.swing.JButton btStart;
  309.     private javax.swing.JComboBox cbbNumber;
  310.     private javax.swing.JComboBox cbbType;
  311.     private javax.swing.JButton jButton2;
  312.     private javax.swing.JLabel jLabel1;
  313.     private javax.swing.JLabel jLabel2;
  314.     private javax.swing.JLabel jLabel3;
  315.     private javax.swing.JLabel jLabel4;
  316.     private javax.swing.JLabel jLabel5;
  317.     private javax.swing.JMenu jMenu1;
  318.     private javax.swing.JMenu jMenu2;
  319.     private javax.swing.JMenuBar jMenuBar1;
  320.     private javax.swing.JMenuItem jMenuItem1;
  321.     private javax.swing.JMenuItem jMenuItem2;
  322.     private javax.swing.JTextField tfInput;
  323.     private javax.swing.JTextField tfOutput;
  324.     // End of variables declaration                  
  325. }
Advertisement
Add Comment
Please, Sign In to add comment