我正在使用 Java 开发一个 Stream Cipher 程序,它应该从 shell 中获取三个参数:一个带有密钥的文件、一个用于输入的文件和一个用于输出的文件。然后,该密钥应作为种子,该种子应生成一个伪随机数,该伪随机数应与输入文件中的明文“异或:ed”。
我已经设法编写了用于读取文件的代码,但我不知道我应该如何编写将密钥作为种子的代码,从而生成一个伪随机数,如上所述。有人可以帮助我吗?
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;
}