Skip to content

Instantly share code, notes, and snippets.

@WolfangAukang
Created April 26, 2017 20:45
Show Gist options
  • Save WolfangAukang/bb417998d11e6580692a0ec9ef776f42 to your computer and use it in GitHub Desktop.
Save WolfangAukang/bb417998d11e6580692a0ec9ef776f42 to your computer and use it in GitHub Desktop.
Code based on Manuel Blum's algorithm for memorizing passwords, using the Linotype standard.
#Blum's algorithm for memorizing passwords.
#Made by Pedro Rodríguez de Oliveira (WolfangAukang), 2015.
#Linotype ordered matrix, with the variant of the numeric digits
linotype = [['e','t','a','o','i','n'],['s','h','r','d','l','u'],['c','m','f','w','y','p'],['v','b','g','k','q','j'],['x','z','0','1','2','3'],['4','5','6','7','8','9']]
#String receptor
def blumcrypto(strToCode):
strToCode = [x.lower() for x in list(strToCode)]
print (blumcryptoEncr([x.lower() for x in list(strToCode)])) #We will work with lowercase letters
#Main algorithm, converter
def blumcryptoEncr(listToCode):
#Direction indicator, which is North(0), East(1), South(2), West(3)
direction = 0
for i in range(0,len(listToCode)):
if listToCode[i] != " ": #Ignore spaces
positions = returnXY(listToCode[i])
if positions == -1: #Invalid character has been read, send error
return("Error, invalid character on input. It must contain characters from A to Z or 0 to 9")
xpos = positions[0]
ypos = positions[1]
if direction == 0: #North
listToCode[i] = linotype[(ypos-1)%6][xpos].title()
elif direction == 1: #East
listToCode[i] = linotype[ypos][(xpos+1)%6].title()
elif direction == 2: #South
listToCode[i] = linotype[(ypos+1)%6][xpos].title()
else: #West
listToCode[i] = linotype[ypos][(xpos-1)%6].title()
#Add to direction
direction = (direction + 1) % 4
#Return converted string
return "".join(listToCode)
#Character finder on Linotype matrix
def returnXY(char):
for y in range(0,len(linotype)):
for x in range(0,len(linotype)):
if linotype[y][x] == char: #If found, return positions on list
return [x,y]
return -1 #If not found, return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment