tzanany

Ort Password Algorithem

Dec 16th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import java.util.Date;
  2. import java.util.Random;
  3.  
  4. public class TimeChacker {
  5.       private static Random random = new Random((new Date()).getTime());
  6.  
  7.         public static String generateRandomString(int length) {
  8.           char[] values = {'a','b','c','d','e','f','g','h','i','j',
  9.                    'k','l','m','n','o','p','q','r','s','t',
  10.                    'u','v','w','x','y','z'};
  11.  
  12.           String out = "";
  13.  
  14.           for (int i=0;i<length;i++) {
  15.               int idx=random.nextInt(values.length);
  16.             out += values[idx];
  17.           }
  18.  
  19.           return out;
  20.         }
  21.  
  22.     public static String formatInt(int n, int digits) {
  23.         /*
  24.               we create a format :
  25.                %% : %  the first % is to escape the second %
  26.                0  : 0  zero character
  27.                %d :    how many '0' we want (specified by digits)
  28.                d  : d  the number to format
  29.        
  30.         */
  31.         String format = String.format("%%0%dd", digits);
  32.         return String.format(format, n);
  33.  
  34.     }
  35.     public static void main(String[] args) {
  36.         // TODO Auto-generated method stub
  37.         int result=0;
  38.         String pass = "";
  39.         int tries=0;
  40.         Random numbers = new Random();
  41.         while(pass!="abc1234"){
  42.             result = numbers.nextInt(9999);
  43.             pass = generateRandomString(3) + formatInt(result, 4);
  44.             tries++;
  45.             System.out.println(pass);
  46.         }
  47.         System.out.println("There Was: " + tries + "Tries");
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment