Git Product home page Git Product logo

coupon-encode's Introduction

coupon-encode

The purpose of this encoding scheme is generating coupon codes. It was originally wrote for ClickCupom, a "deal of the day" website in Brazil.

The standard base32 encoding will generate codes that can be hard to read over the phone (because of characters like I/l/1 and O/0). It also has potential to generate f* words (at least in Portuguese) and the sequence is easy to guess.

This special base 32 scheme has the following attributes:

  • to make it easy to read over the phone, chars I/L/O are not used (avoids confusion with 1/0)
  • the letter U is not used (to decrease the possibility of f* words)
  • the generated codes are not trivial to guess

By default it will generate 5 digit coupon codes, but can generate codes with any number of digits.

CouponEncoder()

Initialize this object with a key made with the characters 'ABCDEFGHJKMNPQRSTWVXYZ0123456789' in random order.

Example:

  >>> c = CouponEncoder('10BEH8G426RADWZVF9JPKX5QMC3YTN7S')
  >>> c.encode(15171013)
  'FS19E'
  >>> c.decode('FS19E')
  15171013
  >>> code, check = c.encode_with_verification(1234)
  ('NH4RZ', '782AV')
  >>> c.is_valid(code, check)
  True
  >>> c.is_valid(code, '782AA')
  False

coupon-encode's People

Contributors

scardine avatar

Stargazers

 avatar

Watchers

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