コード例 #1
0
ファイル: test_huffman.py プロジェクト: piroflip/acsploit
def test_run():
    output = DummyOutput()
    expected = 'abccdddeeeee'
    n_inputs = len(expected)
    huffman.options['n_inputs'] = n_inputs
    huffman.run(CharGenerator(), output)
    assert len(output) == 1
    assert output[0] == expected
コード例 #2
0
def test_run():
    output = DummyOutput()
    string_length = 120
    line_breaking.options['string_length'] = string_length
    line_breaking.run(CharGenerator(), output)
    assert len(output) == 1
    assert len(output[0]) == string_length - 1
    assert output[0] == ('a ' * ((string_length - 1) // 2)) + 'a'
コード例 #3
0
def test_smaller_length_than_substring_length():
    output = DummyOutput()
    length = 2
    substring_length = 3
    target = '42'
    python2_32.options['length'] = length
    python2_32.options['substring_length'] = substring_length
    python2_32.options['target'] = target
    with pytest.raises(ValueError):
        python2_32.run(CharGenerator(), output)
コード例 #4
0
ファイル: test_rabin_karp.py プロジェクト: piroflip/acsploit
def test_run():
    output = DummyOutput()
    string_length = 10
    pattern_length = 5
    rabin_karp.options['string_length'] = string_length
    rabin_karp.options['pattern_length'] = pattern_length
    rabin_karp.options['match'] = True
    rabin_karp.run(CharGenerator(), output)
    assert len(output) == 2
    string = output[0][len('String: '):]
    pattern = output[1][len('Search Pattern: '):]
    assert string == 'a' * string_length
    assert pattern == 'a' * pattern_length
コード例 #5
0
ファイル: test_boyer_moore.py プロジェクト: piroflip/acsploit
def test_longer_pattern():
    output = DummyOutput()
    string_length = 10
    pattern_length = 50
    boyer_moore.options['string_length'] = string_length
    boyer_moore.options['pattern_length'] = pattern_length
    boyer_moore.options['match'] = True
    boyer_moore.run(CharGenerator(), output)
    assert len(output) == 2
    string = output[0][len('String: '):]
    pattern = output[1][len('Search Pattern: '):]
    assert string == 'a' * string_length
    assert pattern == 'a' * pattern_length
コード例 #6
0
def test_longer_string():
    output = DummyOutput()
    string_length = 100
    pattern_length = 5
    knuth_morris_pratt.options['string_length'] = string_length
    knuth_morris_pratt.options['pattern_length'] = pattern_length
    knuth_morris_pratt.options['match'] = True
    knuth_morris_pratt.run(CharGenerator(), output)
    assert len(output) == 2
    string = output[0][len('String: '):]
    pattern = output[1][len('Search Pattern: '):]
    assert string == 'a' * string_length
    assert pattern == 'a' * pattern_length
コード例 #7
0
def test_run_small_collision_count():
    output = DummyOutput()
    n_collisions = 10
    hash_table_size = 2**32
    target = '42'
    java.options['n_collisions'] = n_collisions
    java.options['target_type'] = 'image'
    java.options['target'] = target
    java.options['hash_table_size'] = hash_table_size
    java.run(CharGenerator(), output)
    assert output.count() == n_collisions
    for i in output:
        assert java_common.java_hash(i, hash_table_size) == int(target)
コード例 #8
0
ファイル: test_rabin_karp.py プロジェクト: piroflip/acsploit
def test_run_no_match():
    output = DummyOutput()
    string_length = 10
    pattern_length = 5
    rabin_karp.options['string_length'] = string_length
    rabin_karp.options['pattern_length'] = pattern_length
    rabin_karp.options['match'] = False
    rabin_karp.run(CharGenerator(), output)
    assert len(output) == 2
    string = output[0][len('String: '):]
    pattern = output[1][len('Search Pattern: '):]
    assert string == ('a' * (pattern_length - 1) + 'z') * (string_length //
                                                           pattern_length)
    assert pattern == 'a' * pattern_length
コード例 #9
0
def test_preimage():
    output = DummyOutput()
    n_collisions = 10
    hash_table_size = 2**32
    preimage_target = 'hello world'
    java.options['n_collisions'] = n_collisions
    java.options['target_type'] = 'preimage'
    java.options['target'] = preimage_target
    java.options['hash_table_size'] = hash_table_size
    java.run(CharGenerator(), output)
    target = java_common.java_hash(preimage_target, hash_table_size)
    assert output.count() == n_collisions
    for i in output:
        assert java_common.java_hash(i, hash_table_size) == target
コード例 #10
0
def test_run_small_collision_count():
    output = DummyOutput()
    n_collisions = 20
    hash_table_size = 2**32
    target = '42'
    php5_fast.options['n_collisions'] = n_collisions
    php5_fast.options['n_substrings'] = 10
    php5_fast.options['target_type'] = 'image'
    php5_fast.options['target'] = target
    php5_fast.options['hash_table_size'] = hash_table_size
    php5_fast.run(CharGenerator(), output)
    assert output.count() == n_collisions
    for i in output:
        assert php5_common.php_hash(i, hash_table_size) == int(target)
コード例 #11
0
def test_run_small_collision_output():
    output = DummyOutput()
    n_collisions = 2
    length = 7
    substring_length = 3
    target = '42'
    python2_32.options['n_collisions'] = n_collisions
    python2_32.options['length'] = length
    python2_32.options['substring_length'] = substring_length
    python2_32.options['target'] = target
    python2_32.options['target_type'] = 'image'
    python2_32.run(CharGenerator(), output)
    assert output.count() == n_collisions
    for i in output:
        assert python2_32.hash(i) == int(target)
コード例 #12
0
def test_preimage():
    output = DummyOutput()
    n_collisions = 2
    length = 8
    substring_length = 4
    target = 'hello'
    python2_32.options['n_collisions'] = n_collisions
    python2_32.options['length'] = length
    python2_32.options['substring_length'] = substring_length
    python2_32.options['target'] = target
    python2_32.options['target_type'] = 'preimage'
    python2_32.run(CharGenerator(), output)
    assert output.count() == n_collisions
    for i in output:
        assert python2_32.hash(i) == python2_32.hash(target)
コード例 #13
0
def test_preimage():
    output = DummyOutput()
    n_collisions = 10
    hash_table_size = 2**32
    preimage_target = 'hello world'
    php5_fast.options['n_collisions'] = n_collisions
    php5_fast.options['n_substrings'] = 10
    php5_fast.options['target_type'] = 'preimage'
    php5_fast.options['target'] = preimage_target
    php5_fast.options['hash_table_size'] = hash_table_size
    php5_fast.run(CharGenerator(), output)
    target = php5_common.php_hash(preimage_target, hash_table_size)
    assert output.count() == n_collisions
    for i in output:
        assert php5_common.php_hash(i, hash_table_size) == target