Exemplo n.º 1
0
def test_brute_force_transposition_mp(loaded_dictionaries: LoadedDictionaries):
    elapsed_time = []
    with timeit(elapsed_time):
        found_key = brute_force_mp(CIPHERED_MESSAGE_KEY_8,
                                   _database_path=loaded_dictionaries.temp_dir)
        _assert_found_key(found_key)
    print(
        f"\n\nElapsed time with test_brute_force_transposition_mp: {elapsed_time[0]} seconds."
    )
Exemplo n.º 2
0
def test_brute_force_vigenere_mp(loaded_dictionaries: LoadedDictionaries):
    elapsed_time = []
    with timeit(elapsed_time):
        found_key = brute_force_mp(CIPHERED_MESSAGE,
                                   _database_path=loaded_dictionaries.temp_dir,
                                   _testing=True)
        _assert_found_key(found_key)
    print(
        f"\n\nElapsed time with test_brute_force_vigenere_mp: {elapsed_time[0]} seconds."
    )
Exemplo n.º 3
0
def test_statistical_brute_force_vigenere_mp(
        loaded_dictionaries: LoadedDictionaries):
    ciphered_text = "PPQCA XQVEKG YBNKMAZU YBNGBAL JON I TSZM JYIM. VRAG VOHT VRAU C TKSG. DDWUO XITLAZU VAVV RAZ C VKB QP IWPOU"
    test_key = "wick"
    elapsed_time = []
    with timeit(elapsed_time):
        found_key = statistical_brute_force_mp(
            ciphered_text,
            _database_path=loaded_dictionaries.temp_dir,
            maximum_key_length=4)
        assert found_key == test_key
    print(
        f"\n\nElapsed time with test_brute_force_vigenere_mp: {elapsed_time[0]} seconds."
    )
def test_hack_substitution_mp(loaded_dictionaries: LoadedDictionaries,
                              text_file: str, language: str, key: str,
                              charset: str):
    elapsed_time = []
    with timeit(elapsed_time):
        text_file_pathname = os.path.join(os.getcwd(), "cifra", "tests",
                                          text_file)
        with open(text_file_pathname) as text_file:
            clear_text = text_file.read()
            ciphered_text = substitution.cipher(clear_text, key, charset)
        found_key = attack_substitution.hack_substitution_mp(
            ciphered_text,
            charset,
            _database_path=loaded_dictionaries.temp_dir)
        assert key == found_key[0]
    print(
        f"\n\nElapsed time with test_hack_substitution: {elapsed_time[0]} seconds."
    )
def test_timeit():
    TIME_TO_SLEEP = 1  # seconds
    elapsed_time = []
    with timing.timeit(elapsed_time):
        time.sleep(TIME_TO_SLEEP)
    assert TIME_TO_SLEEP <= elapsed_time[0]