{"id":28418520,"url":"https://github.com/rebeccapowell/csharp-algorithm-coupon-code","last_synced_at":"2025-06-28T04:31:25.812Z","repository":{"id":41407081,"uuid":"44112601","full_name":"rebeccapowell/csharp-algorithm-coupon-code","owner":"rebeccapowell","description":"Implementation of Perl's Algorithm::CouponCode in C# - https://www.nuget.org/packages/Powell.CouponCode/","archived":false,"fork":false,"pushed_at":"2021-05-04T10:53:45.000Z","size":548,"stargazers_count":27,"open_issues_count":3,"forks_count":15,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-04T17:20:18.934Z","etag":null,"topics":["code","coupon","csharp","perl","port"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rebeccapowell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-12T14:29:47.000Z","updated_at":"2025-04-28T14:38:21.000Z","dependencies_parsed_at":"2022-08-25T11:41:16.034Z","dependency_job_id":null,"html_url":"https://github.com/rebeccapowell/csharp-algorithm-coupon-code","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rebeccapowell/csharp-algorithm-coupon-code","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeccapowell%2Fcsharp-algorithm-coupon-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeccapowell%2Fcsharp-algorithm-coupon-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeccapowell%2Fcsharp-algorithm-coupon-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeccapowell%2Fcsharp-algorithm-coupon-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rebeccapowell","download_url":"https://codeload.github.com/rebeccapowell/csharp-algorithm-coupon-code/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeccapowell%2Fcsharp-algorithm-coupon-code/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262375679,"owners_count":23301336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code","coupon","csharp","perl","port"],"created_at":"2025-06-04T11:17:23.098Z","updated_at":"2025-06-28T04:31:25.748Z","avatar_url":"https://github.com/rebeccapowell.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Logo](https://repository-images.githubusercontent.com/44112601/e7646680-3302-11eb-91df-9962cfb40da5)\n\n# csharp-algorithm-coupon-code\nImplementation of Perl's Algorithm::CouponCode in C#\n\n```\nInstall-Package Powell.CouponCode -Version 1.0.3\n```\n\nSupports net35, net40, net45 and netstandard20. netstandard\u003c20 not supported due to System.Security.Cryptography deficit.\n\nPort of http://search.cpan.org/dist/Algorithm-CouponCode/\n\nCopyright 2011 Grant McLean grantm@cpan.org\n\nWith nods to the various other language ports for guidance:\n- https://github.com/baxang/coupon-code/blob/master/lib/coupon_code.rb\n- https://github.com/chilts/node-coupon-code/blob/master/coupon-code.js\n\n## Synopsis\n A 'Coupon Code' is made up of letters and numbers grouped into 4 character\n 'parts'.  For example, a 3-part code might look like this:\n \n 1K7Q-CTFM-LMTC\n\n Coupon Codes are random codes which are easy for the recipient to type\n accurately into a web form.  An example application might be to print a code on\n a letter to a customer who would then enter the code as part of the\n registration process for web access to their account.\n\n Features of the codes that make them well suited to manual transcription:\n  - The codes are not case sensitive.\n  - Not all letters and numbers are used, so if a person enters the letter 'O' we\n    can automatically correct it to the digit '0' (similarly for I =\u003e 1, S =\u003e 5, Z =\u003e 2).\n - The 4th character of each part is a checkdigit, so client-side scripting can\n    be used to highlight parts which have been mis-typed, before the code is even\n    submitted to the application's back-end validation.\n - The checkdigit algorithm takes into account the position of the part being\n    keyed.  So for example '1K7Q' might be valid in the first part but not in the\n    second so if a user typed the parts in the wrong boxes then their error could\n    be highlighted.\n - The code generation algorithm avoids 'undesirable' codes. For example any code\n    in which transposed characters happen to result in a valid checkdigit will be\n    skipped.  Any generated part which happens to spell an 'inappropriate' 4-letter\n    word (e.g.: 'P00P') will also be skipped.\n - The code returned by Generate() is random, but not necessarily unique.\n    If your application requires unique codes, it is your responsibility to\n    avoid duplicates (for example by using a unique index on your database column).\n - The codes are generated using a SHA1 cryptographic hash of a plaintext.  If you\n    do not supply a plaintext, one will be generated for you (using RNGCryptoServiceProvider).  \n    In the event that an 'inappropriate' code is created, the generated hash will be \n    used as a plaintext input for generating a new hash and the process will be repeated.\n - Each 4-character part encodes 15 bits of random data, so a 3-part code will\n    incorporate 45 bits making a total of 2^45 (approximately 35 trillion) unique\n    codes.\n\n## string Generate(Options opts) method:\nReturns a coupon code as a string of 4-character parts separated by '-'\ncharacters.  The following optional named parameters may be supplied:\n\nExample:\n```\nvar opts = new Options();\nvar ccb = new CouponCodeBuilder();\nvar badWords = ccb.BadWordsList;\nvar code = ccb.Generate(opts);\n// code example EED9-128L-BJUQ\n```\n\n### Parts\nThe number of parts desired.  Must be a number in the range 1 - 6.  Default is 3.\n\n### Plaintext\nA byte string which will be hashed using Digest::SHA to produce the code.\nIf you do not supply your own plaintext then a random one will be generated for you.\n\n## string Validate(string code, Options opts)\n\nTakes a code, cleans it up and validates the checkdigits.  Returns the\nnormalised (and untainted) version of the code on success or undef on error.\nThe following named parameters may be supplied:\n\n### Code\nThe code to be validated.  The parameter is mandatory.\n\n### Parts\nThe number of parts you expect the code to contain.  Default is 3.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebeccapowell%2Fcsharp-algorithm-coupon-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frebeccapowell%2Fcsharp-algorithm-coupon-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebeccapowell%2Fcsharp-algorithm-coupon-code/lists"}