One time pad, encryption and decryption

后端 未结 6 1859
-上瘾入骨i
-上瘾入骨i 2021-01-17 23:34

I am trying to pick up cryptography and had been trying this exercise

Write a program (preferably Java) to generate a one-time pad, which is a relatively large file

6条回答
  •  旧巷少年郎
    2021-01-18 00:02

    First here is a OTP algorithm specified called HOTP which is a standard RFC. Almost all other OTP are propriety and we don't know the algorithm for those.

    http://tools.ietf.org/html/rfc4226

    There is some java code in there you can use to learn how its done. Second if you are going to do encryption don't use Random. Random is nice for psuedo random, but if you really want a good source of random data you need to adopt SecureRandom. That's a much better source of random numbers that are suitable for cryto algorithms.

    For converting things to Hex you can easily use

    http://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigInteger.html#toString(int)

    Or any of the varieties Long.toString(value,radix), Integer.toString(value,radix), or Byte.toString(value,radix).

    byte[] bytes = ...;
    for( int i = 0; i < bytes.length; i++ ) {
        System.out.println( Integer.toString( bytes[i], 16 );
    }
    

提交回复
热议问题