MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / encode

Method encode

ciphers/bifid.py:54–86  ·  view source on GitHub ↗

Return the encoded version of message according to the polybius cipher >>> BifidCipher().encode('testmessage') == 'qtltbdxrxlk' True >>> BifidCipher().encode('Test Message') == 'qtltbdxrxlk' True >>> BifidCipher().encode('test j') == BifidCipher().

(self, message: str)

Source from the content-addressed store, hash-verified

52 return letter
53
54 def encode(self, message: str) -> str:
55 """
56 Return the encoded version of message according to the polybius cipher
57
58 >>> BifidCipher().encode('testmessage') == 'qtltbdxrxlk'
59 True
60
61 >>> BifidCipher().encode('Test Message') == 'qtltbdxrxlk'
62 True
63
64 >>> BifidCipher().encode('test j') == BifidCipher().encode('test i')
65 True
66 """
67 message = message.lower()
68 message = message.replace(" ", "")
69 message = message.replace("j", "i")
70
71 first_step = np.empty((2, len(message)))
72 for letter_index in range(len(message)):
73 numbers = self.letter_to_numbers(message[letter_index])
74
75 first_step[0, letter_index] = numbers[0]
76 first_step[1, letter_index] = numbers[1]
77
78 second_step = first_step.reshape(2 * len(message))
79 encoded_message = ""
80 for numbers_index in range(len(message)):
81 index1 = int(second_step[numbers_index * 2])
82 index2 = int(second_step[(numbers_index * 2) + 1])
83 letter = self.numbers_to_letter(index1, index2)
84 encoded_message = encoded_message + letter
85
86 return encoded_message
87
88 def decode(self, message: str) -> str:
89 """

Callers 9

reformat_hexFunction · 0.45
preprocessFunction · 0.45
text_to_bitsFunction · 0.45
test_project_eulerFunction · 0.45
hash_Method · 0.45
generate_shared_keyMethod · 0.45
base64_encodeFunction · 0.45
get_blocks_from_textFunction · 0.45

Calls 3

letter_to_numbersMethod · 0.95
numbers_to_letterMethod · 0.95
emptyMethod · 0.45

Tested by 1

test_project_eulerFunction · 0.36