sudoaptinstallname

brute3

Feb 18th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 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_V3 {
  7.     public String main() {
  8.  
  9.         {
  10.             //Generates dictionary
  11.             String diction = "";
  12.             for (int x = 32; x < 126; x++)//32,126 for full or 97,123 for just lowercase
  13.             {
  14.                 diction = diction + (char) x;
  15.             }
  16.  
  17.             //Input target string.
  18.             System.out.print("Input String: ");
  19.             Scanner input = new Scanner(System.in);
  20.             String word = input.nextLine();
  21.  
  22.             //Declarations.
  23.             int count = 0;
  24.             Random rand = new Random();
  25.             String dictiontemp = diction;
  26.             String letter;
  27.             boolean isEqual;
  28.             String output = "";
  29.  
  30.             //Generate output
  31.             for (int z = 0; z < word.length(); z++) {
  32.                 do {
  33.                     int a = rand.nextInt((dictiontemp.length()));
  34.                     System.out.println();
  35.                     System.out.println("Number: " + a);
  36.                     System.out.println("TARGET: " + word.substring(z, z + 1));
  37.                     System.out.println();
  38.                     letter = String.valueOf(dictiontemp.charAt(a));
  39.                     dictiontemp = dictiontemp.substring(0, a) + dictiontemp.substring(a + 1);
  40.                     //Neat way of modifying temporary dictionary. Strings can't be edited but this tecnically works.
  41.                     count++;
  42.                     System.out.println(output + letter);
  43.                     System.out.println();
  44.                     System.out.println(dictiontemp);
  45.                     System.out.println();
  46.                     isEqual = letter.equals(word.substring(z, z + 1));
  47.                 }
  48.                 while (!isEqual);
  49.                 output = output + letter;
  50.                 dictiontemp = diction;
  51.             }
  52.  
  53.             System.out.print(output);
  54.             System.out.println();
  55.             System.out.println(count + " Iterations");
  56.             //count represents how many attempts were made.
  57.  
  58.  
  59.         }
  60.         return ("");
  61.     }
  62. }
Add Comment
Please, Sign In to add comment