vendredi 11 août 2017

Random seed generator

I need to upgrade to the new Iota wallet today. It doesn't have a random seed generator, so I built my own and ran it from NetBeans. Can you give me your opinion? It has to be 81 characters long, and contain A through Z and the number 9. Nothing else. Here's the entire code.

Does this leave anything insecure? Could the code have been cleaner from a standpoint of convention?

    class SeedGenerator    {
    /*
    This is a program to randomize a seed for Iota wallet
    */

    public static void main(String[] args)  {
        System.out.println("*****");
        int seedLength = 81;
        String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9"; //Only characters allowed in Iota seed are A-Z and number 9
        char[] charArray = alphabet.toCharArray();  //Turn string into array of characters to be referenced by index
        String[] seed = new String[seedLength];
        System.out.print("Random wallet seed is: ");

        for (int i = 0; i < seedLength; i++)    {
            Random newRandomNumber = new Random();
            int seedIndex = newRandomNumber.nextInt(alphabet.length()); //This is an array of index numbers to pull from charArray
//            System.out.print(seedIndex + " "); //Used for testing the random character index range
            seed[i] += charArray[seedIndex];
            System.out.print(charArray[seedIndex] + "");

        }

        System.out.println();
        System.out.println("*****");
    }
}




Aucun commentaire:

Enregistrer un commentaire