vendredi 26 mars 2021

How to generate a pseudo-random number using a seed in java for a Stream Cipher?

I am working on a Stream Cipher program in Java which should take three arguments from the shell: a file with a key, a file for input, and a file for output. The key should then serve as the seed which should generate a pseudo-random number which should be "XOR:ed" with the plaintext in the input file.

I have managed to write the code for reading a file but I do not know how I am supposed to write the code for taking the key as the seed and thus generate a pseudo-random number as explained above. Could someone help me?

public static void main(String[] args) throws IOException {
   File key = null;
   File input = null;
   File output = null;
   if (0 < args.length) {
      key = new File(args[0])
      input = new File(args[1]);
      output = new File(args[2]);
}
//more stuff

//a function that takes the seed from the key file and should generate a pseudo-random number

int prng (long seed) {
    Random random = new Random ();
    int bound = 256;
    int number = random.nextInt(bound);

    return number;

    }


      



Aucun commentaire:

Enregistrer un commentaire