Generates next lexographically occuring word, say "aaa" -> "aab" -> "aac"
Can be used for password cracking....
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public static String nextLexographicWord(String txt)
{
char [] letters = txt.toCharArray();
int l = letters .length - 1;
while(l >= 0)
{
if(letters[l] == 'z')
letters[l] = 'a';
else
{
letters[l]++;
break;
}
l--;
}
if(l < 0) return 'a' + (new String(letters));
return new String(letters);
}
|