Skip to content

Instantly share code, notes, and snippets.

@einstein95
Forked from notwa/sckey.c
Last active August 22, 2017 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einstein95/e3bbd846345c2505be443231754485f0 to your computer and use it in GitHub Desktop.
Save einstein95/e3bbd846345c2505be443231754485f0 to your computer and use it in GitHub Desktop.
Starcraft CD-Key Validator
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