- if (!encrypted_sys_file_unlock (enc, password))
- error (1, 0, _("sorry, wrong password"));
+ for (int len = password ? strlen (password) : 0;
+ len <= max_length; len++)
+ {
+ if (password && len == strlen (password))
+ {
+ for (int i = 0; i < len; i++)
+ {
+ const char *p = strchr (alphabet, password[i]);
+ if (!p)
+ error (1, 0, _("%s: '%c' is not in alphabet"),
+ password, password[i]);
+ indexes[i] = p - alphabet;
+ pw[i] = *p;
+ }
+ }
+ else
+ {
+ memset (indexes, 0, len * sizeof *indexes);
+ for (int i = 0; i < len; i++)
+ pw[i] = alphabet[0];
+ }
+ pw[len] = '\0';
+
+ unsigned int target = 0;
+ for (unsigned int j = 0; ; j++)
+ {
+ if (j >= target)
+ {
+ target += 100000;
+ if (isatty (STDOUT_FILENO))
+ {
+ printf ("\rlength %d: %s", len, pw);
+ fflush (stdout);
+ }
+ }
+ if (encrypted_file_unlock__ (enc, pw))
+ {
+ printf ("\npassword is: \"%s\"\n", pw);
+ password = pw;
+ goto success;
+ }
+
+ int i;
+ for (i = 0; i < len; i++)
+ if (++indexes[i] < alphabet_size)
+ {
+ pw[i] = alphabet[indexes[i]];
+ break;
+ }
+ else
+ {
+ indexes[i] = 0;
+ pw[i] = alphabet[indexes[i]];
+ }
+ if (i == len)
+ break;
+ }
+ }
+ free (indexes);
+ free (pw);