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 🙏

© 2024 – Pkg Stats / Ryan Hefner

one-time-pad-es6

v0.9.1

Published

One-time-pad implementation using ES6. Encrypts both String and Array Buffer.

Downloads

6

Readme

One-time-pad using modern ES6 implementation Build Status

JavaScript Library to encrypt both Array Buffer and String using one-time-pad encryption technique.
At the time of writing, this is the only one-time-pad implementation on NPM that supports encryption of both string and Array Buffer.
Codebase prioritize on ease of use and ease of understanding.

One-time-pad is cryptographically MOST SECURE encryption. It is mathematically and theoretically unbreakable if used correctly.

The following rules must be followed to ensure One-Time-Pad is secure:

  • The key is at least as long as the message or data that must be encrypted.
  • The key is truly random (not generated by a simple computer function or such)
  • Key and plaintext are calculated modulo 10 (digits), modulo 26 (letters) or modulo 2 (binary)
  • Each key is used only once, and both sender and receiver must destroy their key after use.
  • There should only be two copies of the key: one for the sender and one for the receiver (some exceptions exist for multiple receivers)

Node.js (Install)

Requirements:

  • Node.js (version 8 or above. Need ES6 async/await and typed array)
  • NPM
npm install one-time-pad-es6

Usage

    const otp = require("one-time-pad-es6");
    const fs = require("fs");
    
    //Encrypt String
    const HarryPotterBook1 = fs.readFileSync("./Harry_Potter_Philosopher_Stone", {encoding: "utf8"})
    const Agent007_otp = new otp(HarryPotterBook1);
    const ciphertext = await Agent007_otp.encryptString("I have the Golden Eye!", offset=100,step=5)
    
    //NOTE: - offset is the starting location of the key for padding
    //      - step is the number of character(s) in the key to skip for every plaintext character get padded

    //Decrypt String
    const plaintext = await Agent007_otp.decryptString(ciphertext, offset=100, step=5);
    
    //Pad Array Buffer
    const data = JSON.stringify({name: "Rick Sanchez", job: "Mad Scientist", weapon: "Portal Gun"});
    const buffer = new ArrayBuffer(data.length * 2);
    const view = new Uint16Array(buffer);
    data.split("").forEach((char, index) => { view[index] = char.charCodeAt(0); });
    const cipher = await Agent007_otp.pad(buffer, offset=3, step=2);
    //cipher is of type ArrayBuffer

Q&A

Q: Why this library needs node version 8 or above?

A: Specifically, this library requires async/await and typed array feature from ES2015. Any node or browser version supporting these two will suffice. Async/await is much less important as it only served as wrapper for async call. You can fork your own on github and rewrite the async/await portion.
However, the typed array feature is a must as typed array is used heavily.

Q: Why not just use one of more established library?

A: As of the writing of this library, I can't find One-Time-Pad implementation on NPM that uses modern ES2015

Q: Your library is garbage! I don't like it!

A: Then you open PR and improve it! Or don't use it! Nobody is begging you here...
Look, I get it. This library isn't super optimized. It is optimized enough for my project, and I published this on NPM so others may take advantage of my works.
I know some people (like those working in G-Company) love writing highly optimized but long and cryptic codes without documentation.
I prefer codes that can be easily and quickly understood by teammate of different experience levels so they can contribute quickly.