// example by Stian Lavik Stokkenes oct 2005 // INF329 - University of Bergen // Demonstrates the "Throwing Dice for password" example // in chapter 13 in Building secure Software. // import java.util.Random ; public class Dices { public static Random rand = new Random() ; public static String [][][]table; protected static String password = ""; /** * Generates a random number between 1 and 6 */ public static int throw_dice () { int dice = rand.nextInt(); dice = Math.abs(dice); dice = dice % 6; dice += 1; return dice; } /** * Init the table of chars */ public static void init(){ table = new String[7][7][7]; table[1][1][1]="a";table[1][1][2]="b";table[1][1][3]="c";table[1][1][4]="d"; table[1][1][5]="e";table[1][1][6]="f";table[1][2][1]="g";table[1][2][2]="h"; table[1][2][3]="i";table[1][2][4]="j";table[1][2][5]="k";table[1][2][6]="l"; table[1][3][1]="m";table[1][3][2]="n";table[1][3][3]="o";table[1][3][4]="p"; table[1][3][5]="q";table[1][3][6]="r";table[1][4][1]="s";table[1][4][2]="t"; table[1][4][3]="u";table[1][4][4]="v";table[1][4][5]="w";table[1][4][6]="x"; table[1][5][1]="y";table[1][5][2]="z";table[1][5][3]="A";table[1][5][4]="B"; table[1][5][5]="C";table[1][5][6]="D";table[1][6][1]="E";table[1][6][2]="F"; table[1][6][3]="G";table[1][6][4]="H";table[1][6][5]="I";table[1][6][6]="J"; table[3][1][1]="K";table[3][1][2]="L";table[3][1][3]="M";table[3][1][4]="N"; table[3][1][5]="O";table[3][1][6]="P";table[3][2][1]="Q";table[3][2][2]="R"; table[3][2][3]="S";table[3][2][4]="T";table[3][2][5]="U";table[3][2][6]="V"; table[3][3][1]="W";table[3][3][2]="X";table[3][3][3]="Y";table[3][3][4]="Z"; table[3][3][5]="0";table[3][3][6]="1";table[3][4][1]="2";table[3][4][2]="3"; table[3][4][3]="4";table[3][4][4]="5";table[3][4][5]="6";table[3][4][6]="7"; table[3][5][1]="8";table[3][5][2]="9";table[3][5][3]="'";table[3][5][4]="~"; table[3][5][5]="!";table[3][5][6]="@";table[3][6][1]="#";table[3][6][2]="$"; table[3][6][3]="%";table[3][6][4]="^";table[3][6][5]="&";table[3][6][6]="*"; table[5][1][1]="(";table[5][1][2]=")";table[5][1][3]="_";table[5][1][4]="-"; table[5][1][5]="+";table[5][1][6]="=";table[5][2][1]="{";table[5][2][2]="["; table[5][2][3]="}";table[5][2][4]="]";table[5][2][5]="|";table[5][2][6]="\\"; table[5][3][1]=":";table[5][3][2]=";";table[5][3][3]="\"";table[5][3][4]=","; table[5][3][5]="?";table[5][3][6]="/";table[5][4][1]="2";table[5][4][2]="3"; table[5][4][3]="4";table[5][4][4]="5";table[5][4][5]="6";table[5][4][6]="7"; table[5][5][1]="8";table[5][5][2]="9";table[5][5][3]="'";table[5][5][4]="~"; table[5][5][5]="!";table[5][5][6]="@";table[5][6][1]="#";table[5][6][2]="$"; table[5][6][3]="%";table[5][6][4]="^";table[5][6][5]="&";table[5][6][6]="*"; } public static String gen_password(int length){ int dice1; int dice2; int dice3; for(int i=0;i