Package: vernamcipher
Updates!The vernamcipher project is now using truly-random keys. Credit to The Australian National University for their Quantum Random Number Generator (no affiliation).
With this latest update, the vernamcipher package is officially using the strongest encryption methods with truly-random keys.Please refer below for an in-depth explanation and usage examples.What is the Vernam Cipher?The Vernam Cipher was invented in 1917 by the American scientist Gilbert Vernam. It is the only cipher still proven to be unbreakable.
All other ciphers and encryption methods are based on computational security and integrity, therefore they are theoretically discoverable given enough time, computational power and ciphertext.Encryption ProcessAone-time padorkeyis used to encrypt plaintext. The one-time pad must be equal to or longer in characters than the plaintext.
In practice, the key must be truly random and used only once. Once for encryption and once for decryption.
Since the key is random, so will be the distribution of the characters meaning that no amount of cryptanalysis will produce any meaningful results.ExampleAs an example, Bob wants to encrypt the letterMand send it to Alice. Bob randomly generates a random key which is the same length as the plaintext, in this case1 character long.
The plaintext and key are both converted into their ASCII binary representation.AnXORoperation is carried out between the binary character value of the first character of the plaintext and the first character of theone-time pad.Plaintext: MKey: +XOR101011000110101011110As you can see from the table above, theXORoperations generate a 7-bit binary value of1100110, which corresponds to the letterfon the ASCII table.
Alice would then use the ciphertextfagainst the key+and follow the same process to decrypt the ciphertext.Cryptanalysis and Perfect SecurityCiphers which use computer-generated random keys can be broken since mathematically generated random numbers are not truly random, they only appear to be.
A truly random sequence must be collected from a physical and unpredictable phenomenon such as white noise, the time of a hard disk or radioative decay.
To ensure it is mathematically impossible to break, truly random keys must be used.DisclaimerThe truly-random keys are NOT generated on the computer or system being used. They are provided by the ANU QRNG. No computer can generate truly-random values only cryptographically strong.Installationvernamcipher requires one dependency listed below:- requests>=2.27.1Requirements- Python 3.8+
- macOS or Linux (Windows not officially supported)
- Working internet connection required to access QRNG when generating keys.pip install vernamcipherUsageGenerate a cryptographically-strong, random keyfromvernamcipher.cryptographicimportCryptographickey=Cryptographic.generate_key()Encryptfromvernamcipher.cryptographicimportCryptographicplaintext="Hello World"key=Cryptographic.generate_key()encrypted_data=Cryptographic.exclusive_operations(plaintext,key)Decryptfromvernamcipher.cryptographicimportCryptographicencrypted="tTuPl"key=Cryptographic.generate_key()decrypted_data=Cryptographic.exclusive_operations(encrypted,key)