# shannon-es

> Shannon stream cipher in modern JavaScript

Latest version **0.0.1** (published 2024-03-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install shannon-es
pnpm add shannon-es
yarn add shannon-es
bun add shannon-es
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2024-03-24 |
| First published | 2024-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 25.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | alina sireneva |
| Maintainers | teidesu |
| Keywords | shannon, stream, cipher |

## Links

- npm: https://www.npmjs.com/package/shannon-es
- Repository: https://github.com/teidesu/shannon-es
- Issues: https://github.com/teidesu/shannon-es/issues
- npm.io page: https://npm.io/package/shannon-es

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2024-03-24

## README

# shannon

[![NPM version](https://img.shields.io/npm/v/shannon-es.svg)](https://www.npmjs.com/package/shannon-es)
[![Tests](https://github.com/teidesu/shannon-es/actions/workflows/test.yaml/badge.svg)](https://github.com/teidesu/shannon-es/actions/workflows/test.yaml)


Modern JavaScript implementation of Shannon stream cipher. No-brainer port of [shannon](https://github.com/chatoooo/shannon).

Shannon cipher is used in Spotify Connect to encrypt communication between player and Spotify AP server. Shannon cipher
is variant of [Sober](https://en.wikipedia.org/wiki/SOBER) stream cipher.

## Example
Encryption
```javascript
import { Shannon } from 'shannon';

let key = new Uint8Array([0x65, 0x87, 0xd8, 0x8f, 0x6c, 0x32, 0x9d, 0x8a, 0xe4, 0x6b]);
let message = new TextEncoder().encode('My secret message');

let cipher = new Shannon(key);
let message = cipher.encrypt(message);
// message contains ciphertext now
let mac = cipher.final(new Uint8Array(16));
// mac contains MAC of the message
```

Decryption
```javascript
import { Shannon } from 'shannon';

let key = new Uint8Array([0x65, 0x87, 0xd8, 0x8f, 0x6c, 0x32, 0x9d, 0x8a, 0xe4, 0x6b]);
// message is encrypted
let message = new Uint8Array([0x91, 0x9d, 0xa9, 0xb6, 0x29, 0xfc, 0x9c, 0xdd, 0x17, 0x8c, 0x15, 0x31, 0x9a, 0xae, 0xcc, 0x6e, 0xd4]);
let receivedMac = new Uint8Array([0xbe, 0x7b, 0xef, 0x39, 0xee, 0xfe, 0x54, 0xfd, 0x8d, 0xb0, 0xbc, 0x6f, 0xd5, 0x30, 0x35, 0x19]);
let cipher = new Shannon(key);
let message = cipher.decrypt(message);
// message contains plaintext now
let mac = cipher.final(new Uint8Array(16));
if (buffersEqual(mac, receivedMac)) {
	console.log("MAC OK")
}
```

---
_Source: https://npm.io/package/shannon-es · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
