MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / encode_to_morse

Function encode_to_morse

ciphers/fractionated_morse_cipher.py:79–92  ·  view source on GitHub ↗

Encode a plaintext message into Morse code. Args: plaintext: The plaintext message to encode. Returns: The Morse code representation of the plaintext message. Example: >>> encode_to_morse("defend the east") '-..x.x..-.x.x-.x-..xx-x....x.xx.x.-x...x-'

(plaintext: str)

Source from the content-addressed store, hash-verified

77
78
79def encode_to_morse(plaintext: str) -> str:
80 """Encode a plaintext message into Morse code.
81
82 Args:
83 plaintext: The plaintext message to encode.
84
85 Returns:
86 The Morse code representation of the plaintext message.
87
88 Example:
89 >>> encode_to_morse("defend the east")
90 '-..x.x..-.x.x-.x-..xx-x....x.xx.x.-x...x-'
91 """
92 return "x".join([MORSE_CODE_DICT.get(letter.upper(), "") for letter in plaintext])
93
94
95def encrypt_fractionated_morse(plaintext: str, key: str) -> str:

Callers 1

Calls 1

getMethod · 0.45

Tested by

no test coverage detected