コード例 #1
0
ファイル: bellaso.py プロジェクト: stroykova/search
def second_sifra(data, key, alphabet_key):
    #now the substitution alphabet is generated from a passphrase

    consonants = mix_alphabet(alphabet_key, "bcdfghlmnpqrstxyz")
    #then we'll work on the vowels, but we'll insert them every 3 character
    #let's split the consonants string
    consonants_blocks = split_string_blocks(consonants, 3)
    #and parse the key for its used vowels
    vowels = mix_alphabet(alphabet_key, "aeiou")
    #let's merge the consonants and vowels data

    alphabet = "".join(i + j
                       for i, j in zip_extend(consonants_blocks, list(vowels)))

    #assert alphabet == "rmqacntupsbidfgehlxoyz"
    constant_part, rotated_part = alphabet[:11], Str(alphabet[11:])

    #now to generate the pairs, we'll do the same, but merge the vowel every char blocks
    consonants_blocks = split_string_blocks(consonants, 1)
    pairsString = Str("".join(
        i + j for i, j in zip_extend(consonants_blocks, list(vowels))))
    pairs = pairsString.splitblock(2)

    #now we have the pairs, the initial substitution alphabet
    #let's generate the 'rotated' alphabet for each pair
    alphabets = dict()
    for index, pair in enumerate(pairs):
        #let's get the pair by its first char in the order
        alphabets[pair] = constant_part + (rotated_part >> index)

    # now the actual encryption
    # for this cipher, the xth character of the key is used to decrypt the xth word (space separated) of the plaintext
    output = str()
    key_index = 0
    for char in data:
        pair = [p for p in alphabets if key[key_index] in p]
        if pair:
            char = substitute(char, alphabets[pair[0]])
        if char == ' ':
            key_index += 1
        output += char
    return output
コード例 #2
0
ファイル: bellaso.py プロジェクト: 4lextg/kabopan
def second_sifra(data, key, alphabet_key):
    #now the substitution alphabet is generated from a passphrase

    consonants = mix_alphabet(alphabet_key, "bcdfghlmnpqrstxyz")
    #then we'll work on the vowels, but we'll insert them every 3 character
    #let's split the consonants string
    consonants_blocks = split_string_blocks(consonants, 3)
    #and parse the key for its used vowels
    vowels = mix_alphabet(alphabet_key, "aeiou")
    #let's merge the consonants and vowels data

    alphabet = "".join(i + j for i, j in zip_extend(consonants_blocks, list(vowels)))

    #assert alphabet == "rmqacntupsbidfgehlxoyz"
    constant_part, rotated_part = alphabet[:11], Str(alphabet[11:])

    #now to generate the pairs, we'll do the same, but merge the vowel every char blocks
    consonants_blocks = split_string_blocks(consonants, 1)
    pairsString = Str("".join(i + j for i, j in zip_extend(consonants_blocks, list(vowels))))
    pairs = pairsString.splitblock(2)

    #now we have the pairs, the initial substitution alphabet
    #let's generate the 'rotated' alphabet for each pair
    alphabets = dict()
    for index, pair in enumerate(pairs):
        #let's get the pair by its first char in the order
        alphabets[pair] = constant_part + (rotated_part >> index)

    # now the actual encryption
    # for this cipher, the xth character of the key is used to decrypt the xth word (space separated) of the plaintext
    output = str()
    key_index = 0
    for char  in data:
        pair = [p for p in alphabets if key[key_index] in p]
        if pair:
            char = substitute(char, alphabets[pair[0]])
        if char == ' ':
            key_index += 1
        output += char
    return output
コード例 #3
0
ファイル: types_test.py プロジェクト: 4lextg/kabopan
s = Str("abcdefghij")
assert [ s,           s << 1,       s >> 1,       (s << 1) >> 1, s << 2,       s << 3,      s << 4] == \
       ['abcdefghij', 'bcdefghija', 'jabcdefghi', 'abcdefghij', 'cdefghijab', 'defghijabc', 'efghijabcd']

assert s.setstart("d") == "defghijabc"

s = Str('abcaba')
assert s.indexes("a") == [0, 3, 5]
assert s.indexes("d") == []

s = Str("abcdefghij")
import pprint
assert [s.insert("1", 2), s.insert("12", 2), s.overwrite("1", 2), s.overwrite("12", 2)] == \
       ['ab1cdefghij',   'ab12cdefghij',     'ab1defghij',        'ab12efghij']

assert [s.splitblock(2), s.splitblock(3)] == [['ab', 'cd', 'ef', 'gh', 'ij'], ['abc', 'def', 'ghi', 'j']]
 

assert List([1, 2, 3, 4]) >> 1 == [4, 1, 2, 3]
assert List([1, 2, 3, 4]) >> 4 == [1, 2, 3, 4]
assert List([1, 2, 3, 4]) << 1 == [2, 3, 4, 1]

assert 0xFFCD9AD6 == Dword(251972843051734)
assert 0x9AD6 == Word(251972843051734)
assert 0xD6 == Byte(251972843051734)
assert str(Qword(17)) == "0000000000000011"
assert 214 == Byte(251972843051734)
assert Byte(15 + 1)  == Byte(15) + 1

# casting is important
assert Byte(0xF) + Dword(0xFFFFF00) == 0xF
コード例 #4
0
ファイル: types_test.py プロジェクト: stroykova/search
s = Str("abcdefghij")
assert [ s,           s << 1,       s >> 1,       (s << 1) >> 1, s << 2,       s << 3,      s << 4] == \
       ['abcdefghij', 'bcdefghija', 'jabcdefghi', 'abcdefghij', 'cdefghijab', 'defghijabc', 'efghijabcd']

assert s.setstart("d") == "defghijabc"

s = Str('abcaba')
assert s.indexes("a") == [0, 3, 5]
assert s.indexes("d") == []

s = Str("abcdefghij")
import pprint
assert [s.insert("1", 2), s.insert("12", 2), s.overwrite("1", 2), s.overwrite("12", 2)] == \
       ['ab1cdefghij',   'ab12cdefghij',     'ab1defghij',        'ab12efghij']

assert [s.splitblock(2), s.splitblock(3)] == [['ab', 'cd', 'ef', 'gh', 'ij'],
                                              ['abc', 'def', 'ghi', 'j']]

assert List([1, 2, 3, 4]) >> 1 == [4, 1, 2, 3]
assert List([1, 2, 3, 4]) >> 4 == [1, 2, 3, 4]
assert List([1, 2, 3, 4]) << 1 == [2, 3, 4, 1]

assert 0xFFCD9AD6 == Dword(251972843051734)
assert 0x9AD6 == Word(251972843051734)
assert 0xD6 == Byte(251972843051734)
assert str(Qword(17)) == "0000000000000011"
assert 214 == Byte(251972843051734)
assert Byte(15 + 1) == Byte(15) + 1

# casting is important
assert Byte(0xF) + Dword(0xFFFFF00) == 0xF