Challenge 50

🗝️

Keygen

Open in Code Editor or Copy Instructions
...solutions at bottom of page...

Note: this post doesn't support piracy - in the same way 99% of the population wouldn't start filling their pockets with things from the supermarket without paying, people should also be willing to support software they like

Today and especially previously, lots of software would require a license key to be validated. Since this license key was sometimes only checked by the running software and not validated with a server, it became possibly for skilled individuals to 'crack' it by disassembling & reverse-engineering the executable

Once the algorithm used to generated keys is discovered, a keygen that can automatically generate valid keys can be created by the crackers

Windows 95 surprisingly used an incredibly simple algorithm for validating keys - a key was in the format:

nnn-nnnnnnn

Here, 'n' is a number/digit (0-9). The important things to note:

Note: the above is a slightly simplified version - the real version is listed here - you can implement it exactly if you want

Your task is to create a program that offers the following functionality:

  1. Validate product key - takes product key as a parameter and returns true or false if it's a valid license key
  2. Get all valid product keys - from "000-0000000" to "999-9999999", it should output all the valid product keys
  3. Get next product key - takes a product key as a parameter and returns it if valid, else returns the next valid product key
  4. Exit

Examples:

validate("000-0000000") would return true

validate("000-0000001") would return red

outputAllValidKeys() would output "000-0000000", "000-0000007", "000-0000016", ...

getNextValidKey("111-1111111") would return "111-1111111"

getNextValidKey("111-1111112") would return "111-1111118"

Extension:

Implement the key validating rules from the Wikipedia link exactly

Solutions

A-Level 9618