Skip to content

Instantly share code, notes, and snippets.

@morgant
Forked from anonymous/pt100reg.py
Last active April 4, 2024 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save morgant/ad56d9dc487e2ab389b13c45fd178c5a to your computer and use it in GitHub Desktop.
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
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))
@morgant
Copy link
Author

morgant commented Oct 22, 2023

s/raw_input/input for Python 3 support, per this 68kmla thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment