コード例 #1
0
def processing_request(input_text, args):
    if args.mode == "counting_frequency":
        counting_frequency.dump_frequency(input_text, args.output_file)
    else:
        if args.cipher == 'caesar':
            if args.mode == 'encode':
                output_text = caesar_cipher.encode(input_text, int(args.key))
            elif args.mode == 'decode':
                output_text = caesar_cipher.decode(input_text, int(args.key))
            elif args.mode == 'hack':
                output_text = caesar_cipher.hack(input_text,
                                                 args.symbols_frequency)
        elif args.cipher == 'vigenere':
            if args.mode == 'encode':
                output_text = vigenere_cipher.encode(input_text, args.key)
            elif args.mode == 'decode':
                output_text = vigenere_cipher.decode(input_text, args.key)
        print_output_text(args.output_file, output_text)
コード例 #2
0
def encrypt(cipher, mode, input_text, key=None):
    if cipher == 'caesar':
        if mode == 'hack':
            return caesar_cipher.hack(
                input_text, "./symbols_frequency/symbols_frequency.pickle")
        try:
            key = int(key)
        except Exception as e:
            return "For caesar's cipher, the key must be an integer"
        if mode == 'encode':
            return caesar_cipher.encode(input_text, key)
        elif mode == 'decode':
            return caesar_cipher.decode(input_text, key)
    else:
        for symbol in key:
            if symbol not in SYMBOLS_TO_POSITIONS:
                return "Symbol '" + symbol + "' not in alphabet"
        if mode == 'encode':
            return vigenere_cipher.encode(input_text, key)
        elif mode == 'decode':
            return vigenere_cipher.decode(input_text, key)
        elif mode == 'hack':
            return "Sorry, this function is not implemented"
import caesar_cipher as cc

myI = [1, 1, 1, 1]
text = cc.encode("Zeta Zeza Mario", myI)

print(text)

print(cc.decode(text, myI))
コード例 #4
0
 def test_encode_two(self):
     test_input = 'middle-Outz'
     test_ans = encode(test_input, 2)
     self.assertIsNotNone(test_ans)
     self.assertEqual('okffng-Qwvb', test_ans)
コード例 #5
0
 def test_encode(self):
     test_input = 'alex'
     test_ans = encode(test_input, 0)
     self.assertIsNotNone(test_ans)
     self.assertEqual(test_input, test_ans)