import re import sys class Riddle: def __init__(self): self.local_parts = ['}kvo}', 'zoyx}', 'sxpy', 'qkwo', 'zoyzvo'] self.msg_1 = ['$', '@', ';', '}', "'", '\\', 'o', '$', '>', '/', '[', '/', ']', '+', '-', '@', ']', ']', '!', '$', 'y', '&', '%', '|', '*', '+', '^', '^', 'F', '#', '|', '>', ':', '}', '<', ']', '.', '~', '&', '?', "'", "'", '{', "'", ] self.msg_2 = ['#', ')', '>', '\\', '!', '#', '[', 'n', '?', ')', '`', '|', '_', '^', '!', '\\', '!', '-', ')', '_', 'm', ',', '?', '+', '$', '_', '=', '%', '_', '#', '*', ':', '{', '$', '$', '@', ',', '"', ':', '+', ']', '/', 'S', ':', ] def get_word(self, word): return ''.join(list(map(lambda x: chr(ord(x) - 10), word))) def do_action(self, command, _msg, **params): msg = _msg.format(**params) try: exec('%s("%s")' % (command, msg)) except: print('Try a python function.') def get_params(self, **kwargs): try: local_parts = getattr(self, kwargs.pop('local')) except AttributeError: return regex = re.compile("[^\w*=]|_") word = ''.join(list(sum(zip(self.msg_1, self.msg_2), ()))[::-1]) word = regex.sub('', word) word = self.get_word(word) return { 'word': word, 'local_part': self.get_word( list(filter(lambda x: x, map( lambda y: y if local_parts.index(y) is 2 else None, local_parts)))[-1]) } def solve(self, command, commands, **kwargs): msg = 'mail \'{word} (%s)\' naar {local_part}@fourdigits.nl.' % ' '.join(commands) params = self.get_params(**kwargs) if params: self.do_action(command, msg, **params) rdl = Riddle() if len(sys.argv) > 2: rdl.solve(sys.argv[1], sys.argv, local=sys.argv[2])