Welcome, guest | Sign In | My Account | Store | Cart

Generates next lexographically occuring word, say "aaa" -> "aab" -> "aac"

Can be used for password cracking....

Java, 18 lines
 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); 
	}
Created by st0le on Sun, 18 Jul 2010 (MIT)
Java recipes (20)
st0le's recipes (4)

Required Modules

  • (none specified)

Other Information and Tasks