Code Monkey home page Code Monkey logo

shannon's Introduction

shannon

NPM version Downloads Build Status

NPM

Pure javascript 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

const Shannon = require('shannon');

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

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

Decryption

const Shannon = require('shannon');

let key = Buffer.from([0x65, 0x87, 0xd8, 0x8f, 0x6c, 0x32, 0x9d, 0x8a, 0xe4, 0x6b]);
// message is encrypted
let message = Buffer.from([0x91, 0x9d, 0xa9, 0xb6, 0x29, 0xfc, 0x9c, 0xdd, 0x17, 0x8c, 0x15, 0x31, 0x9a, 0xae, 0xcc, 0x6e, 0xd4]);
let receivedMac = Buffer.from([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(Buffer.alloc(16));
if (Buffer.compare(mac, receivedMac)) {
	console.log("MAC OK")
}

shannon's People

Contributors

twonky4 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

teidesu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.