Help please idk how to fix

I want it to do

tpassword = tpassword + (acharset[iter] * iter(how many iterations have gone through))

so if its iter 0 than it just does

tpassword = tpassword 

if it’s higher it does

tpassword =  tpassword + (acharset[iter] * iter(how many iterations have gone through)

so it can do every possible password

WHOLE CODE

exit();
String charset = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()_-+=[{]}|:;'\",<.>/?";
char[] acharset = charset.toCharArray();
String password = "Test123";
//char[] apassword = password.toCharArray();
String tpassword = "";
int i = 0;
int c = 0;
int iter = 0;
//First Attempt
//**W.I.P**
//Could work ***SOON***
while (tpassword != password) {
  tpassword = acharset[iter] + (acharset[i] * iter);
  print("\nNEW TEST:", tpassword, "|ITERATION:", iter, "|TEST #:", c);
  if (i < 94)
    i++;
  else
    i = 0;
  if (c < 100) 
    c++;
  else
    break;
  if (c % 94 == 0) 
    iter++;
}


//Second Attempt
/*
**W.I.P**
 for (int i = 0; i < 92; i++) {
 if (tpassword != password) {
 print("\nNew Test:", tpassword);
 for (int c = 0; c < 2; c++) {
 String test = tpassword + acharset[i];
 if (c % 92 != 0) {
 tpassword =  test + acharset[i];
 } else {
 g++;
 print(" ITERATION:", g);
 }
 }
 } else { 
 print("\nFound Password:", tpassword);
 break;
 }
 }
 */

I know i can optimist but I’ll do that later. I’m trying to make a sort of brute force password cracker, but non malicious

1 Like

It is not clear what this line suppose to do: tpassword = acharset[iter] + (acharset[i] * iter);. Can you expand on it?

An additional point:

  • This is not the proper way to compare strings: if (tpassword != password). Check here

Kf

First, this is a common exercise – you will find it in Java on sites like Stackoverflow.

Not to worry – this kind of “password cracking” by iterative guessing isn’t going to be much use in the real world. It will only work on a plain-text passwords of trivial length. If someone has an 8+ character password – a minimum on most systems – that isn’t particularly tractable via charset iteration. Every time you add a single character to the password you are increasing the potential search space by a factor of – in your case – 93.

So if you loop through the charset, and finding “Test1” takes about 3 minutes… then “Test12” will take about 6 hours, “Test123” will take about 20 days – and 36337997988780 guesses. Going beyond your example to a minimum normal length password, “Test1234” will take 4-5 years. A 9-character password like “Test1234!” will take 4-5 centuries.

Here is a toy example – it doesn’t generate the test passwords and it doesn’t check password guesses. Instead it just does the math on how many guesses such a loop would take to find a solution by converting the proposed password to a base-93 double number (length of the charset). It then fakes counting up that high and gives a running estimate of how long it might take the computer to run such a loop.

// 2019-03-22 Processing 3.4
// discourse.processing.org/t/help-please-idk-how-to-fix/9425

String charset = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()_-+=[{]}|:;'\",<.>/?";
String password = "Test1"; // or try: "Test1234!"

void setup() {
  println(password);
  println("password length:", password.length());
  println("out of chars:", charset.length());
  long guesses = guessCount(charset, password);
  println("would guess:", guesses, "times");
  println("mock guessing:");
  int guessTime = guessTimer(guesses);
  println("mock guessing seconds:", guessTime); 
  println("done");
}

long guessCount(String charset, String password) {
  long guesses = 0;
  for (int i=0; i<password.length(); i++) {
    long index = charset.indexOf(password.charAt(password.length()-i-1))+1;
    long power = (long)pow(charset.length(), i);
    guesses = guesses + index * power;
  }
  return guesses;
}

int guessTimer(long guesses) {
  int start = millis();
  int update = start;
  long elapsed = 0;
  long estimated = 0;
  for (long j=0; j<guesses; j++) {
    if (millis() > update+3000) {
      update = millis();
      elapsed = update - start;
      estimated = elapsed*(guesses/j);
      println("...progress:", (int)(1000000*j/(double)guesses)/10000.0, "%",
              "ellapsed:", elapsed/1000, "/ ~", estimated/1000, "secs");
    }
  }
  return (millis() - start)/1000;
}

Example output:

Test1
password length: 5
out of chars: 93
would guess: 4201410167 times
mock guessing:
…progress: 1.5817 ellapsed: 3 / ~ 189 secs ...progress: 3.1289 ellapsed: 6 / ~ 186 secs
…progress: 4.7048 ellapsed: 9 / ~ 189 secs ...progress: 6.1458 ellapsed: 12 / ~ 192 secs
…progress: 7.6283 ellapsed: 15 / ~ 195 secs ...progress: 9.1196 ellapsed: 18 / ~ 180 secs
…progress: 10.6133 ellapsed: 21 / ~ 189 secs [SNIP] ...progress: 96.8809 ellapsed: 189 / ~ 189 secs
…progress: 98.4359 ellapsed: 192 / ~ 192 secs ...progress: 99.5105 ellapsed: 195 / ~ 195 secs
mock guessing seconds: 196
done

1 Like