# The module for distributed John (djohn)


[List.External:dJohn]
int length;				// Current length
int charset[@charset_length@];
int rword[@max_word@];
int charsetl;
int first_time;

void init()
{
  length = @length_word_1@;  charsetl = @charset_length@;
@charset@
@word_1@
  first_time = 1;
}

void generate()
{
	int i;

	if (first_time) {
	  first_time = 0;
	  return;
	}

	if (@eq_word_2@) {
	  word = 0;
	  return;
	}

  	i = length - 1;			// Start from the last character
	while (++rword[i] == charsetl)		// Try to increase it
	if (i)				// Overflow here, any more positions?
		rword[i--] = 0;	// Yes, move to the left, and repeat
	else				// No
	if (length < @max_word@-1) {
		i = ++length;	// Switch to the next length
		while (i--)
			rword[i] = 0;
		while (i < length)
		  word[i] = charset[rword[i++]];
		word[length] = 0;
		return;
	} else {
		word = 0; return;	// We're done
	}
	i = 0;
	while (i < length)
	  word[i] = charset[rword[i++]];
	word[length] = 0;
}
