Implementation of One Time Pad Cipher
Python includes a hacky implementation module for one-time-pad cipher implementation. The package name is called One-Time-Pad which includes a command line encryption tool that uses encryption mechanism similar to the one-time pad cipher algorithm.
You can use the following command to install this module −
>pip install onetimepad
If you wish to use it from the command-line, run the following command −
The following code helps to generate a one-time pad cipher −
import onetimepad cipher = onetimepad.encrypt('One Time Cipher', 'random') print("Cipher text is ") print(cipher) print("Plain text is ") msg = onetimepad.decrypt(cipher, 'random') print(msg)
You can observe the following output when you run the code given above −
Note − The encrypted message is very easy to crack if the length of the key is less than the length of message (plain text).
In any case, the key is not necessarily random, which makes one-time pad cipher as a worth tool.