""" A file of secret functions. You weren't able to see this code during the lab, but you had to figure out what was happening using the debugger. """ def a(x, y): "Adds two things together." return y + x def b(x): "Scrambles up a string." parts = x.split() return '\n'.join(parts[::-1]) + '\n\n' def c(x, y): "Encrypts or decrypts a message using a password." # Pad password to length of message while len(y) < len(x): y = y * 2 result = '' # Swizzle each character for i in range(len(x)): c = x[i] p = y[i] result += crypt(c, p) return result def d(x, y): "Decrypts a message using a password." # Pad password to length of message while len(y) < len(x): y = y * 2 result = '' # Un-swizzle each character for i in range(len(x)): c = x[i] p = y[i] result += decrypt(c, p) return result def an(x): "Returns number from alphabetic value." o = ord(x) if 0 <= o - ord('a') < 26: # lowercase letter return o - ord('a') elif 0 <= o - ord('A') < 26: # uppercase letter return 26 + o - ord('A') elif 0 <= o - ord('0') < 10: # number return 52 + o - ord('0') elif x == ' ': return 62 elif x == '\n': return 63 else: return None def na(n): "Returns letter." if n == 63: return '\n' elif n == 62: return ' ' elif n < 26: return chr(ord('a') + n) elif n < 52: return chr(ord('A') + (n - 26)) else: return chr(ord('0') + (n - 52)) def crypt(a, b): "Encrypts letter a using letter b." n1 = an(a) n2 = an(b) if n1 is None or n2 is None: return a c = (n1 + n2) % 64 return na(c) def decrypt(a, b): "Decrypts letter a using letter b." n1 = an(a) n2 = an(b) if n1 is None or n2 is None: return a c = (n1 - n2) % 64 return na(c)