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.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

cccodes-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cccodes-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 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.0.tar.gz
Algorithm Hash digest
SHA256 c4c28c9b617278b0b8c7cbf56988e8eaa98d4dbfbde2c473fbedd451aaef2e7d
MD5 8a4dd284e6d8ecce90416198c047c586
BLAKE2b-256 5e631b34369269fe12d11d743bc512b2d3be54a45174a3fb42cf2a593a74449a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cccodes-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9456e8d743e49570d37ab28b50f1cd492dac79b1ab68132867ca1766a2e6c0fe
MD5 cda57ecaa1d46f43cc21f5671b744a98
BLAKE2b-256 b984fef775b4ef811bd1b90dee30cdc420ae858ba4eed5699e3f176c41e5b71f

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