Advertisement
sudoaptinstallname

brute1.java

Feb 18th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.*;
  4. import java.util.Scanner;
  5.  
  6. public class helloWorld {
  7. //    public static void main(String [] args)
  8.  
  9.         public String main() {
  10.  
  11.  
  12.         System.out.print("Input String: ");
  13.         Scanner input = new Scanner(System.in);
  14.         String word = input.nextLine();
  15.         //inputs string
  16.  
  17.  
  18.         int count = 0;
  19.         String temp;
  20.         char[] current = new char[word.length()];
  21.         Random rand = new Random();
  22.         int x;
  23.         int y;
  24.         do {
  25.             for (x = 0; x < word.length(); x++) {
  26.                 if (current[x] != word.charAt(x)) {
  27.                     current[x] = (char) (rand.nextInt(91) + 32);
  28.                     //Completely random, does not check against a list of previous attempts.
  29.  
  30.                 }
  31.             }
  32.             temp = "";
  33.             for (y = 0; y < current.length; y++)
  34.                 temp += current[y];
  35.             System.out.println(temp);
  36.             count++;
  37.  
  38.         } while (!temp.equals(word));
  39.         System.out.println();
  40.         System.out.println(count + " Iterations");
  41.         return("");
  42.     }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement