import java.util.*;
import java.lang.*;
import java.io.*;

/* Usage: java genkeys > <keyfilename> */

public class genkeys {

private static String charlist="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*+-<>.,?/|][_={}:()~;' ÈÐÛÔíäû£ÜÊÖ¼Òïºö°ÉìùÃË¾ÝµÀóþâÚêÕýçÓú½ñÑá¢±Áð¡Äÿ¿\"";
//private static String charlist="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*+-<>.,?/|][_={}:()~;' \"";

public static void main(String argc[]){

//generate passphrasekey
//create a random number generator
Random r1=new Random();
String passphrasekey="";
int randnum;
for (int i=0;i<charlist.length();i++) {
//generate a random num
randnum=r1.nextInt(charlist.length());
//use randnum as the index to pull a random char from charlist
char thischar=charlist.charAt(randnum);
	//if this char does not exist yet in the passphrasekey
	if (passphrasekey.indexOf(""+thischar) < 0) {
		//add thischar to passphrasekey string
		passphrasekey=passphrasekey+thischar;
	} else {
		//char has already been chosen.  Do again
		i--;
	}
}//end for loop

//print out the passphrasekey
System.out.println(""+passphrasekey+"\n");

String keyline="";
String firstcharlist="";//this varible defines which chars have already been chosen as a first char in a key line.
Random r2=new Random();
int randnum2;

//for 0 to charlist.length.  J sets the number of key lines we will have.  
//The number of key lines is always = to the number of chars in charlist.

for (int j=0;j<charlist.length();j++) {

   //generate a key string line
for (int k=0;k<charlist.length();k++) {
//generate a random num
randnum2=r2.nextInt(charlist.length());
//use that randnum2 as index to pull a random char from charlist
char thischar=charlist.charAt(randnum2);
        if (keyline.indexOf(""+thischar) < 0) {
                //add to passphrasekey string
		//if char is not part of the firstcharlist
                keyline=keyline+thischar;
		if (k == 0) { //we are currently on the first char of the keyline
			if (firstcharlist.indexOf(""+thischar)>=0) {
			//we dont want to repeat chars as the first one in each line.  If it has already been chosen, do again
			keyline=keyline.substring(0,keyline.length()-1);//get rid of the last char
			k--;//do again
			} else {
			firstcharlist=firstcharlist+thischar;//char is okay
			}
		}
		
		
        } else {
                //char has already been chosen.  Do again
                k--;
		
        }
}//end for loop
//output this key line to standard output
System.out.println(keyline);
keyline="";//repeat for next key line
}
System.exit(0);
}//end main

}//end class
