
package fortuna;

/**
 *
 * @author Viliam Krizan
 */
import aalg.crypto.AesCipher;
import fortuna.entropySources.EntropySource;
import fortuna.entropySources.keyboard.KeyboardES;
import fortuna.entropySources.microphone.CaptureMicrophoneData;
import fortuna.entropySources.mouse.MouseES;
import fortuna.entropySources.system.SystemES;
import fortuna.entropySources.webcam.CaptureWebcam;
import fortuna.generator.BlockCipherGenerator;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;



public class Test {

    
    
    
    public static void main(String[] args) {
        File cryptoData = new File("CryptoData.txt");
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(cryptoData));
        } catch (IOException ex) {
            System.exit(0);
        }
        
        //creating aes block cipher generator
        BlockCipherGenerator aesCipherGenerator = new BlockCipherGenerator(new AesCipher(32));
        //creating fortuna
        Fortuna fortuna = new Fortuna(aesCipherGenerator);
        
        //creating entropy source threads
        EntropySource microphone = new CaptureMicrophoneData();
        fortuna.addEntropySource(microphone);
        
        /*EntropySource webcam = new CaptureWebcam();
        fortuna.addEntropySource(webcam);
        
        EntropySource mouse = new MouseES();
        fortuna.addEntropySource(mouse);
        
        EntropySource ses = new SystemES();
        fortuna.addEntropySource(ses);*/
        
        //EntropySource keyboard = new KeyboardES();
        //fortuna.addEntropySource(keyboard);
        
        //generate output
        byte[] result = new byte[20];
        for (int m = 0; m < 100; m++) {
            for (int k = 0; k < 3; k++) {
                //request to generate 16 bytes of random data
                fortuna.generateRandomData(result);
                /*try {
                    Thread.sleep(5000);
                    } catch (InterruptedException e) {
                }*/
                /*try {
                    writer.write(new String(result, "UTF-8"));
                } catch (IOException ex) {
                }*/
                //printing result 
                int c = 0;
                for (int i = 0; i < 2; i++) {
                    for (int j = 0; j < 8; j++) {
                        System.out.print(result[c++] + "\t");
                        
                    }
                    System.out.println("");
                }
                System.out.println("");
            }
            System.out.println("-------------------------------------------------------------\n");
            //reseed after each request
            fortuna.reseed();
        }
        try {
            writer.close();
        } catch (IOException ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        }
        fortuna.finish();
        
        
    }
}
