GithubHelp home page GithubHelp logo

idconverter's Introduction

IdConverter

Introduction

Sometimes we need to hide the real id of the database to the user of a web application. The following implementation allow us to apply a completely random biyective function to a given ID to show it to the user and get it back again applying the inverse function.

How it works

The ids of an Sql database are base 10 integers, to get a shorter id we need to write that number in a higher base. To accomplish that we need to define an alphabet representing each digit of another numeric base. If we choose base 64 we need to map numbers 0 to 63 each one to a symbol in our new alphabet. The symbols in the new alphabet will be used to "create" the id in base 64. To obtain the corresponding id in base 64 we just convert the original base 10 id to base 64 using the mapped characters applying the following algorithm:

pre: numberToConver >= 0 and baseToConvert > 1 and DigitsList.length = 0

post: DigitList contains each digit of the numberToConvert in base baseToConvert

num = numberToConvert

while num > 0

remainder = modulo(num, baseToConvert)

DigitsList.add(remainder)

num = num / baseToConvert

return DigitsList.reverse

Then for each element in the DigitsList we must get the corresponding symbol in our alphabet. The inverse function is analogous.

Requirements

  • We must to be capable to define several alphabets to enconde our ids to be used in differents parts of our web application.
  • We must get shorten ids than the originals.
  • We must broke the current ids from MongoDB.
  • We must define random alphabets from the ascii table and to be able to exclude certain characters.
  • We need a way to identify each alphabet and the converted ids.

Analysis

  • We need some data structures to work with differents alphabets
  • We need a way to identify the encoded ids, the alphabet and the base
  • We need a way to broke the string of the original id
  • We need an algorithm to encode and decode the ids
  • We need a way to ask for a new alphabet when needed
  • We need to save and load alphabets from a database

Design

  • We need an entity that represents the alphabet and has: a prefix of the alphabet to include in the converted id, the alphabet with his mapping, and the base of the encoding
  • We need one algorithm to encode and other to decode
  • We need to save the alphabets

idconverter's People

Contributors

antidata avatar

Stargazers

 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.