Skip to main content

Python implementation of the Shannon stream cipher

Project description

py-shannon

PyPI

Pure Python implementation of Shannon stream cipher. No-brainer port of shannon.

Shannon cipher is used in Spotify Connect to encrypt communication between player and Spotify AP server. Shannon cipher is variant of Sober stream cipher.

Example

Encryption

from shannon import Shannon

key = b"\x65\x87\xd8\x8f\x6c\x32\x9d\x8a\xe4\x6b"
message = "My secret message".encode("utf-8")

shannon = Shannon(key)

message = shannon.encrypt(message)  # -> bytes
# message contains ciphertext now
mac = shannon.finish()  # -> bytes
# mac contains MAC of the message

Decryption

from shannon import Shannon

key = b"\x65\x87\xd8\x8f\x6c\x32\x9d\x8a\xe4\x6b"
# message is encrypted
message = b"\x91\x9d\xa9\xb6\x29\xfc\x9c\xdd\x17\x8c\x15\x31\x9a\xae\xcc\x6e\xd4"
received_mac = b"\xbe\x7b\xef\x39\xee\xfe\x54\xfd\x8d\xb0\xbc\x6f\xd5\x30\x35\x19"

shannon = Shannon(key)
message = shannon.decrypt(message)  # -> bytes
# message contains plaintext now
mac = shannon.finish()
if mac == received_mac:
    print("MAC OK")

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

py-shannon-1.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

py_shannon-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file py-shannon-1.0.0.tar.gz.

File metadata

  • Download URL: py-shannon-1.0.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for py-shannon-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a3f1374e0af234dffafe93eab288135149c530af43b8b14bde317f74c80e42a4
MD5 18da6600ccade9b1c8c41760a89c9fcb
BLAKE2b-256 4ea4c04e0e4912e6fd2ef3cd64a3ebe82de4fc20b3d771b1cdc69959f7c2868a

See more details on using hashes here.

File details

Details for the file py_shannon-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: py_shannon-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for py_shannon-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a282638150202023187512746888afb2dc8ce0bae9855e70e541893c2c2a34c8
MD5 4cf176ec9161ffa98c17f173d2bd39f4
BLAKE2b-256 e85dd822a52dca084b0da70754882c01fb5657f4e8f408ad1d860640c8d6a8c5

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