Code Monkey home page Code Monkey logo

hmmhmmhm / pseudo-shuffle Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 0.0 172 KB

(FE1 FPE) Make the index look like it is shuffled according to the range so that it is not conflicted without the actual shuffle. (Support Node & Browser)

Home Page: https://codesandbox.io/p/sandbox/pseudo-shuffle-demo-1hycrr

License: MIT License

JavaScript 4.31% TypeScript 95.69%
cjs esm format-preserving-encryption fpe shuffle typescript umd shuffle-algorithms javascript nodejs

pseudo-shuffle's Introduction

๐Ÿ”€ pseudo-shuffle

Actual Image

๐Ÿ“œ Make the index look like it is shuffled according to the range so that it is not conflicted without the actual shuffle.


๐Ÿš€ Usage

1. Install

npm install pseudo-shuffle

2. Basic Encode - Decode Example

import { encode, decode } from "pseudo-shuffle";

const encoded = encode({
  min: 0,
  max: 100,
  index: 3,
});
console.log(`encoded:`, encoded);
// encoded: 29

const decoded = decode({
  min: 0,
  max: 100,
  index: encoded,
});
console.log(`decoded:`, decoded);
// decoded: 3

3. 7 Length Base 36 Shuffle Example

import { encode, decode } from "pseudo-shuffle";

const privateKey = "something-secret-any-string-like-this!";

const encoded = encode({
  min: 0,
  max: 36 ** 7 - 1,
  index: 3,
  privateKey,
});
console.log(`encoded:`, encoded.toString(36));
// encoded: ltne180

const decoded = decode({
  min: 0,
  max: 36 ** 7 - 1,
  index: encoded,
  privateKey,
});
console.log(`decoded:`, decoded);
// decoded: 3

โš ๏ธ Caution

  1. pseudo-shuffle is pseudo random, not truly random. As a result, the library can encode or decode the shuffled sequence on the fly without having to remember all the shuffled values.
  2. Algorithm can be applied only when the difference between the min and max values is at least 4. In this case, it doesn't throw an error, it just doesn't apply the shuffle.
  3. The private and public keys are set to their defaults. If you want more security, set the privateKey.
  4. This library was developed to make it easier to use the node-fe1-fpe library without a lot of exception handling, and the real genius is the person who wrote it.

โœ… License

MIT Licensed.

pseudo-shuffle's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.