I am trying to pick up cryptography on my own and no problem with caesar and vigenere cipher but here I am trying to understand or to start this bit on the one-time pad. Could anyone advise or give me a head start on this?

Write a program (preferably Java) to generate a one-time pad, which is a relatively large file of all
random data (say 1 MB). The program should also be able to encrypt/decrypt files based on the
generated one time pad.
Tip: use the following test vector to check if your program does encryption correctly.

Plaintext (ASCII): Every cloud has a silver lining
OTP (HEX): 6dc72fc595e35dcd38c05dca2a0d2dbd8e2df20b129b2cfa29ad17972922a2
ciphertext (HEX): 2 8b14ab7ecc33ea157b539ea426c5e9def0d81627eed498809c17ef9404cc5

Recommended Answers

All 4 Replies

Hmm... Have you read the Wikipedia page? The way the encryption uses in this case is to use the ASCII value of the current letter. In other words, you first convert each letter to a hex ASCII value. Then you apply a set of key which is also in hex string -- add each hex value of the letter that has the same location as the key hex string. Then the result value from modulo must be between x00 to xFF (mod it with 256). That's my guess from glancing your requirement and read the algorithm.

HI Taywin,

I have read the ascii page but I don't quite understand, what you meant by hex ASCII value..

First, keep the ASCII table next to you so you can see where the number comes from (white space is 20x). Then see the example below for how to convert a character to an ASCII value. In Java, chatAt() of String class automatically gives you a decimal (int). You can convert it to hex using Integer class.

/*
E   v   e   r   y  ...
45  76  65  72  79  <-- hex value of each char

6d  c7  2f  c5  95  <-- hex value of the OTP key

<---- this line is to process it using some sort of addition, subtraction, & modulo --->

28  b1  4a  b7  ec  <-- result after the process
*/

After looking at it again, I think the modulo value may not be 256. You need to find the process of convertion.

thanks.. I have the following OTP, does it look proper to you? I mean it generates random charater from the string given, I am just wondering about the encryption bit....how do I go around it,Could you shed some light for me? Cheers

public static void oneTimePad()
    {
        Random ran = new Random();
        String s = "0123456789ABCDEF";
        for(int i = 0; i < 100; i++)
        {   
            System.out.print(s.charAt(ran.nextInt(s.length())));
        }


    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.