-
-
Save morgant/ad56d9dc487e2ab389b13c45fd178c5a to your computer and use it in GitHub Desktop.
PT100Reg - allows you to create a registration key for the PT100 terminal emulator for Newton
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
maxUnsigned = 0x1FFFFFFF | |
bitsInUnsigned = int(29) | |
seventyFivePercent = int(22) | |
twelvePercent = int(4) | |
highBits = 0x1E000000 | |
lowBits = 0x01FFFFFF | |
def generateRegCode(userName): | |
reg = "" | |
sn = "" | |
string = userName + "PT100" | |
while len(string) < 20: | |
string = string + string | |
h = int(0) | |
g = int(0) | |
s_len = len(string) | |
for i in range(s_len): | |
h = (((h << twelvePercent) & maxUnsigned) + ord(string[i])) & maxUnsigned | |
g = h & highBits | |
if g != 0: | |
h = (h ^(g >> seventyFivePercent)) & lowBits | |
for i in range(0, 26, 3): | |
reg = reg + chr(((h>>i) & 0x0f) + 97); | |
return(reg) | |
if __name__ == "__main__": | |
name = input("Please enter the Newton's serial number\n") | |
print("Registration key is:\n") | |
print(generateRegCode(name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
s/raw_input/input
for Python 3 support, per this 68kmla thread.