Coder Social home page Coder Social logo

fakerng's Introduction

A simple tool to convert serial numbers into another number that looks like random number.

It uses modular multiplicative inverse to build a bijection function and its inverse function. The domain and codomain of both functions are n-digit integer (0 ~ 10^n-1, inclusive).

Usage

// integer
a := fakerng.MustRawConverter(4, 9529)
a.Enc(9991) // returns 4720
a.Dec(4720) // returns 9991
// string
str, err := a.Encode("9991") // returns "4720"
str, err := a.Decode("4720") // returns "9991"

// more digits (12 digits
b := fakerng.New(
        fakerng.MustRawConverter(6, 910110),
        fakerng.MustRawConverter(6, 977691),
)
str, err := b.Encode("000000002278") // returns "910110177871"
str, err := b.Decode("910110177871") // returns "000000002278"

// multiple pass to increase randomness (5 pass)
c := fakerng.NewNPass(
        fakerng.New(
                fakerng.MustRawConverter(4, 9566),
        ),
        fakerng.New(
                fakerng.MustRawConverter(4, 9456),
        ),
        fakerng.New(
                fakerng.MustRawConverter(4, 9247),
        ),
        fakerng.New(
                fakerng.MustRawConverter(4, 9953),
        ),
        fakerng.New(
                fakerng.MustRawConverter(4, 9683),
        ),
)
str, err := c.Encode("9991") // returns "5373"
str, err := c.Decode("5373") // returns "9991"

There's a tool to generate codes above for you.

go get -u github.com/raohwork/fakerng

fakerng -h

License

This software is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at Mozilla MPL.

fakerng's People

Contributors

ronmi 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.