Skip to main content

Coupon codes algorithm

Project description

couponcodes

Implements the Coupon Codes Algorithm from Dan Mclean:

CouponCodes are designed to be distributed in printed form and typed into a web form. Features of the codes that make them well suited to manual transcription:

  • The codes are not case sensitive.
  • Not all letters and numbers are used, so if a person enters the letter 'O' we can automatically correct it to the digit '0' (similarly for I ⇨ 1, S ⇨ 5, Z ⇨ 2).
  • The 4th character of each part is a checkdigit, so client-side scripting can be used to highlight parts which have been mis-typed, before the code is even submitted to the application's back-end validation.
  • The checkdigit algorithm takes into account the position of the part being keyed. So for example '1K7Q' might be valid in the first part but not in the second so if a user typed the parts in the wrong boxes then their error could be highlighted.
  • The code generation algorithm avoids 'undesirable' codes. For example any code in which transposed characters happen to result in a valid checkdigit will be skipped. Any generated part which happens to spell an 'inappropriate' 4-letter word (e.g.: 'P00P') will also be skipped.
  • Codes can be generated and validated on the server

This python implementation is not written or endorsed by Dan Mclean.

Known bugs/shortcomings compared to upstream:

  • Too lazy to rot13 the bad words, you have to live with them in the repo.
  • You can not select your own plaintext, it will only generate new random codes.
  • This code has been barely tested and not audited, security and fit for purpose is your problem.

All other shortcomings are bugs and you should file issues. Patches to fix the known shortcomings welcome.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cccodes-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

cccodes-0.1.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file cccodes-0.1.1.tar.gz.

File metadata

  • Download URL: cccodes-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0

File hashes

Hashes for cccodes-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ea31ea970c8b2715d2abb003aac974951ffffa1ff259f46e87c0210bf7c57540
MD5 0cc2047c0e24be58a28890e7294adddf
BLAKE2b-256 689f450038ec53e513ef80321ac1a45b41add5ef1c22ae71b5d195b6e3f3adc5

See more details on using hashes here.

File details

Details for the file cccodes-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cccodes-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0

File hashes

Hashes for cccodes-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6be0cd755b89ba51f395661f6117a105f0273f14fd34a416cac068c684cae093
MD5 faee3361490b4cee127b7ccb936b0e61
BLAKE2b-256 e129e3bab12905755ba4e27f64c14e6d6e7b8c13d353515b97a6b15291b7118b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page