sudoaptinstallname

brute2.java

Feb 18th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class Brute_Diction_V2 {
  7.     public String main() {
  8.     {
  9.  
  10.  
  11.         System.out.print("Input a single character: ");
  12.         Scanner input = new Scanner(System.in);
  13.         String word = input.nextLine();
  14.  
  15.  
  16.         //Generates dictionary
  17.         String diction = "";
  18.         for(int x = 32; x<126; x++)//32,126 for full or 97,123 for just lowercase
  19.         {
  20.             diction = diction+(char)x;
  21.         }
  22.  
  23.         String dictionfull = "";
  24.         int bound = 0;
  25.         for(int x = 0; x<word.length(); x++)
  26.         {
  27.             dictionfull =dictionfull+diction;
  28.             bound++;
  29.         }
  30.         System.out.println("BOUND: "+bound);
  31.         System.out.println(dictionfull);
  32.         int count = 0;
  33.         String temp;
  34.         char[] current = new char[word.length()];
  35.         Random rand = new Random();
  36.         int x;
  37.         int y;
  38.  
  39.         do {
  40.             for (x = 0; x < word.length(); x++)
  41.             {
  42.                 if (current[x] != word.charAt(x))
  43.                 {
  44. //                    int z = rand.nextInt((diction.length())+(diction.length()*(bound-1)));
  45.                     int z = rand.nextInt((dictionfull.length()));
  46.                     current[x] = dictionfull.charAt(z);
  47.                     dictionfull = dictionfull.substring(0,z)+dictionfull.substring(z+1);
  48.                 }
  49.                 else
  50.                 {
  51.                     diction = "";
  52.                     for(int p = 97; p<123; p++)//32,126 for full or 97,123 for just lowercase
  53.                     {
  54.                         diction = diction+(char)x;
  55. //                        System.out.println("MAERSK  "+(char)x);
  56.                     }
  57.                 }
  58.             }
  59.             temp ="";
  60.             for (y = 0; y<current.length; y++)
  61.                 temp+=current[y];
  62.             System.out.println(temp);
  63.             count++;
  64.             System.out.println();
  65.             System.out.println(dictionfull);
  66.             System.out.println();
  67.         }
  68.         while (!temp.equals(word));
  69.         System.out.println();
  70.         System.out.println("Output: "+temp);
  71.         System.out.println();
  72.         System.out.println(count+" Iterations");
  73.         System.out.println();
  74.         System.out.println("Unused Characters: "+dictionfull);
  75.  
  76.     }
  77.     return("");
  78. }
  79. }
Add Comment
Please, Sign In to add comment