Пример #1
0
def breakit(input_file: IO[str], output_file: IO[str]) -> IO[str]:
    """
    Brute force breaker to crack encrypted text.

    Examples:
    $ python breaker.py file_to_crack.txt -o output_file_name.txt
    """
    click.echo('Decoding...')
    encrypted_text = input_file.read()
    # load an English dictionary
    english_dictionary = sc.SpellChecker("en")
    max_number_of_english_words = 0
    # tries possible alphabet shifts and shows a progress bar
    for key in tqdm(range(26)):
        plaintext = encrypt(encrypted_text, -key)
        number_of_english_words = 0

        for word in plaintext.split(' '):
            # check in the word_frequency list of words from the dictionary
            if word in english_dictionary.word_frequency:
                number_of_english_words += 1

        if number_of_english_words > max_number_of_english_words:
            max_number_of_english_words = number_of_english_words
            best_plaintext = plaintext
            best_key = key

    click.echo(f'Completed. The most likely encryption key is {best_key}. \
        \nIt gives the following plaintext:\n{best_plaintext[:1000]}...\n')
    output_file.write(best_plaintext)
Пример #2
0
def send():
    ending = '\nДля отписки от рассылки напиши /unsub'

    message = request.get_json()
    validation = RequestSchema().validate(message)

    logger.info(message)
    logger.info(validation)

    if validation != {}:
        return jsonify(validation)

    if 'X-Forwarded-For' in request.headers:
        ip = request.headers.getlist('X-Forwarded-For')[0]
    elif 'X-Real-Ip' in request.headers:
        ip = request.headers.getlist('X-Real-Ip')[0]
    else:
        ip = request.remote_addr

    if ip not in settings.ip:
        return jsonify('Forbidden')

    if settings.encryption:
        if message['sign'] != encrypt(message):
            return jsonify('Forbidden')

    text = message['message']
    try:
        link = message['link']

    except KeyError:
        link = None

    response = {}

    if 'discord' in message['dispatchers']:
        response.update({"discord": discord_bot.main(text, link)})
    if 'telegram' in message['dispatchers']:
        response.update({"telegram": tele_bot.main(text, link)})
    if 'vk' in message['dispatchers']:
        response.update({"vk": vk_bot.main(text + ending, link)})
    return jsonify(response)
def test_break_code_wonka_wrap():
    encrypted = encrypt('We are the dreams of makers and the makers of dreams 111', 30)
    actual = break_code(encrypted) 
    expected = 'We are the dreams of makers and the makers of dreams 111'
    assert actual == expected
def test_encrypt_lower():
    actual = encrypt('abc', 1) 
    expected = 'bcd'
    assert actual == expected
def test_break_code_wrap():
    encrypted = encrypt('It was the best of times, it was the worst of times.', 30)
    actual = break_code(encrypted) 
    expected = 'It was the best of times, it was the worst of times.'
    assert actual == expected
def test_encrypt_non_string():
    actual = encrypt('X8Z', 1) 
    expected = 'Y8A'
    assert actual == expected
def test_encrypt_upper_wrap():
    actual = encrypt('XYZ', 1) 
    expected = 'YZA'
    assert actual == expected
def test_encrypt_upper():
    actual = encrypt('ABC', 1) 
    expected = 'BCD'
    assert actual == expected
def test_encrypt__lower_wrap():
    actual = encrypt('xyz', 1) 
    expected = 'yza'
    assert actual == expected