-
-
Save einstein95/e3bbd846345c2505be443231754485f0 to your computer and use it in GitHub Desktop.
Starcraft CD-Key Validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
def validate(key): | |
magic = 3 | |
count = 0 | |
for c in key: | |
if not c.isdigit(): | |
continue | |
v = int(c) | |
count += 1 | |
if count == 13: | |
return(magic % 10 == v) | |
else: | |
v ^= magic * 2 | |
magic += v | |
def main() | |
if (len(argv) == 1) | |
# self-test. | |
if not validate("0000-00000-0003"): | |
return(False) | |
if not validate("1234-56789-0123"): | |
return(False) | |
if not validate("1337-42069-0008"): | |
return(False) | |
if not validate("1998-00000-1997"): | |
return(False) | |
if not validate("3333-33333-3333"): | |
return(False) | |
return(True) | |
for i in argv: | |
validate(i) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment