Ejemplo n.º 1
0
def fitness(position):
    key = "".join(alphabet[i] for i in position)
    substitution = Substitution(alphabet, key)
    original_text = substitution.decrypt(cyphertext)
    frequency = Frequency(n_gram, alphabet)
    frequency.get_frequency(original_text)
    res = 0
    for i in range(len(n_gram)):
        for j in range(len(frequency.ftab[i])):
            res += alpha[i] * abs(frequency.ftab[i][j] - target.ftab[i][j])
    return res
Ejemplo n.º 2
0
from caesar import Caesar

args = get_args()
file_data = get_text_data(args['FILENAME'])
text = file_data

if args['CIPHER'] == 'SUBSTITUTION':
    substitution = Substitution()

    if args['SHOULD_ENCRYPT']:
        key = args['ENCRYPTION_KEY']
        encrypted = substitution.encrypt(text, key)
        print(encrypted)

    elif args['SHOULD_DECRYPT']:
        decrypted = substitution.decrypt(text)
        print(decrypted)

elif args['CIPHER'] == 'VIGENERE':
    vigenere = Vigenere()

    if args['SHOULD_ENCRYPT']:
        key = args['ENCRYPTION_KEY']
        encrypted = vigenere.encrypt(text, key)
        print(encrypted)

    elif args['SHOULD_DECRYPT']:
        key_length = args['VIGENERE_KEY_LENGTH']
        decrypted = vigenere.decrypt(text, key_length)
        print(decrypted)