I am writing a system, for which I need to generate unique transaction numbers (which can be verified by myself). I want to use something similar to that used by credit cards, where a string of the form:


I want to be able to craft an algorithm that generates only a subset of the range of keys possible from the set of all possible combinations of keys above.

I don't know much about security, but I'm guessing that the solution would probably involve coming up with a logic procedure that restricts the generated set, such that members of the 'valid' set, satisfy a CRC check.

I would be grateful if anyone could shed more light on how to implement this.

  • crypto.stackexchange.com/questions/tagged/format-preserving ​ ​ – user49075 May 15 '16 at 12:44
  • This is probably doable, but it depends on what other properties you want your generated numbers to have. The easiest implementation would simply be a 15-digit base 36 number (0-9 + A-Z), which gets increased by 1 each time, and then a Luhn check-digit appended. Of course, that pattern would be really obvious to anyone who had several sequential transactions, but you may not care about that. If you don't want the numbers to be guaranteed sequential, it can get more advanced. – Bobson Jun 14 '16 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.