Skip to main content

A Python implementation of truly-random Vernam Cipher encryption.

Project description

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.

Installation

vernamecipher does not require any additional dependencies and can work on a fresh Python install, without any additional requirements.

Requirements

Python 3.8+ macOS or Linux (Windows not officially supported, but might work)

pip3 install vernamcipher

Usage

Generate a truly-random key

from vernamcipher.cryptographic import Cryptographic

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

Encrypt

from vernamcipher.cryptographic import Cryptographic

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

encrypted_data = Cryptographic.exclusive_operations(plaintext, key)

Decrypt

from vernamcipher.cryptographic import Cryptographic

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

decrypted_data = Cryptographic.exclusive_operations(encrypted, key)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vernamcipher-0.2.2.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

vernamcipher-0.2.2-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file vernamcipher-0.2.2.tar.gz.

File metadata

  • Download URL: vernamcipher-0.2.2.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for vernamcipher-0.2.2.tar.gz
Algorithm Hash digest
SHA256 8bedaabc4e087f8846d75f2926966b1f8e3f86100a390a6f96e937bd66f753ae
MD5 ebc2540b3ed850c158185886f94acbf1
BLAKE2b-256 579e1058141a1dc30a6313731a7aa6baa8fe2b4a3be76b495728d14bbf247b33

See more details on using hashes here.

File details

Details for the file vernamcipher-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: vernamcipher-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for vernamcipher-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6b7ac989a6f2f69a9b76e41fa95315c79e5d08a8109c28c4dc17e9b29ba29cf4
MD5 26ec73d5c1ac5ba75cfd8394851cc9c1
BLAKE2b-256 e885fbc000acf6e5c4170a23a16e5650794da977716d0059c8fd4cea6637e6af

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page