Skip to main content

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 Process

A one-time pad or key is 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.

Example

As an example, Bob wants to encrypt the letter M and send it to Alice. Bob randomly generates a random key which is the same length as the plaintext, in this case 1 character long. The plaintext and key are both converted into their ASCII binary representation.

An XOR operation is carried out between the binary character value of the first character of the plaintext and the first character of the one-time pad.

Plaintext: M Key: + XOR
1 0 1
0 1 1
0 0 0
1 1 0
1 0 1
0 1 1
1 1 0

As you can see from the table above, the XOR operations generate a 7-bit binary value of 1100110, which corresponds to the letter f on the ASCII table. Alice would then use the ciphertext f against the key + and follow the same process to decrypt the ciphertext.

Cryptanalysis and Perfect Security

Ciphers 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.

Disclaimer

The 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.

Installation

vernamcipher requires one dependency listed below:

- requests>=2.27.1

Requirements

- Python 3.8+
- macOS or Linux (Windows not officially supported)
- Working internet connection required to access QRNG when generating keys.

pip install vernamcipher

Usage

Generate a cryptographically-strong, random key

from vernamcipher.cryptographic import Cryptographic

key = Cryptographic.generate_key()

Encrypt

from vernamcipher.cryptographic import Cryptographic

plaintext = "Hello World"
key = Cryptographic.generate_key()

encrypted_data = Cryptographic.exclusive_operations(plaintext, key)

Decrypt

from vernamcipher.cryptographic import Cryptographic

encrypted = "tTuPl"
key = Cryptographic.generate_key()

decrypted_data = Cryptographic.exclusive_operations(encrypted, key)

Metadata

Release files for vernamcipher 1.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vernamcipher 1.1.5
File Size Uploaded
vernamcipher-1.1.5.tar.gz 18.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vernamcipher 1.1.5
File Interpreter ABI Platform
vernamcipher-1.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 34.1 kB

Release files / vernamcipher-1.1.5.tar.gz

Download URL vernamcipher-1.1.5.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6b40812c963e71ab5727518945e88b7464a6e5336622ac37886b4ebdfb83fdf9
BLAKE2b-256 checksum
How to use checksums
f8e41581bded8dca7ee815f9ab08e06d65128698aa5f059c0ded75087dbba7b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.3

Release files / vernamcipher-1.1.5-py3-none-any.whl

Download URL vernamcipher-1.1.5-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3e92b628fa7a3ed5f374915f726f3d8d95ff8070c7b9571929365e36b13cb26
BLAKE2b-256 checksum
How to use checksums
2d4376832a5fb6d1115e34db7a6d3a18efa360a0d11aff823396d70b312bfb47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

1.1.5 This release

2 release files

1.1.4

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page