class Scytale: def encrypt(self, texto, key): ''' (Scytale, str, int) -> str Cifra o texto com a cifra scytale utilizando a chave key. ''' cifrado = '' texto = texto.replace(' ', '') # calcula a qtd de caracteres e a qtd de colunas qtd_ch = len(texto) col = qtd_ch // key if qtd_ch % key > 0: col += 1 i = ord('A') while len(texto) < key * col: texto += chr(i) i += 1 for i in range(col): for j in range(0, qtd_ch, col): cifrado += texto[i + j] return cifrado.upper() def decrypt(self, texto, key): ''' (Scytale, str, int) -> str Decifra o texto cifrado com a cifra Scytale usando a chave key. ''' texto_plano = '' texto = texto.replace(' ', '') for i in range(key): for j in range(0, len(texto), key): texto_plano += texto[i + j] return texto_plano.lower()