npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cipher.js

v1.1.2

Published

A javascript decryption libary

Downloads

8

Readme

cipher.js

A javascript decryption libary.

This library is an attempt at not cheating the UK National Cipher Challenge, whilst also serving a purpose to the open source community. (That was a joke; I would only ever think about myself)

(Have a play-a-round on Codepen)

Wanna learn how to use it?

I've coded it into three categories: encrypt, decrypt and tools. These are all stored in the object cipher. So, if I wanted to get to the tools section, I would do: cipher.tools.BLAH.

The encrypt section.

As you can probably tell, the encrypt section is all about encrypting things. Although not the primary idea of the library, I've included these anyway.

caesar(str, amount)

This takes two arguments - str and amount. str is the phrase that you want to be encrypted, and amount is a number of letters to shift. Example:

  cipher.encrypt.caesar('abc', 1) // Returns 'bcd'

  var secretMessage = cipher.encrypt.caesar('Momma, I just killed a man-', 13);
  console.log(secretMessage) // Logs 'Zbzzn, V whfg xvyyrq n zna-'

reverseString(str, spaces)

This too takes two arguments - str and spaces. str is the phrase you want to be reversed, whilst spaces is a boolean. If true, the str will be reversed including spaces. If false, it will disregard all spaces and reverse it that way. Example:

  cipher.encrypt.reverseString('abc def', true); // returns 'def abc'
  cipher.encrypt.reverseString('abc def', false); // returns 'defabc'

The decrypt section.

This section is the primary focus of the library – allowing you to easily decipher text. This section references cipher.tools a lot.

caesar(str, amount)

However visually symmetrical to the cipher.encrypt.caesar, it has one difference. Instead of moving the letters forward by the amount, it moves them backwards. Example:

  cipher.decrypt.caesar('abc', 1) // returns 'zab'
  var decodedMessage = cipher.decrypt.caesar('Zbzzn, V whfg xvyyrq n zna-', 13);
  console.log(decodedMessage) // Logs 'Momma, I just killed a man-'

caesarGuess(str, letter)

This is my favourite bit of the library. It can take any string (the second argument isn't required) and guess a shift, then decode it into English.

To understand its use, you need to know how it works. These are the steps it follows:

  • Find the most common letter, using a call to the cipher.tools.frequency().
  • Work out the difference between it and the most common letters in English (e,a,t,o).
  • Store these in an object.
  • Decrypt the text using the cipher.decrypt.caesar() function using an amount of the chosen letter.
  • Display result.

Usually it works when letter is 'e', because it's the mostest most common letter in English. Examples:

  var words = 'Hello! this is a very large piece of text containing a lot of vowels. Hey, look at that I\'m using e so much. I like e. Did you know that in mathematics e^n is a transcendental number?'
  var secretMessage = cipher.encrypt.caesar(words,18)
  cipher.decrypt.caesarGuess(secretMessage); // Returns what is the same as the words variable.

reverseString(str, spaces)

This is 100% the same as the cipher.encrypt.reverseString() function. Scroll up to read the documentation for that.

Tools

These do not encrypt or decrypt, but are common resuable bits of code.

alphabetNum(letter)

This function takes one argument - letter - and returns the number of that letter in the alphabet. Examples:

  cipher.tools.alphabetNum('a') // Returns 1.

stringNum(str)

This function does the same as the alphabetNum(), but instead turns a string into an array of numbers corresponding to the letters at that point. Examples:

  cipher.tools.stringNum('abc') // Returns ['1','2','3']

frequency(str)

This function returns an object of information about a given string. In total, it returns 5 things.

  cipher.tools.frequency(str)

  // Returns
  {
    consisency: // Equal to (range*str.length)/100 - the higher the number the more 'diverse' a string is. Used to check if                   // its been encrypted with a shift cipher.
    mostUsedLetter: // Funnily enough, the most used letter.
    maxAmountOfTimesALetterAppeared: // Have a guess.
    minAmountOfTimesALetterAppeared: // ""         ""
    range: // The range of the amount of times letters occured. If 'a' had been used 3 times and 'b' had been used once, the
           // range would be 2 (3-1).
  }