Skip to content

Instantly share code, notes, and snippets.

@igorvanloo
Created July 25, 2021 14:08
Show Gist options
  • Save igorvanloo/f9a3ecfef4a6e9a98f5e7f5930ea8a10 to your computer and use it in GitHub Desktop.
Save igorvanloo/f9a3ecfef4a6e9a98f5e7f5930ea8a10 to your computer and use it in GitHub Desktop.
Problem 59
def compute(cipher):
possiblecodes = []
for x in range(97,123):
for y in range(97, 123):
for z in range(97,123):
password = chr(x) + chr(y) + chr(z)
count = 0
decrypt = []
for i in cipher:
temp = i^(ord(password[count % 3]))
if AcceptableChar(temp) == False:
break
else:
count += 1
decrypt.append(temp)
if len(decrypt) == len(cipher):
finaltext = "".join(chr(x) for x in decrypt)
total = sum(decrypt)
possiblecodes.append((finaltext, total, password))
return possiblecodes
def AcceptableChar(char):
if char < 32:
return False
elif char > 122:
return False
elif 60 <= char <= 62:
return False
elif char == 64 or char == 42:
return False
elif 36 <= char <= 38:
return False
else:
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment