Шифърът на Цезар

Краен срок
04.04.2014 23:59

Срокът за предаване на решения е отминал

Шифърът на Цезар е вид шифър с пряка субституция (субституционен шифър) - това означава, че всяка буква се замества само с една и съща друга буква, в целия текст. Според някои исторически източници, този шифър е използван от Гай Юлий Цезар.

Предизвикателството

Напишете декоратори ceaser_output и ceaser_input, които да работят на базата на Шифърът на Цезар.

ceaser_output:

Променя изхода на декорираната функция със съответното отместване според Цезаровия шифър. Декораторът приема един аргумент, който указва големината на отместването.

Пример

@ceaser_output(13)
def cross_the_river():
    return "ALEA IACTA EST"


>>> print(cross_the_river())
NYRN VNPGN RFG

ceaser_input:

  • също приема число за отместване
  • приема и функция, която може да бъде използвана за избирателно прилагане на шифъра

Пример

@ceaser_input(-13, lambda key: key > 0)
def make_a_speech(name, *args):
    print('{} says:\n{}'.format(name, ' '.join(args)))


>>> make_a_speech('Reg', 'JUNG', 'UNIR', 'GUR', 'EBZNAF',
                  'RIRE', 'QBAR', 'SBE', 'HF?', '...')
Reg says:
WHAT HAVE THE ROMANS EVER DONE FOR US? ...

Бележки:

  • без значение са главни/малки букви за низовете, които ще бъдат шифровани, а резултатитеа от шифрирането са винаги в главни букви
  • положително отместване означава преместване надясно(1: Z=>A, A=>B, B=>C ...), а отрицателно - наляво(-1: B=>A, A=>Z ...).

Решения

Веселин Генадиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Веселин Генадиев
from string import ascii_letters, ascii_uppercase
def shift(symbol, key):
if not symbol.isalpha():
return symbol
letter_position = ascii_letters.index(symbol) % 26
return ascii_uppercase[(letter_position + key) % 26]
def ceaser_encrypt(text, key):
return ''.join(shift(symbol, key) for symbol in text)
def ceaser_output(key):
def encrypt(function):
def encrypted(*args):
text = function(*args)
return ceaser_encrypt(text, key)
return encrypted
return encrypt
def ceaser_input(key, predicate):
def encrypt(function):
def encrypted(*args):
args = [ceaser_encrypt(argument, key) if predicate(index)
else argument for index, argument in enumerate(args)]
return function(*args)
return encrypted
return encrypt
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Драгомир Тунчев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Драгомир Тунчев
def is_lower_latin(character):
return ord(character) in range(ord('a'), ord('z') + 1)
def is_upper_latin(character):
return ord(character) in range(ord('A'), ord('Z') + 1)
def encode_lower_latin(character, offset):
return chr(((ord(character) + offset) - ord('a')) % 26 + ord('A'))
def encode_upper_latin(character, offset):
return chr(((ord(character) + offset) - ord('A')) % 26 + ord('A'))
def ceaser_output(offset):
def function(func):
def decorated(*args):
return ''.join(map(str, [encode_upper_latin(character, offset)
if is_upper_latin(character)
else character
for character in func(*args).upper()]))
return decorated
return function
def ceaser_input(offset, chooser):
def function(func):
def decorated(*args):
arguments = []
for position in range(len(args)):
if chooser(position):
argument = [encode_upper_latin(character, offset)
if is_upper_latin(character)
else encode_lower_latin(character, offset)
if is_lower_latin(character)
else character.upper()
for character in list(args[position])]
else:
argument = [character
for character in list(args[position])]
arguments.append(''.join(map(str, argument)))
return func(*tuple(' '.join(map(str, arguments)).split()))
return decorated
return function
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Йосиф Цветков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Йосиф Цветков
from string import ascii_uppercase as alpha
def ceaser_output(shift):
def new_function(function):
def decorated_function(*args, **kwargs):
final = []
for character in function(*args, **kwargs).upper():
final.append((alpha[(alpha.index(character) + shift) % 26]
if character in alpha else character))
return ''.join(final)
return decorated_function
return new_function
def ceaser_input(shift, to_transform):
def new_function(function):
def decorated_function(*args):
final = []
for index, word in enumerate(args):
final.append(ceaser_output(shift)(lambda x: x)(word))\
if to_transform(index) else final.append(word)
return function(*final)
return decorated_function
return new_function
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Михаил Станин
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Михаил Станин
def ceaser_output(move):
def wrap(f):
def moveRight(input_letter, move):
if ord(input_letter) + move > ord('Z'):
return (chr(ord('A') + (move - 1 -
(ord('Z') - ord(input_letter)))))
else:
return chr(ord(input_letter) + move)
def moveLeft(input_letter, move):
if ord(input_letter) + move < ord('A'):
return (chr(ord('Z') + (move + 1 -
(ord('A') - ord(input_letter)))))
else:
return chr(ord(input_letter) + move)
def wrapped_f():
text = f().upper()
ceaser_text = ""
for letter in text:
if letter.isalpha():
if move > 0:
ceaser_text += moveRight(letter, move)
else:
ceaser_text += moveLeft(letter, move)
else:
ceaser_text += letter
print(ceaser_text.upper())
return wrapped_f
return wrap
def ceaser_input(move, func):
def wrap(f):
def moveRight(input_letter, move):
if ord(input_letter) + move < ord('A'):
return (chr(ord('Z') + (move + 1 -
(ord('A') - ord(input_letter)))))
else:
return chr(ord(input_letter) + move)
def moveLeft(input_letter, move):
if ord(input_letter) + move > ord('Z'):
return (chr(ord('A') + (move - 1 -
(ord('Z') - ord(input_letter)))))
else:
return chr(ord(input_letter) + move)
def wrapped_f(name, *args):
normal_text = name + " says:\n"
for arg in ' '.join(args):
for letter in arg:
if letter.isalpha():
if move > 0:
normal_text += moveLeft(letter, move)
else:
normal_text += moveRight(letter, move)
else:
normal_text += letter
print(normal_text)
return wrapped_f
return wrap
F
Stdout:
Reg says:
WHAT HAVE THE ROMANS EVER DONE FOR US? ...
F
Stdout:
NYRN VNPGN RFG
F
Stdout:
XYZABCDEFGHIJKLMNOPQRSTUVW
F
Stdout:
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG

======================================================================
FAIL: test_ceaser_input (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1931jpj/test.py", line 32, in test_ceaser_input
    self.assertEqual(real_input, expected_input)
AssertionError: None != 'Reg says:\nWHAT HAVE THE ROMANS EVER DONE FOR US? ...'

Stdout:
Reg says:
WHAT HAVE THE ROMANS EVER DONE FOR US? ...

======================================================================
FAIL: test_ceaser_output (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1931jpj/test.py", line 13, in test_ceaser_output
    self.assertEqual(decorated(), "NYRN VNPGN RFG")
AssertionError: None != 'NYRN VNPGN RFG'

Stdout:
NYRN VNPGN RFG

======================================================================
FAIL: test_output_with_overflowing (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1931jpj/test.py", line 19, in test_output_with_overflowing
    self.assertEqual(decorated(), "XYZABCDEFGHIJKLMNOPQRSTUVW")
AssertionError: None != 'XYZABCDEFGHIJKLMNOPQRSTUVW'

Stdout:
XYZABCDEFGHIJKLMNOPQRSTUVW

======================================================================
FAIL: test_the_quick_brown_fox (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1931jpj/test.py", line 40, in test_the_quick_brown_fox
    self.assertEqual(decorator(lambda: encoded)(), message)
AssertionError: None != 'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG'

Stdout:
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG

----------------------------------------------------------------------
Ran 4 tests in 0.004s

FAILED (failures=4)
Божидар Михайлов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Михайлов
def encrypt_word(word, shift):
def encrypt_char(c):
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
return LETTERS[(ord(c) - ord('A') + shift) % 26] if c in LETTERS else c
return ''.join(encrypt_char(c) for c in word.upper())
def ceaser_input(shift, arg_filter):
def shifter(f):
def shifted(*args):
return f(*[encrypt_word(word, shift) if arg_filter(i)
else word for i, word in enumerate(args)])
return shifted
return shifter
def ceaser_output(shift):
def shifter(f):
return lambda *args: ''.join(encrypt_word(f(*args).upper(), shift))
return shifter
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Тихомир Янев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Тихомир Янев
import re
def ceaser_shift(string, offset):
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ALPHABET_SIZE = len(ALPHABET)
return re.sub('[A-Z]', lambda x: ALPHABET[(ALPHABET.index(
x.group()) + offset) % ALPHABET_SIZE], string.upper())
def ceaser_output(n=0):
return lambda f: lambda *args: f(*args) if n == 0 \
else ceaser_shift(f(*args), n)
def ceaser_input(n, func):
return lambda f: lambda *args: f(*map(lambda x: \
ceaser_shift(x, n) if func(args.index(x)) else x, args))
....
----------------------------------------------------------------------
Ran 4 tests in 0.004s

OK
Георги Стайков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Стайков
def shift(symbol, number):
new_symbol_ascii = ((ord(symbol) - 65) + number) % 26
return chr(new_symbol_ascii + 65)
def shift_string(string, number):
result = ""
for symbol in string:
symbol = symbol.upper()
if symbol.isalpha():
result += shift(symbol, number)
else:
result += symbol
return result
def ceaser_output(number):
def ceaser_code(function):
def decorated():
return shift_string(function(), number)
return decorated
return ceaser_code
def ceaser_input(number, predicate):
def ceaser_decode(function):
def decorated(*arguments):
result = list()
for (index, argument) in enumerate(arguments):
if predicate(index):
result.append(shift_string(argument, number))
else:
result.append(argument)
return function(*result)
return decorated
return ceaser_decode
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Димитър Мутафчиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Мутафчиев
from string import ascii_uppercase as ALPHABET
def ceaser_output(n):
def inner_ceaser_output(f):
result = f()
encrypted = apply_cipher(result, n)
return lambda: encrypted
return inner_ceaser_output
def apply_cipher(string, n):
string = string.upper()
encrypted = ""
for s in string:
if s.isalpha():
encrypted += ALPHABET[(ALPHABET.find(s) + n) % len(ALPHABET)]
else:
encrypted += s
return encrypted
def ceaser_input(n, pattern):
def inner_ceaser_input(f):
def decode(name, *args):
all_args = [name] + [a for a in args]
encrypted_all_args = list()
for i in range(0, len(all_args)):
if pattern(i):
encrypted_all_args.append(apply_cipher(all_args[i], n))
else:
encrypted_all_args.append(all_args[i])
encrypted_name = encrypted_all_args[0]
encrypted_all_args.pop(0)
encrypted_args = tuple(encrypted_all_args)
return f(encrypted_name, *encrypted_args)
return decode
return inner_ceaser_input
@ceaser_input(-13, lambda key: key > 0)
def make_a_speech(name, *args):
print('{} says:\n{}'.format(name, ' '.join(args)))
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Стефани Цакова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Стефани Цакова
ALPHABET = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
def decode(shift, message):
result = [ALPHABET[(ALPHABET.index(letter.upper()) + shift) % 26]
if letter.isalpha()
else letter
for letter in message]
return "".join(result)
def ceaser_output(shift):
def inner(func):
def decorator():
return decode(shift, func())
return decorator
return inner
def ceaser_input(shift, condition):
def inner(func):
def decorator(*args):
result = [decode(shift, args[index])
if condition(index) else args[index]
for index in range(0, len(args))]
return func(*result)
return decorator
return inner
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Стефан Маринов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Маринов
def encipher(plain_text, shift):
cipher = ""
for character in plain_text.upper():
if character.isalpha():
cipher += chr(ord('A') + (ord(character) - ord('A') + shift) % 26)
else:
cipher += character
return cipher
def caesar_output(shift=0):
def applied_to(f):
def decorated(*args, **kwargs):
return encipher(f(*args, **kwargs), shift)
return decorated
return applied_to
def caesar_input(shift, func):
def applied_to(f):
def decorated(*args, **kwargs):
new_args = []
for key, value in enumerate(args):
if func(key):
new_args.append(encipher(value, shift))
else:
new_args.append(value)
return f(*tuple(new_args), **kwargs)
return decorated
return applied_to
ceaser_input = caesar_input
ceaser_output = caesar_output
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Антонио Николов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Антонио Николов
import string
def ceaser_output(offset):
def input_function(function):
def decorated():
def output(char):
if (char.upper() not in string.ascii_uppercase):
return char
return chr((ord(char.upper())-65+offset) % 26 + 65)
return ''.join(map(output, function()))
return decorated
return input_function
def ceaser_input(offset, condition):
def input_function(function):
def decorated(*args):
def output(char):
if (char.upper() not in string.ascii_uppercase):
return char
return chr((ord(char.upper())-65+offset) % 26 + 65)
cipher = []
for index, arg in enumerate(args):
if condition(index):
cipher.append(''.join(map(output, arg)))
else:
cipher.append(arg)
return function(*cipher)
return decorated
return input_function
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Георги Димитров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Димитров
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def ceaser_output(offset):
offset %= 26
def func_dec(func):
def f(*args):
mapped = alphabet[offset:] + alphabet[:offset]
trans = str.maketrans(alphabet, mapped)
return func(*args).upper().translate(trans)
return f
return func_dec
def ceaser_input(offset, function):
offset %= 26
def func_dec(func):
def f(*args):
mapped = alphabet[offset:] + alphabet[:offset]
trans = str.maketrans(alphabet, mapped)
filtered_args = []
for i, arg in enumerate(args):
if not function(i):
filtered_args.append(arg)
else:
filtered_args.append(arg.upper().translate(trans))
return func(*filtered_args)
return f
return func_dec
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Никола Димитров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Димитров
A_ASCII = ord('A')
ALPHABET_SIZE = 26
def encrypt_symbol(symbol, key):
if symbol.isalpha():
shifted_letter_code = ord(symbol.upper()) - A_ASCII + key
return chr((shifted_letter_code % ALPHABET_SIZE) + A_ASCII)
return symbol
def encrypt_string(string, key):
return "".join([encrypt_symbol(symbol, key) for symbol in string])
def ceaser_output(key):
def decorator(func):
def decorated(*args):
return encrypt_string(func(*args), key)
return decorated
return decorator
def ceaser_input(key, predicate):
def decorator(func):
def decorated(*args):
encrypted_args = [encrypt_string(arg, key) if predicate(index) else arg
for (index, arg) in enumerate(args)]
return func(*encrypted_args)
return decorated
return decorator
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Денис Бялев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Денис Бялев
def letter_displacement(letter, number):
if letter>="A" and letter<="Z":
return chr((ord(letter) + number - ord('A'))%26 + ord('A'))
else:
return letter
def string_displacement(word, number):
return "".join(letter_displacement(x, number) for x in word)
def ceaser_output(displacement):
def cypher_output(f):
def decypher_output(*args):
return "".join(letter_displacement(x, displacement)
for x in f(*args).upper())
return decypher_output
return cypher_output
def ceaser_input(displacement, condition):
def cypher_input(f):
def decypher_input(*args):
my_args=[]
for index in range(len(args)):
if condition(index):
my_args.append(string_displacement(args[index].upper(),
displacement))
else:
my_args.append(args[index])
return f(*my_args)
return decypher_input
return cypher_input
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Гергана Петрова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Гергана Петрова
def ceaser_shift(shift, words):
shift %= 26
alphabet = 'abcdefghijklmnopqrstuvwxyz'
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
words = words.lower()
shifted_words = words.maketrans(alphabet, shifted_alphabet)
return words.translate(shifted_words).upper()
def ceaser_output(shift):
def decoration(function):
def ceaser():
words = function()
return ceaser_shift(shift, words)
return ceaser
return decoration
def ceaser_input(shift, filter_function):
def decoration(function):
def ceaser(*args, **kwargs):
function_args = []
function_kwargs = {}
for index, arg in enumerate(args):
if filter_function(index):
function_args.append(ceaser_shift(shift, arg))
else:
function_args.append(arg)
for key, value in kwargs.items():
if filter_function(key):
function_kwargs[key] = ceaser_shift(shift, value)
else:
function_kwargs[key] = value
return function(*function_args, **function_kwargs)
return ceaser
return decoration
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Стоян Ефтимов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Ефтимов
def ciphered_string(shift, string):
ciphered = []
for char in string:
if char.isalpha():
ciphered.append(chr((ord(char) - 65 + shift) % 26 + 65))
else:
ciphered.append(char)
return ''.join(ciphered)
def ceaser_output(shift):
def wrapper(function):
def cipher():
return ciphered_string(shift, function().upper())
return cipher
return wrapper
def ceaser_input(shift, cipher_function):
def wrapper(wrapped_function):
def decipher(*args):
newargs = list(args)
for index, word in enumerate(args):
if cipher_function(index):
newargs[index] = ciphered_string(shift, word.upper())
return wrapped_function(*newargs)
return decipher
return wrapper
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Емилиан Станков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Емилиан Станков
def caesar_output(displacement):
def displace(function):
displaced_message = ''
key = displacement % 26
for char in function():
if ord(char) > 64 and ord(char) < 91:
decrypted = ord(char) + key
if decrypted < 65:
decrypted += 26
elif decrypted > 90:
decrypted -= 26
elif ord(char) > 96 and ord(char) < 123:
decrypted = ord(char) + key
if decrypted < 97:
decrypted += 26
elif decrypted > 122:
decrypted -= 26
else:
decrypted = ord(char)
displaced_message += chr(decrypted).upper()
def displaced():
return displaced_message
return displaced
return displace
ceaser_output = caesar_output
def caesar_input(displacement, function):
def displace(function_to_decipher):
def filtered(*arguments):
new_arguments = []
for argument in arguments:
if function(arguments.index(argument)):
new_argument = ''
key = displacement % 26
for char in argument:
if ord(char) > 96 and ord(char) < 123:
decrypted = ord(char) + key
if decrypted < 97:
decrypted += 26
elif decrypted > 122:
decrypted -= 26
elif ord(char) > 64 and ord(char) < 91:
decrypted = ord(char) + key
if decrypted < 65:
decrypted += 26
elif decrypted > 90:
decrypted -= 26
else:
decrypted = ord(char)
new_argument += chr(decrypted).upper()
new_arguments.append(new_argument)
else:
new_arguments.append(argument)
return function_to_decipher(*new_arguments)
return filtered
return displace
ceaser_input = caesar_input
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Цветелина Борисова
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Цветелина Борисова
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def crypted_message(plaintext, shift):
shifted_alphabet = ALPHABET[shift:] + ALPHABET[:shift]
table = str.maketrans(ALPHABET, shifted_alphabet)
return plaintext.translate(table)
def ceaser_output(*args):
def ceaserable(f):
def decorated():
return crypted_message(f().upper(), args[0])
return decorated
return ceaserable
def ceaser_input(*args):
def ceaserable(f):
def decorated(*words):
message = ''
for index, word in enumerate(words):
if args[1](index):
message += word + ' '
return f(words[0], crypted_message(message, args[0]))
return decorated
return ceaserable
F...
======================================================================
FAIL: test_ceaser_input (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1yzxlhc/test.py", line 32, in test_ceaser_input
    self.assertEqual(real_input, expected_input)
AssertionError: 'Reg says:\nWHAT HAVE THE ROMANS EVER DONE FOR US? ... ' != 'Reg says:\nWHAT HAVE THE ROMANS EVER DONE FOR US? ...'
  Reg says:
- WHAT HAVE THE ROMANS EVER DONE FOR US? ... ?                                           -
+ WHAT HAVE THE ROMANS EVER DONE FOR US? ...

----------------------------------------------------------------------
Ran 4 tests in 0.004s

FAILED (failures=1)
Иван Георгиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Георгиев
from string import ascii_lowercase as alphabet
def ceaser(string, offset):
for number in range(len(string)):
letter = string[number]
if letter.isalpha():
index = (alphabet.find(letter) + offset)
string[number] = alphabet[index % len(alphabet)]
return ''.join(string).upper()
def ceaser_output(offset):
def accepter(func):
def decorated(*args):
string = list(func(*args).lower())
return ceaser(string, offset)
return decorated
return accepter
def ceaser_input(offset, key_func):
def accepter(given_func):
def decorated(*args):
pairs = dict(enumerate(args))
for key in pairs:
if(key_func(key)):
pairs[key] = ceaser(list(pairs[key].lower()), offset)
return given_func(*pairs.values())
return decorated
return accepter
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Данаил Койчев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Данаил Койчев
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def convert_to_ceaser_script(phrase, displacement):
ceaser_script = []
for letter in phrase.upper():
if letter in ALPHABET:
letter = ALPHABET[(ALPHABET.index(letter) + displacement) % 26]
ceaser_script.append(letter)
return "".join(ceaser_script)
def ceaser_output(displacement):
def decorator(f):
def wrapper(*args, **kwargs):
original_script = f(*args, **kwargs).upper()
return convert_to_ceaser_script(original_script, displacement)
return wrapper
return decorator
def ceaser_input(displacement, should_convert):
def decorator(f):
def wrapper(*args):
new_args = []
for index, arg in enumerate(args):
if should_convert(index):
arg = convert_to_ceaser_script(arg, displacement)
new_args.append(arg)
return f(*new_args)
return wrapper
return decorator
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Йордан Дикманов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Йордан Дикманов
def ceaser_output(code):
def ceaser_outputs(f):
def decorators(*args):
new_string = ''
for i in f(*args):
if i.isalpha():
i_displacemant = ord(i.upper()) + code - ord('A')
letter = chr(i_displacemant % 26 + ord('A'))
else:
letter = i
new_string += letter
return new_string
return decorators
return ceaser_outputs
def ceaser_input(code, *functions):
def ceaser_inputs(f):
def decorators(*args):
@ceaser_output(code)
def return_string(name):
return name
def is_true_key(word_ind):
for fun in functions:
if fun(word_ind) == False:
return False
return True
new_tupple = []
for (j, i) in enumerate(args):
if not is_true_key(j):
new_tupple.append(i)
else:
new_tupple.append(return_string(i))
return f(*new_tupple)
return decorators
return ceaser_inputs
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Весела Бандова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Весела Бандова
import string
LETTERS = list(string.ascii_uppercase)
POSITION = {ch: i for i, ch in enumerate(string.ascii_uppercase)}
def ceaser_output(pos):
def ceaser_out(func):
def inner(*args, **kwargs):
output = func(*args, **kwargs)
return ceaser_shift(output, pos)
return inner
return ceaser_out
def ceaser_input(pos, clause=None):
def ceaser_in(func):
def inner(*args, **kwargs):
cl = clause
if cl is None:
cl = lambda x: True
arg = list(args)
for i in range(len(arg)):
if cl(i):
arg[i] = ceaser_shift(args[i], pos)
return func(*arg, **kwargs)
return inner
return ceaser_in
def ceaser_shift(word, pos):
length = len(LETTERS)
arr = [LETTERS[(POSITION[i] + pos) % length] if i in LETTERS else i
for i in word.upper()]
return "".join(arr)
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Александър Златков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Златков
FIRST_SYMBOL_CODE = ord('A')
def shift_symbol(symbol, offset):
symbol_number = ord(symbol.upper())-FIRST_SYMBOL_CODE
return chr(
FIRST_SYMBOL_CODE + (((symbol_number + offset % 26) + 26) % 26))
def get_propert_symbol(symbol, offset):
if symbol.isalpha():
return shift_symbol(symbol, offset).upper()
else:
return symbol
def convert_symbols(symbols, offset):
return "".join(
get_propert_symbol(symbol, offset) for symbol in symbols)
def ceaser_output(offset):
def ceaser_output_inner(func):
def modify_output(*args):
func_result = func(*args)
return convert_symbols(func_result, offset)
return modify_output
return ceaser_output_inner
def ceaser_input(offset, valid_argument_index):
def ceaser_input_inner(func):
def modify_input(*args):
converted_arguments = []
for i in range(0, len(args)):
if valid_argument_index(i):
converted_arguments.append(
convert_symbols(args[i], offset))
else:
converted_arguments.append(args[i])
return func(*converted_arguments)
return modify_input
return ceaser_input_inner
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Ралица Цанова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Ралица Цанова
def change(c, shift):
return chr((ord(c) + shift - 65) % 26 + 65) if c.isalpha() else c
def convert(string, shift):
return ''.join([change(i, shift) for i in string.upper()])
def ceaser_output(shift):
def accepter(ceaser_func):
def coder(*args):
return convert(ceaser_func(*args), shift)
return coder
return accepter
def ceaser_input(shift, condition):
def accepter(ceaser_func):
def coder(*args):
result = []
for index in range(0, len(args)):
if(condition(index)):
result.append(convert(args[index], shift))
else:
result.append(args[index])
return ceaser_func(*result)
return coder
return accepter
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Стефан Владков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Владков
def ceaser_output(displacement):
def encoded(func):
encoded_message = ''
message = func()
message = message.upper()
for symbol in message:
if (ord('A') <= ord(symbol) and ord('Z') >= ord(symbol)):
position = ord(symbol) - ord('A')
char = chr(ord('A') + (position + displacement) % 26)
encoded_message += char
else:
encoded_message += symbol
def result():
return encoded_message
return result
return encoded
@ceaser_output(13)
def cross_the_river():
return "ALEA IACTA EST"
#print(cross_the_river())
def decodeMessage(message, displacement):
decoded_message = ''
for symbol in message:
if (ord('A') <= ord(symbol) and ord('Z') >= ord(symbol)):
position = ord(symbol) - ord('A')
decoded_message += chr(ord('A') + (position + displacement) % 26)
else:
decoded_message += symbol
return decoded_message
def ceaser_input(displacement, pred):
def decode(func):
def decoded(*args):
result = ()
for message in args:
decoded_message = message
if pred(args.index(message)):
message = message.upper()
decoded_message = decodeMessage(message, displacement)
result += (decoded_message,)
return func(*result)
return decoded
return decode
@ceaser_input(-13, lambda key: key > 0)
def make_a_speech(name, *args):
print('{} says:\n{}'.format(name, ' '.join(args)))
make_a_speech('Reg', 'JUNG', 'UNIR', 'GUR', 'EBZNAF',
'RIRE', 'QBAR', 'SBE', 'HF?', '...')
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Иван Бобев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Бобев
def cypher(s, shift):
return ''.join(chr(ord('A') + (ord(c) - ord('A') + shift) % 26)
if c.isalpha() else c for c in s.upper())
def ceaser_output(shift):
def decorator(func):
def decorated(*args):
output = func(*args)
if isinstance(output, str):
output = cypher(output, shift)
return output
return decorated
return decorator
def ceaser_input(shift, key_func=None):
def decorator(func):
def decorated(*args):
new_args = []
for i, arg in enumerate(args):
if isinstance(arg, str) and (not key_func or key_func(i)):
new_args.append(cypher(arg, shift))
else:
new_args.append(arg)
return func(*new_args)
return decorated
return decorator
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Атанас Филчев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Филчев
START_ALPHABET_INDEX = 96
LAST_LETTER_INDEX = 122
ALPHABET_LENGTH = 26
def ceaser_output(number):
def inner(func):
def ceaser_outputted(*args):
cipher = ''
text_to_shift = list(func(*args).lower())
for character in text_to_shift:
if character == ' ' or not character.isalpha():
cipher += character
else:
int_of_char = (ord(character) + number)
if int_of_char > LAST_LETTER_INDEX:
int_of_char = ((int_of_char - LAST_LETTER_INDEX) +
START_ALPHABET_INDEX)
elif int_of_char <= START_ALPHABET_INDEX:
int_of_char += ALPHABET_LENGTH
cipher += chr(int_of_char)
return cipher.upper()
return ceaser_outputted
return inner
def ceaser_input(number, f):
def inner(func):
def ceaser_outputted_if_needed(*args):
output_of_ceaser = []
name = args[0]
for index, entry in enumerate(args):
if (f(index)):
@ceaser_output(number)
def get_output(number):
return entry
ceasered_word = get_output(number)
output_of_ceaser.append(ceasered_word)
return func(name, *output_of_ceaser)
return ceaser_outputted_if_needed
return inner
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Йончо Йончев
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Йончо Йончев
import string
from functools import wraps
def create(shift, funk):
#print(funk())
message = funk().upper()
letters = string.ascii_uppercase
data = []
for i in message:
if i.strip() and i in letters:
data.append(letters[(letters.index(i) + shift) % 26])
else:
data.append(i)
return ''.join(data)
def ceaser_output(number):
def decorator_helper(funk):
def wrapped(*args, **kwargs):
return create(number, funk)
return wrapped
return decorator_helper
def ceaser_input(number, criterion):
def decorator_helper(funk):
def wrapped(*args, **kwargs):
values = [x for x in args]
def value_holder():
new_list=[values[x] for x in list(filter(criterion,range(len(values))))]
return ' '.join(new_list)
return create(number, value_holder)
return wrapped
return decorator_helper
F...
======================================================================
FAIL: test_ceaser_input (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-19l5x49/test.py", line 32, in test_ceaser_input
    self.assertEqual(real_input, expected_input)
AssertionError: 'WHAT HAVE THE ROMANS EVER DONE FOR US? ...' != 'Reg says:\nWHAT HAVE THE ROMANS EVER DONE FOR US? ...'
- WHAT HAVE THE ROMANS EVER DONE FOR US? ...
+ Reg says:
WHAT HAVE THE ROMANS EVER DONE FOR US? ...
? ++++++++++


----------------------------------------------------------------------
Ran 4 tests in 0.004s

FAILED (failures=1)
Атанас Димитров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Димитров
ALPHABET = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
def ceaser_output(displacement):
cipher = {letter: ALPHABET[(ALPHABET.index(letter) + displacement) % 26]
for letter in ALPHABET}
def middle(function):
def encode():
to_encode = function().upper()
encoded = ''
for symbol in to_encode:
if symbol.isalpha():
encoded += cipher[symbol]
else:
encoded += symbol
return encoded
return encode
return middle
def ceaser_input(displacement, restriction):
cipher = {letter: ALPHABET[(ALPHABET.index(letter) + displacement) % 26]
for letter in ALPHABET}
def middle(function):
def decode(*args):
decoded = []
for argument in args:
current_result = ''
if restriction(args.index(argument)):
for symbol in argument:
if symbol.isalpha():
current_result += cipher[symbol.upper()]
else:
current_result += symbol
else:
current_result = argument
decoded.append(current_result)
return function(*decoded)
return decode
return middle
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Георги Йорданов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Йорданов
def get_ciphered_symbol(symbol, number):
if symbol.isalpha():
return chr((((ord(symbol) - 65) + number) % 26) + 65)
else:
return symbol
def get_ciphered_text(text, number):
cipher_text = ''
for symbol in text:
cipher_text += get_ciphered_symbol(symbol, number)
return cipher_text
def ceaser_output(number):
def wrap(function):
def wrapped_function(*args):
plain_text = function(*args).upper()
ciphered_text = get_ciphered_text(plain_text, number)
return ciphered_text
return wrapped_function
return wrap
def ceaser_input(number, predicate):
def wrap(function):
def wrapped_function(*args):
ciphered_args = []
for i, text in enumerate(args):
if predicate(i):
ciphered_args.append(get_ciphered_text(text.upper(),
number))
else:
ciphered_args.append(text)
return function(*ciphered_args)
return wrapped_function
return wrap
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Мартин Георгиев
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Мартин Георгиев
# CAESAR
alphabet = list("abcdefghijklmnopqrstuvwxyz")
def rotate(string, offset):
string = string.lower()
new_string = ""
for letter in string:
if letter.isalpha():
letter = alphabet[(alphabet.index(letter) + offset + 26) % 26]
new_string += letter
return new_string.upper()
def caesar_output(offset):
def inner_decorator(func):
def inner(*args, **kwargs):
string = func(*args, **kwargs)
return rotate(string, offset)
return inner
return inner_decorator
def caesar_input(offset, filter_predicate):
def inner_decorator(func):
def inner(*args, **kwargs):
new_args = []
for argument in args:
if filter_predicate(args.index(argument)):
argument = rotate(argument, offset)
new_args.append(argument)
func(*new_args, **kwargs)
return inner
return inner_decorator
ceaser_output = caesar_output
ceaser_input = caesar_input
F...
======================================================================
FAIL: test_ceaser_input (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1c3n23o/test.py", line 32, in test_ceaser_input
    self.assertEqual(real_input, expected_input)
AssertionError: None != 'Reg says:\nWHAT HAVE THE ROMANS EVER DONE FOR US? ...'

----------------------------------------------------------------------
Ran 4 tests in 0.003s

FAILED (failures=1)
Никола Ненков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Ненков
alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
def code_character(character, displacement):
if character.upper() in alphabet:
return alphabet[(alphabet.index(character.upper()) + displacement)
% len(alphabet)]
return character
def code_word(word, displacement):
return ''.join(code_character(character, displacement)
for character in word)
def ceaser_input(displacement, key_filter):
def accepter(function):
def decorator(*args):
coded_args = [code_word(word, displacement) if key_filter(index)
else word for index, word in enumerate(args)]
return function(*coded_args)
return decorator
return accepter
def ceaser_output(displacement):
def accepter(function):
def decorator(*args):
return ''.join(code_word(word, displacement)
for word in function(*args))
return decorator
return accepter
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Петър Парушев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Парушев
def ceaser_output(key):
def accepter(f):
def decorated(*args):
return ceaser_encoding(key, f(*args))
return decorated
return accepter
def ceaser_encoding(key, message):
result = ""
message = message.upper()
a_code = ord('A')
for letter in message:
if letter.isalpha():
result += chr(((ord(letter) - a_code + key) % 26) + a_code)
else:
result += letter
return result
def ceaser_input(key, function):
def accepter(f):
def decorated(*args):
result = []
for index, arg in enumerate(args):
if function(index):
result.append(ceaser_encoding(key, arg))
else:
result.append(arg)
return f(*result)
return decorated
return accepter
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Васил Тодоров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Васил Тодоров
def change_letter(letter, shift):
shift = shift % 26 if shift > 0 else -((-shift) % 26)
letter = letter.upper()
if(not letter.isupper()):
return letter
if ord(letter) + shift < ord('A'):
return chr(ord('Z') + (ord(letter) - ord('A') + shift) + 1)
if ord(letter) + shift <= ord('Z'):
return chr(ord(letter) + shift)
return chr(ord('A') + ord(letter) + shift - ord('Z') - 1)
def string_to_ceaser(str, shift):
result = []
for letter in str:
result.append(change_letter(letter, shift))
return ''.join(result)
def ceaser_output(shift):
def real_decorator(function):
def wrapper(*args, **kwargs):
before_ceaser = function(*args, **kwargs)
return string_to_ceaser(before_ceaser, shift)
return wrapper
return real_decorator
def ceaser_input(shift, checker):
def real_decorator(function):
def wrapper(*args, **kwargs):
new_args = []
for arg in args:
if checker(args.index(arg)):
new_args.append(string_to_ceaser(arg, shift))
else:
new_args.append(arg)
before_ceaser = function(*new_args)
return before_ceaser
return wrapper
return real_decorator
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Милица Борисова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Милица Борисова
from string import ascii_lowercase, ascii_uppercase
ALPHABETH = ascii_lowercase + ascii_uppercase
def ceaser_output(shift):
if shift < -26:
new_shift = shift%26 * -1
elif shift > 26:
new_shift = shift % 26
else:
new_shift = shift
def ceaser_coding(text):
coded_text = ""
if shift < 0:
text_to_code = text().upper()
else:
text_to_code = text().lower()
for letter in text_to_code:
if letter.isalpha():
coded_text += ALPHABETH[ALPHABETH.index(letter) + new_shift]
else:
coded_text += letter
return lambda: coded_text.upper()
return ceaser_coding
def ceaser_input(shift, condition_function):
def ceaser_acceptor_function(function):
def ceaser_decoding(*args):
new_arguments = []
for argument in args:
if condition_function(args.index(argument)):
new_arguments.append((ceaser_output(shift)(lambda: argument))())
else:
new_arguments.append(argument)
return function(*new_arguments)
return ceaser_decoding
return ceaser_acceptor_function
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Елена Димитрова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Елена Димитрова
ALPHABET_SIZE = 26
def encypher_message(message, offset):
cyphered = ""
offset = offset % ALPHABET_SIZE
message = message.upper()
for letter in message:
if letter.isalpha():
letter = ord(letter) + offset
if letter > ord('Z'):
letter -= ALPHABET_SIZE
if letter < ord('A'):
letter += ALPHABET_SIZE
letter = chr(letter)
cyphered += letter
return cyphered
def ceaser_output(offset):
def encryptor(encrypted):
def cypher(*args):
message = encrypted().upper()
return encypher_message(message, offset)
return cypher
return encryptor
def ceaser_input(offset, key):
def decryptor(decrypted):
def cypher(*args):
cyphered = []
for word in args:
current_word = args.index(word)
if key(current_word):
cyphered.append(encypher_message(word, offset))
else:
cyphered.append(word)
return decrypted(cyphered[0], *cyphered[1:])
return cypher
return decryptor
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Теодор Драганов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Драганов
from string import ascii_uppercase as uppercase
def cipher(letter, step):
if letter.isalpha():
return uppercase[(uppercase.index(letter.upper())+step) %
len(uppercase)]
return letter
def ceaser_output(cipher_step):
def output_cipher(f):
def cipher_args(*args, **kwargs):
cipher_arguments = f(*args, **kwargs)
return ''.join(map(lambda x:
cipher(x, cipher_step), cipher_arguments))
return cipher_args
return output_cipher
def ceaser_input(cipher_step, function_filter):
def input_cipher(f):
def cipher_arguments(*args, **kwargs):
new_args = []
for index in range(len(args)):
if function_filter(index):
new_args.append(''.join(map(lambda x:
cipher(x, cipher_step),
args[index])))
else:
new_args.append(args[index])
return f(*tuple(new_args), **kwargs)
return cipher_arguments
return input_cipher
#Just in case :)
caesar_input = ceaser_input
caesar_output = ceaser_output
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Мария Донева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Донева
ALPHABET = [chr(65 + i).upper() for i in range(26)]
def ceaser_output(offset):
def accepts(f):
def decorated():
sequence_to_cipher = f()
cipher_sequence = ''
for symbol in sequence_to_cipher:
symbol = symbol.upper()
if symbol in ALPHABET:
index = ALPHABET.index(symbol)
new_index = (index + offset) % 26
symbol = ALPHABET[new_index]
cipher_sequence += symbol
return cipher_sequence
return decorated
return accepts
def ceaser_input(offset, lambda_f):
def accepts(f):
def decorated(*args):
cipher = []
length = len(args)
for key in range(length):
argument = args[key]
if lambda_f(key):
container = ''
for symbol in argument:
symbol = symbol.upper()
if symbol in ALPHABET:
index = ALPHABET.index(symbol)
new_index = (index + offset) % 26
symbol = ALPHABET[new_index]
container += symbol
cipher.append(container)
else:
cipher.append(argument)
return f(*cipher)
return decorated
return accepts
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Мария Кърчева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Кърчева
import string
def shift(char, num):
alphabet = string.ascii_uppercase
if char.upper() in alphabet:
index = alphabet.index(char.upper())
char = alphabet[(index + num) % 26]
return char
def ceaser_output(num):
def decorator(f):
def wrapped():
return ''.join([shift(char, num) for char in f()])
return wrapped
return decorator
def ceaser_input(num, condition):
def decorator(f):
def wrapped(*args):
args = [arg for arg in args]
for i, arg in enumerate(args):
if condition(i):
args[i] = ''.join(shift(char, num) for char in arg)
return f(*args)
return wrapped
return decorator
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Валентин Петров
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Валентин Петров
def ceaser_output(x):
def decorator(f):
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def decorated(*args,**kwargs):
result = list(f())
for i in range(0,len(result)):
if result[i].isalpha():
index = alphabet.index(result[i].upper())
result[i] = alphabet[(index+x)%len(alphabet)]
return ''.join(result)
return decorated
return decorator
E...
======================================================================
ERROR: test_ceaser_input (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1r8binr/test.py", line 22, in test_ceaser_input
    decorator = solution.ceaser_input(-13, lambda key: key > 0)
AttributeError: 'module' object has no attribute 'ceaser_input'

----------------------------------------------------------------------
Ran 4 tests in 0.003s

FAILED (errors=1)
Иван Латунов
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Иван Латунов
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def ceaser_output(shift):
def call(func):
def decrypt():
result = []
for letter in list(func()):
if letter in ALPHABET:
letter_index = (ord(letter) - ord('A') + shift) % 26
result.append(chr(letter_index + ord('A')))
else:
result.append(letter)
return ''.join(result)
return decrypt
return call
E...
======================================================================
ERROR: test_ceaser_input (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-buvlz8/test.py", line 22, in test_ceaser_input
    decorator = solution.ceaser_input(-13, lambda key: key > 0)
AttributeError: 'module' object has no attribute 'ceaser_input'

----------------------------------------------------------------------
Ran 4 tests in 0.003s

FAILED (errors=1)
Георги Харизанов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Харизанов
from functools import reduce
alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
def shift_letter(letter, cypher):
if letter.upper() not in alphabet:
return letter
letter_index = alphabet.index(letter.upper()) + cypher
letter = alphabet[letter_index % len(alphabet)]
return letter
def encrypt(sentance, cypher):
sentance_list = list(sentance)
for i, char in enumerate(sentance_list):
sentance_list[i] = shift_letter(char, cypher)
return (reduce(lambda a,b : a+b, sentance_list))
def ceaser_output(cypher):
def wrapper(func):
def encrypt_ceaser():
return encrypt(func(), cypher)
return encrypt_ceaser
return wrapper
def ceaser_input(cypher, condition):
def wrapper(func):
def decrypt_ceaser(*args, **kwargs):
args = [ encrypt(a, cypher) if condition(args.index(a)) else a for a in args ]
return func(*args, **kwargs)
return decrypt_ceaser
return wrapper
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Любомир Коев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Коев
def char_rotate(char, step):
return (char if not char.isalpha()
else chr((ord(char.upper()) + step - ord('A')) % 26 + ord('A')))
def string_rotate(string, step):
return ''.join([char_rotate(char, step) for char in string])
def ceaser_output(step):
def functor(func):
def decipher(*args):
return string_rotate(func(*args), step)
return decipher
return functor
def ceaser_input(step, predicate):
def functor(func):
def cipher(*args):
return func(*list(map(
lambda pair: string_rotate(pair[1], step)
if predicate(pair[0]) else pair[1],
enumerate(args)
)))
return cipher
return functor
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Филип Митов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Филип Митов
import string
def ceaser_output(number):
def accepter(func):
def decorated(*args):
plain_letters = [symbol for symbol in string.ascii_uppercase]
cipher_letters = [plain_letters[(index+number)%26]
for index in range(26)]
combined_letters = dict(zip(plain_letters, cipher_letters))
func_returned = func(*args)
cipher_text = ""
for one_symbol in func_returned:
if one_symbol.isalpha():
cipher_text += combined_letters[one_symbol.upper()]
else:
cipher_text += one_symbol
return cipher_text
return decorated
return accepter
def ceaser_input(number, function):
def accepter(func):
def decorated(*args):
corrected_arguments = []
letters = [symbol for symbol in string.ascii_uppercase]
cipher_letter = [letters[(index+number) % 26]
for index in range(26)]
combined_letters = dict(zip(letters, cipher_letter))
for one_arg in args:
if function(args.index(one_arg)):
cipher_text = ""
for one_symbol in one_arg:
if one_symbol.isalpha():
cipher_text += combined_letters[one_symbol.upper()]
else:
cipher_text += one_symbol
corrected_arguments.append(cipher_text)
else:
corrected_arguments.append(one_arg)
return func(*tuple(corrected_arguments))
return decorated
return accepter
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Евгени Евлогиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Евгени Евлогиев
def right_rotation(symbol, displacement):
return chr((ord(symbol.upper()) + displacement - 91) % 26 + 65)
def left_rotation(symbol, displacement):
return chr((ord(symbol.upper()) + displacement - 39) % 26 + 65)
def ceaser_output(displacement):
def inner1(func):
def inner2(*args):
result = []
msg = func(*args)
for symbol in msg:
if symbol.upper() >= 'A' and symbol.upper() <= 'Z':
if (ord(symbol.upper()) + displacement > 90):
result.append(right_rotation(symbol, displacement))
elif (ord(symbol.upper()) + displacement < 65):
result.append(left_rotation(symbol, displacement))
else:
result.append(chr(ord(symbol.upper()) + displacement))
else:
result.append(symbol.upper())
return ''.join(symbol for symbol in result)
return inner2
return inner1
def ceaser_input(displacement, *functions):
def inner1(func):
def inner2(*args):
result = []
msg = list(args)
for i in range(len(msg)):
func2 = all([func(i) for func in functions])
if func2:
@ceaser_output(displacement)
def get_str():
return msg[i]
result.append(get_str())
else:
result.append(msg[i])
return func(*result)
return inner2
return inner1
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Петър Камбуров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Камбуров
def ceaser_output(shift):
def string_function(func):
def decorate():
def caesar(coded_text, shift):
encoded_text = ""
shift %= 26
for symbol in coded_text.upper():
if symbol <= 'Z' and symbol >= 'A':
shifted_symbol = ord(symbol) + shift
if shifted_symbol > ord('Z'):
shifted_symbol -= 26
if shifted_symbol < ord('A'):
shifted_symbol += 26
else:
shifted_symbol = ord(symbol)
encoded_text += chr(shifted_symbol)
return encoded_text
return caesar(func(), shift)
return decorate
return string_function
def ceaser_input(shift, func):
def decorate_func(ceaser_func):
def decorate(*args):
def caesar(shift):
encoded_text = ""
encoded_words = []
shift %= 26
for index in range(0, len(args)):
if func(index):
encoded_text = ""
for symbol in args[index].upper():
if symbol <= 'Z' and symbol >= 'A':
shifted_symbol = ord(symbol) + shift
if shifted_symbol > ord('Z'):
shifted_symbol -= 26
if shifted_symbol < ord('A'):
shifted_symbol += 26
else:
shifted_symbol = ord(symbol)
encoded_text += chr(shifted_symbol)
encoded_words.append(encoded_text)
else:
encoded_words.append(args[index])
return ceaser_func(*encoded_words)
return caesar(shift)
return decorate
return decorate_func
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Емануел Стоянов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Емануел Стоянов
def ceaser_output(number):
def inner(func):
def decorated():
number_without_cycles = number
if number_without_cycles >= 0:
how_many_cicles = number_without_cycles // 26
number_without_cycles -= how_many_cicles*26
else:
how_many_cicles = number_without_cycles // -26
number_without_cycles += how_many_cicles*26
upper_string = func().upper()
letters = []
for letter in upper_string:
if letter.isupper():
letters.append(shift(letter, number_without_cycles))
else:
letters.append(letter)
return ''.join(letters)
return decorated
return inner
def shift(word, number):
letters = []
upper_word = word.upper()
if number >= 0:
boundary = 90 - number
for letter in upper_word:
if letter.isupper() and ord(letter) <= boundary:
letters.append(chr(ord(letter) + number))
elif letter.isupper() and ord(letter) > boundary:
letters.append(chr(ord(letter) + number - 26))
else:
letters.append(letter)
else:
boundary = 65 - number
for letter in upper_word:
if letter.isupper() and ord(letter) >= boundary:
letters.append(chr(ord(letter) + number))
elif letter.isupper() and ord(letter) < boundary:
letters.append(chr(ord(letter) + number + 26))
else:
letters.append(letter)
return ''.join(letters)
def ceaser_input(number, should_shift):
def inner(func):
def decorated(*args):
words = []
for i in range(len(args)):
if should_shift(i):
words.append(shift(args[i], number))
else:
words.append(args[i])
return func(*words)
return decorated
return inner
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Николай Масларски
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Масларски
ALPHABETH_LENGTH = 26
def shift_letter(letter, key):
return chr((ord(letter.upper()) - ord('A') + key)
% ALPHABETH_LENGTH + ord('A'))
def ceaser_output(key):
def sipher(function):
coded_string = ''
not_coded_string = function()
for charecter in not_coded_string:
if(charecter.isalpha()):
coded_string += shift_letter(charecter, key)
else:
coded_string += charecter
return lambda: coded_string
return sipher
def ceaser_input(key, key_func):
def accepter(function):
def sipher(*args):
result = []
for i in range(len(args)):
temp = ''
if(key_func(i)):
for charecter in args[i]:
if(charecter.isalpha()):
temp += shift_letter(charecter, key)
else:
temp += charecter
result.append(temp)
else:
result.append(args[i])
return function(*result)
return sipher
return accepter
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Кирил Киров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Кирил Киров
def letter_shifting(one_letter, move_step):
letter_number = ord(one_letter) + move_step
if chr(letter_number) > 'Z':
return chr(ord('A') - 1 + (letter_number - ord('Z')))
elif chr(letter_number) < 'A':
return chr(ord('Z') + 1 - (ord('A') - letter_number))
else:
return chr(letter_number)
def word_shift(shift, word):
result = []
for symbol in word.upper():
if symbol >= 'A' and symbol <= 'Z':
result.append(letter_shifting(symbol, shift))
else:
result.append(symbol)
result = ''.join(result)
return result
def ceaser_input(shift, lambda_fn):
def accepted_fun(f):
def arguments(*args):
new_args = []
for i, arg in enumerate(args):
if lambda_fn(i):
new_args.append(word_shift(shift, arg.upper()))
else:
new_args.append(arg)
return f(*new_args)
return arguments
return accepted_fun
def ceaser_output(shift):
def accepted_fun(f):
def arguments(*args):
function_result = f()
result = []
for symbol in function_result.upper():
if ord(symbol) in range(65, 91):
result.append(letter_shifting(symbol, shift))
else:
result.append(symbol)
result = ''.join(result)
result = result.upper()
return result
return arguments
return accepted_fun
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Теодор Халваджиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Халваджиев
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def encode(word, shift):
cipher = []
for letter in word.upper():
if letter.isalpha():
cipher.append(ALPHABET[(ALPHABET.find(letter)
+ shift) % 26])
else:
cipher.append(letter)
return "".join(cipher)
def ceaser_output(shift):
def real_decorator(function):
def encrypt():
original = function()
return encode(original, shift)
return encrypt
return real_decorator
def ceaser_input(shift, criterion):
def real_decorator(function):
def encrypt(*args):
cipher = []
for index, word in enumerate(args):
if criterion(index):
cipher.append(encode(word, shift))
else:
cipher.append(word)
return function(*cipher)
return encrypt
return real_decorator
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Виктор Иванов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Виктор Иванов
def ceaser_output(shift):
def wrap(function):
def ciphered(*args):
output = function(*args)
result = ""
for symbol in output.upper():
if symbol >= 'A' and symbol <= 'Z':
symbol = chr((ord(symbol)-ord('A')+shift) % 26 + ord('A'))
result += symbol
return result
return ciphered
return wrap
def ceaser_input(shift, selected):
def wrap(function):
def ciphered(*args):
encoded_args = list()
for (key, arg) in enumerate(args):
if selected(key):
encoded_arg = ""
for symbol in arg.upper():
if symbol >= 'A' and symbol <= 'Z':
symbol = chr((ord(symbol)-ord('A')+shift) % 26 +
ord('A'))
encoded_arg += symbol
encoded_args.append(encoded_arg)
else:
encoded_args.append(arg)
return function(*encoded_args)
return ciphered
return wrap
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Дарина Кръстева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Дарина Кръстева
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def replace_letters(expression_to_transform, shift_step):
expression_to_transform = expression_to_transform.upper()
transformed_expression = ''
for symbol in expression_to_transform:
if symbol.isalpha():
transformed_expression += ALPHABET[(ALPHABET.index(symbol) +
shift_step) % 26]
else:
transformed_expression += symbol
return transformed_expression
def ceaser_output(shift_step):
def decorate(function_to_decorate):
def encode(*args, **kwargs):
expression = function_to_decorate(*args, **kwargs)
return replace_letters(expression, shift_step)
return encode
return decorate
def ceaser_input(shift_step, selecting_function):
def decorate(function_to_decorate):
def decode(*args):
decoded_arguments = []
for index in range(0, len(args)):
decoded_argument = args[index]
if selecting_function(index):
decoded_argument = replace_letters(
decoded_argument,
shift_step)
decoded_arguments.append(decoded_argument)
return function_to_decorate(*tuple(decoded_arguments))
return decode
return decorate
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Антония Чекръкчиева
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Антония Чекръкчиева
def ceaser_output(number):
def make_change(func):
def change():
sentence = func().upper()
new_sentence = ""
change_number = number % 26
if change_number < 0:
change_number = 26 + change_number
for word in sentence:
if word == ' ':
new_sentence += ' '
else:
if(ord(word) + change_number > 90):
new_sentence += chr(ord(word) + change_number - 26)
else:
new_sentence += chr(change_number+ord(word))
return new_sentence
return change
return make_change
E...
======================================================================
ERROR: test_ceaser_input (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1ko4e5z/test.py", line 22, in test_ceaser_input
    decorator = solution.ceaser_input(-13, lambda key: key > 0)
AttributeError: 'module' object has no attribute 'ceaser_input'

----------------------------------------------------------------------
Ran 4 tests in 0.003s

FAILED (errors=1)
Георги Янев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Янев
ALPHABET = tuple(map(chr, range(97, 123)))
ALPHABET = tuple(map(lambda x: str.upper(x), ALPHABET))
def ceaser_output(number):
def ceaser_output_decorator(original_function):
def wrapper(*args, **kwargs):
shifted_text = []
for character in original_function(*args, **kwargs):
if str.isalpha(character):
shifted_letter = ALPHABET[(ALPHABET.index(
str.upper(character)) + number) % 26]
shifted_text.append(shifted_letter)
else:
shifted_text.append(character)
return "".join(shifted_text)
return wrapper
return ceaser_output_decorator
def ceaser_input(number, filter_function):
def ceaser_input_decorator(original_function):
def wrapper(*args, **kwargs):
shifted_text = []
for index, word in enumerate(args):
if filter_function(index):
shifted_word = ''
for character in word:
if str.isalpha(character):
shifted_letter = ALPHABET[(ALPHABET.index(
str.upper(character)) + number) % 26]
shifted_word += shifted_letter
else:
shifted_word += character
shifted_text.append(shifted_word)
else:
shifted_text.append(word)
return original_function(" ".join(shifted_text[:1]),
" ".join(shifted_text[1:]))
return wrapper
return ceaser_input_decorator
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Димитър Трендафилов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Трендафилов
from string import ascii_uppercase
LETTER_TO_NUMBER = dict(zip(ascii_uppercase, range(0, 26)))
NUMBER_TO_LETTER = dict(zip(range(0, 26), ascii_uppercase))
def shifter(char, shift):
if char.isalpha():
return NUMBER_TO_LETTER[(LETTER_TO_NUMBER[char] + shift) % 26]
else:
return char
def encription(text, shift, condition):
if condition:
return "".join(shifter(char.upper(), shift) for char in text)
else:
return text
def ceaser_output(shift):
def accepter(function):
def encript(*args):
result = function(*args)
return encription(result, shift, True)
return encript
return accepter
def ceaser_input(shift, condition):
def accepter(function):
def encript(*args):
should = map(condition, range(0, len(args)))
args = (encription(text, shift, next(should)) for text in args)
return function(*args)
return encript
return accepter
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Стоян Христов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Христов
ALPHABET_LEN = 26
def encode(text, shift):
encoded = []
for char in text:
if char.isalpha():
encoded.append(
chr((ord(char.lower()) - ord('a') + shift) %
ALPHABET_LEN + ord('a')).upper()
)
else:
encoded.append(char)
return ''.join(encoded)
def ceaser_output(shift):
def shifting(func):
def code(*args, **kwargs):
text = func()
return encode(text, shift)
return code
return shifting
def ceaser_input(shift, requirement):
def decode(func):
def encode_if_needed(*args):
result_args = ()
for index in range(0, len(args)):
if requirement(index):
result_args = result_args + (encode(args[index], shift), )
else:
result_args = result_args + (args[index], )
return func(*result_args)
return encode_if_needed
return decode
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Марио Димитров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Марио Димитров
def caesarify(move, word):
word = word.upper()
new_word = []
for sign in word:
if sign >= 'A' and sign <= 'Z':
new_word.append(chr((ord(sign) - 65 + move) % 26 + 65))
else:
new_word.append(sign)
return ''.join(new_word)
def caesar_output(move):
def decorate(f):
def caesarify_all(*args, **kwargs):
return caesarify(move, str(f(*args, **kwargs)))
return caesarify_all
return decorate
@caesar_output(13)
def cross_the_river():
return "ALEA IACTA EST"
def caesar_input(move, func):
def decorate(f):
def caesarify_all(*args, **kwargs):
args_new = []
for ind in range(len(args)):
if(func(ind)):
args_new.append(caesarify(move, args[ind]))
else:
args_new.append(args[ind])
return f(*args_new, **kwargs)
return caesarify_all
return decorate
@caesar_input(-13, lambda key: key > 0)
def make_a_speech(name, *args):
print('{} says:\n{}'.format(name, ' '.join(args)))
ceaser_input = caesar_input
ceaser_output = caesar_output
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Герасим Станчев
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Герасим Станчев
def ceaser_output(number):
output = ""
def ceaser_transposition(**kwargs):
for string in kwargs:
element = string()
element = element.upper()
for char in element:
if ord(char) + number > 90:
output.join(chr(ord(char) + number - 26))
elif ord(char) + number < 65:
output.join(chr(ord(char) + number + 26))
else:
output.join(chr(ord(char) + number))
return output
return ceaser_transposition
EEEE
======================================================================
ERROR: test_ceaser_input (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1063bvt/test.py", line 22, in test_ceaser_input
    decorator = solution.ceaser_input(-13, lambda key: key > 0)
AttributeError: 'module' object has no attribute 'ceaser_input'

======================================================================
ERROR: test_ceaser_output (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1063bvt/test.py", line 12, in test_ceaser_output
    decorated = decorator(cross_the_river)
TypeError: ceaser_transposition() takes 0 positional arguments but 1 was given

======================================================================
ERROR: test_output_with_overflowing (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1063bvt/test.py", line 18, in test_output_with_overflowing
    decorated = decorator(cross_the_river)
TypeError: ceaser_transposition() takes 0 positional arguments but 1 was given

======================================================================
ERROR: test_the_quick_brown_fox (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-1063bvt/test.py", line 40, in test_the_quick_brown_fox
    self.assertEqual(decorator(lambda: encoded)(), message)
TypeError: ceaser_transposition() takes 0 positional arguments but 1 was given

----------------------------------------------------------------------
Ran 4 tests in 0.003s

FAILED (errors=4)
Венцислав Велков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Венцислав Велков
import collections
def ceaser_encryption(text, displacement):
alphabet = list('abcdefghijklmnopqrstuvwxyz')
cipher = collections.deque(alphabet)
cipher.rotate(-displacement % 26)
ceaserlike = list(text)
for index, symbol in enumerate(ceaserlike):
if symbol.lower() in alphabet:
ceaserlike[index] = cipher[alphabet.index(symbol.lower())]
return "".join(ceaserlike).upper()
def ceaser_output(displacement):
def ceaserify(function):
def encrypt(*args):
return ceaser_encryption(function(*args), displacement)
return encrypt
return ceaserify
def ceaser_input(displacement, should_shift):
def ceaserify(function):
def encrypt(*args):
encrypted = list(args)
for index, arg in enumerate(args):
if should_shift(index):
encrypted[index] = ceaser_encryption(arg, displacement)
return function(*encrypted)
return encrypt
return ceaserify
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Деян Камбуров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Камбуров
def ceaser_output(offset):
def ceaser_encoder(function):
def decorated(*args):
ciffer = []
for symbol in function(*args).upper():
if symbol.isalpha():
ciffer.append(chr(
(ord(symbol) - 65 + offset % 26) % 26 + 65))
else:
ciffer.append(symbol)
return ''.join(ciffer)
return decorated
return ceaser_encoder
def ceaser_input(offset, filter_function):
def ceaser_decoder(function):
def decorated(*args):
message = []
for index, arg in enumerate(args):
if filter_function(index):
word = ""
for symbol in arg.upper():
if symbol.isalpha():
letter = chr(ord(symbol) + offset % 26)
if ord(symbol) + offset % 26 > 90:
letter = chr(ord(symbol) + offset % 26 - 26)
word += letter
else:
word += symbol
message.append(word)
else:
message.append(arg)
return function(*message)
return decorated
return ceaser_decoder
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Лъчезар Николов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Лъчезар Николов
def caesar_encryption(string, shifting):
encrypted_letters = []
for symbol in string:
if symbol.isalpha():
encrypted_letters.append(shift_single_character(symbol, shifting))
else:
encrypted_letters.append(symbol)
return ''.join(encrypted_letters)
def shift_single_character(char, shifting):
return chr((ord(char.upper()) - ord('A') + shifting) % 26 + ord('A'))
def ceaser_output(shifting):
def decorated(function):
def encrypt_output(*args, **kwargs):
return caesar_encryption(function(*args, **kwargs), shifting)
return encrypt_output
return decorated
def ceaser_input(shifting, predicate):
def decorated(function):
def modify_arguments(*args):
modified_arguments = []
for index, arg in enumerate(args):
if predicate(index):
modified_arguments.append(caesar_encryption(arg, shifting))
else:
modified_arguments.append(arg)
return function(*modified_arguments)
return modify_arguments
return decorated
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK
Ивайло Бъчваров
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Ивайло Бъчваров
import string
def ceaser_output(switch_number):
def _second(f):
def _inner(*args, **kwargs):
all_letters = string.ascii_uppercase
A_INDEX = 65
crypted = ""
string_to_crypt = f(*args, **kwargs)
for character in string_to_crypt:
if character.isalpha():
new_position = ord(character) - A_INDEX + switch_number
crypted += all_letters[new_position % len(all_letters)]
else:
crypted += character
return crypted
return _inner
return _second
E...
======================================================================
ERROR: test_ceaser_input (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-qgz3q4/test.py", line 22, in test_ceaser_input
    decorator = solution.ceaser_input(-13, lambda key: key > 0)
AttributeError: 'module' object has no attribute 'ceaser_input'

----------------------------------------------------------------------
Ran 4 tests in 0.003s

FAILED (errors=1)
Спасимир Тупаров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Спасимир Тупаров
ALPHABET = {x: chr(x) for x in range(ord("A"), ord("Z")+1)}
def decrypt_string(offset, string):
number_new_symbol = 0
result = ""
for symbol in string:
if not symbol.isalpha():
result += symbol
continue
number_new_symbol = ord(symbol) + offset
if number_new_symbol > 90:
while number_new_symbol > 90:
number_new_symbol -= 26
result += ALPHABET[number_new_symbol]
continue
if number_new_symbol < 65:
while number_new_symbol < 65:
number_new_symbol += 26
result += ALPHABET[number_new_symbol]
continue
result += ALPHABET[number_new_symbol]
return result
def ceaser_output(offset):
def wrapper(function):
def encryption():
result = ""
number_new_symbol = 0
not_encrypted = function().upper()
return decrypt_string(offset, not_encrypted)
return encryption
return wrapper
def ceaser_input(offset, function):
def wrapper(decorated_func):
def decrypting(*agrs_decorated):
result_message = []
for index, word in enumerate(agrs_decorated):
if function(index): # wra6ta true prilaga6 6ifar
result_message.append(decrypt_string(offset, word))
else:
result_message.append(word)
return decorated_func(*result_message)
return decrypting
return wrapper
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
Милен Христов
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Милен Христов
def ceaser_output(number):
def edecorator(func):
def ceaser_encoder():
result = []
inputLetters = func().upper()
for letter in inputLetters:
if letter.isalpha():
result.append(chr((ord(letter) - 65 + number) % 26 + 65))
else:
result.append(letter)
return ''.join(result)
return ceaser_encoder
return edecorator
E...
======================================================================
ERROR: test_ceaser_input (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-jja4gs/test.py", line 22, in test_ceaser_input
    decorator = solution.ceaser_input(-13, lambda key: key > 0)
AttributeError: 'module' object has no attribute 'ceaser_input'

----------------------------------------------------------------------
Ran 4 tests in 0.003s

FAILED (errors=1)
Стефан Колчев
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Стефан Колчев
def ceaser_output(number):
def ceaser(func):
def func_wrapper():
text_to_upper = func().upper()
letters_count = 26
schiffer = ""
for letter in text_to_upper:
if letter.isalpha():
letter_code = (ord(letter) - 65) + number
schiffer += chr((letter_code % letters_count) + 65)
else:
schiffer += letter
return schiffer
return func_wrapper
return ceaser
E...
======================================================================
ERROR: test_ceaser_input (test.TestCaesarCipher)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140614-17226-111y9su/test.py", line 22, in test_ceaser_input
    decorator = solution.ceaser_input(-13, lambda key: key > 0)
AttributeError: 'module' object has no attribute 'ceaser_input'

----------------------------------------------------------------------
Ran 4 tests in 0.003s

FAILED (errors=1)