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
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
assert gethyphenstr(r"c:\WINDOWS\system32\drivers\http.sys") == r"c:\WINDOW [...] \http.sys" assert getbinstr(0) == "0" assert getbinstr(8) == "1000" assert countmissing(0, 8) == 0 assert countmissing(3, 8) == 5 assert countmissing(8, 8) == 0 assert insert_string("abcd", 2, "1") == "ab1cd" assert zip([1, 2], [0]) == [(1, 0)] assert zip_extend([1, 2], [0], 0) == [(1, 0), (2, 0)] assert zip_extend([0], [1, 2], 0) == [(1, 0), (2, 0)] assert rorstr("abc") == "cab" assert [rorstr("abc", i) for i in range(4)] == ['abc', 'cab', 'bca', 'abc'] assert setstr("abcde","d") == "deabc" assert list(slice_and_pad("0001" + "0000" + "0", 4)) == ['0001', '0000', '01__'] assert list(slice_and_pad("0001" + "0000" + "00", 4)) == ['0001', '0000', '001_'] assert list(slice_and_pad("0001" + "0000" + "000", 4)) == ['0001', '0000', '0001', 'extr'] assert list(slice_and_pad("0001" + "0000" + "0000", 4)) == ['0001', '0000', '0000', '1___'] assert hex2bin("0123456789ABCDEF") == "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
assert nibbleswap(0x1234, 2) == 0x2143 assert gethyphenstr( r"c:\WINDOWS\system32\drivers\http.sys") == r"c:\WINDOW [...] \http.sys" assert getbinstr(0) == "0" assert getbinstr(8) == "1000" assert countmissing(0, 8) == 0 assert countmissing(3, 8) == 5 assert countmissing(8, 8) == 0 assert insert_string("abcd", 2, "1") == "ab1cd" assert zip([1, 2], [0]) == [(1, 0)] assert zip_extend([1, 2], [0], 0) == [(1, 0), (2, 0)] assert zip_extend([0], [1, 2], 0) == [(1, 0), (2, 0)] assert rorstr("abc") == "cab" assert [rorstr("abc", i) for i in range(4)] == ['abc', 'cab', 'bca', 'abc'] assert setstr("abcde", "d") == "deabc" assert list(slice_and_pad("0001" + "0000" + "0", 4)) == ['0001', '0000', '01__'] assert list(slice_and_pad("0001" + "0000" + "00", 4)) == ['0001', '0000', '001_'] assert list(slice_and_pad("0001" + "0000" + "000", 4)) == ['0001', '0000', '0001', 'extr'] assert list(slice_and_pad("0001" + "0000" + "0000", 4)) == ['0001', '0000', '0000', '1___']