GithubHelp home page GithubHelp logo

fairplay's Introduction

fairplay

Javascript implementation of the Playfair cipher

Demo

fairplay

Usage

Include the script in your document:

<script src="dist/fairplay.min.js"></script>

If you are using a module loader like RequireJS, require the module:

require(["dist/fairplay.min"], function (fairplay) {

});

Functions

fairplay.generateKey()

Providing a keyphrase to this function will generate a key square:

fairplay.generatekey("Charles Wheatstone");
// Returns: [
//  ["c", "h", "a", "r", "l"],
//  ["e", "s", "w", "t", "o"],
//  ["n", "b", "d", "f", "g"],
//  ["i", "k", "m", "p", "q"],
//  ["u", "v", "x", "y", "z"]
// ]

fairplay.printKey()

In addition to generating a key square, it will print the key with the newline character(s) of your choice (\n by default):

fairplay.printKey("Charles Wheatstone", "<br />");
// Returns:
// "c h a r l<br />
//  e s w t o<br />
//  n b d f g<br />
//  i k m p q<br />
//  u v x y z"

fairplay.encrypt()

Given a keyphrase and plaintext, it will encrypt the plaintext using the Playfair cipher:

fairplay.encrypt("Charles Wheatstone", "Lord Playfair");
// Returns: "ogafqrrxdrpc"

fairplay.decrypt()

Given a keyphrase and ciphertext, it will decrypt the ciphertext using the Playfair cipher:

fairplay.decrypt("Charles Wheatstone", "ogafqrrxdrpc");
// Returns: "lordplayfair"

Configuration

In situations where there is an odd number of characters in the plaintext and double-letter digraphs, by default an x is used to pad the plaintext or replace the duplicated letter.

You may change the monograph directly:

fairplay.monograph = "x";

Note: This implementation of the Playfair cipher changes all letter js to is to facilitate perfect 5x5 key squares.

Testing

Test with nodeunit:

nodeunit test/test.js

fairplay's People

Contributors

kevinselwyn avatar

Stargazers

 avatar Christian Nogueras  avatar Crispin Ou avatar

Watchers

James Cloos avatar  avatar

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.