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

numerical-hashing-algorithm

v0.0.9

Published

A small client-side JavaScript encryption experiment

Downloads

1

Readme

Numerical Hashing Algorithm

A small client-side JavaScript encryption experiment

Updated: 3/19/21

For better visuals, see documentation/White paper.pdf

Introduction

Just a small experiment of client-side JavaScript based encryption.

Process

This section will use the string input of "Hello" (without quotes) to demonstrate the process of the Numerical Hashing Algorithm (NHA).

Binary Conversion

The input is taken and each character is converted to binary and stored in an array called binaryValues.

[1101000, 1100101, 1101100, 1101100, 1101111]

Raw 1: Output of converting all characters in the input to binary.

Binary Value Manipulation

The values from binaryValues are now each taken and multiplied by their index plus one and stored in a new array called multipliedBinaryValues.

[1101000, 2200202, 3303300, 4404400, 5505555]

Raw 2: Output of multiplying each value in binaryValues by their index plus one.

Garble Generation

The garble is generated at this stage. The garble comprises the majority of the encryption and confusion aspect of the output making it harder to crack.

Fragment 1

Once all manipulated binary values have been stored in the multipliedBinaryValues array, they are then summed together to create the multipliedBinaryValuesSum variable. The value of multipliedBinaryValueSum is then base36 encoded and any numbers in the encoding are summed, while the remaining letters are grouped together both of which are stored in an array that is returned when garbleFragement1() is called.

Fragment 2

The second fragment of the garble is generated via two parts. The first part takes the values of multipliedBinaryValues sorts them in numerical order, then multiplies them by their index plus one. They are then all summed together into a variable called numericalResult. The second part of the process encodes numericalResult into base36 and any numbers are summed together while any letters are grouped together and both are stored in an array that is returned when garbleFragment2() is called.

21rthzzso

Raw 3: Output of the garble generation formula for the input.

Finalization

The final process is simple; the garble is sorted numerically and alphabeticially.

12horstzz

Raw 4: Output of sorting the garble numerically and alphabetically.

Speed(s)

Table 1: Time taken to encrypt "Hello" over several iterations.

| Iterations | Speed (ms) | | :--------: | :--------: | | 1 | ~0.23 | | 10 | ~0.41 | | 100 | ~1.54 | | 1000 | ~13.30 | | 10000 | ~465.33 | | 100000 | ~475.00 | | 1000000 | ~4458.58 |

Usage

import NHA from 'Numerical-Hashing-Algorithm'

NHA("Hello")

Usage is simple, just import as an ES6 module and call the function with the desired input to be encrypted as the only parameter. The algorithm will encrypt the input and return it using return.

Caveats

Version Differences

When compared to a Python prototype, the JavaScript version is not as accurate mathematically which means hash values could slightly change between different versions of JavaScript. This means that both the client and server need to have an updated browser and JavaScript version or must be both on the same version of JavaScript.

Weaknesses

Considering the fact that the algorithm is purely based on basic mathematical principles and only uses base 10 numbers to encrypt, it may not be as secure as SHA256, SHA512, or some other big names in cryptography. If an attacker knows the exact length of the orignal unencrypted input, they would have a significant advantage in cracking the encryption.

Limitation(s)

One glaring limitation is JavaScript's inability to process numbers larger than $2^{53}$ which would limit the amount of characters that can be entered for encryption.

Security

As with most encryption, and similar to passwords, the longer the input, the better the encryption. NHA is no different.