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

@cryptoolsorg/bitshiftcipher

v1.0.0

Published

A homemade encryption solution

Downloads

7

Readme

BitShift Cipher

A homemade encryption solution

How it works

Encoding

The Bitshift Cipher works by (as the name suggests) shifting over the bits of the text's ASCII. We do this using the bitwise << operator, which is used to shift the bits a certain number of places.

To encode the text, we loop through the text, and for each character x, we loop through the key array, and for each key character i:

x = x + 1 << i % 8

We limit the maximum shift using modulo to avoid having a bit shifted by hundreds of places

Example:

Let's imagine we are currently working on the character A, and that our key is YO

A = 0b01000001 # ASCII for A
    0b01000010 # plus 1
    0b010000100 # Y is 89, 89 % 8 = 1, so we add 1 zero.
    # next charachter in key: O
    0b010000101 # plus 1
    0b0100001010000000 # O is 79, 79 % 8 = 7, so we add 7 zeros.

After each character is encoded, we add it to an array and reverse the key to make frequency analysis harder.

Let's say the next character in our string is B, our key now is OY, as it was reversed.

B = 0b01000010 # ASCII for B
    0b01000011 # plus 1
    0b010000110000000 # O is 79, 79 % 8 = 7, so we add 7 zeros.
    # next character in key: Y
    0b010000110000001 # plus 1
    0b0100001100000010 # Y is 89, 89 % 8 = 1, so we add 1 zero.

Our array now looks like this: [0b0100001010000000, 0b0100001100000010], or in decimal: [17024, 17154].

Finally, we encode the array in base64 to get the final encrypted string: b'WzE3MDI0LCAxNzE1NF0='.

Decoding

To decode, we start by decoding and evaluating the base64 string, and then we reverse the key. We can then loop through the text and key like for the encoding process:

x = x - 1 >> i % 8

Example:

The character A was encoded as 0b0100001010000000. The key was YO, but we reversed it, so we will be using OY.

A = 0b0100001010000000
  = 0b0100001001111111  # minus 1
  = 0b010000100 # O is 79, 79 % 8 = 7, so we remove the 7 least significant bits
  # next character in key: Y
  = 0b010000011 # minus 1
  = 0b01000001 # Y is 89, 89 % 8 = 1, so we remove the least significant bit

0b01000001 is A in ASCII, so we have successfully decoded the first letter. We carry on like this, making sure that we remember to reverse the key every time.

Pros & Cons

Pros

  • Reversing the key makes frequency analysis hard.
  • Key can be as long as you want (theoretically, depends on your programming language), and include special characters, making brute force harder.

Cons

  • Different languages have different outputs depending on the base64 support.
  • Developed at CrypTools by @arguiot, who isn't a professional cryptologist, so it might have some security issues.

Implementations

| Language | Encrypt | Decrypt | |------------|-----------------------------|-----------------------------| | Javascript | encrypt.js | decrypt.js | | Python | encrypt.py | decrypt.py | | Swift | lib.swift| lib.swift|

Package managers

NPM:

npm i @cryptoolsorg/bitshiftcipher

Running the tests

Tests are automatically handled by Travis CI.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Arthur Guiot - Initial work & conception - @arguiot

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details