Skip to main content

Easily Encode & Decode Morse Code

Project description

Logo

License

Requirements

Python Version

Introduction

MorseCodePy helps with encoding text into Morse code and decoding it back. It supports multiple languages, including English, Russian, Ukrainian, Spanish, French. It also has support for numbers and other special characters.


Usage

encode(string, /, language, *, dot, dash, error, markup)

Encodes the string into Morse code

  • string: Input string
  • language: Language for encoding (e.g., english, french, spanish, russian, ukrainian, numbers, special)
  • dot: (optional) Symbol representing dots (default is .)
  • dash: (optional) Symbol representing dashes (default is -)
  • separator: (optional) Symbol separating words (default is /)
  • error: (optional) Symbol representing errors when the index is not found in the dictionary (default is *)
  • markup: (optional) If True, shows the original character in brackets before its Morse code (default is False)
from MorseCodePy import encode

# Encoding a simple English sentence
encoded_string: str = encode('Python is fun!', language='english')
print(encoded_string)
# Output: .--. -.-- - .... --- -. / .. ... / ..-. ..- -. -.-.--
from MorseCodePy import encode

# Encoding a Ukrainian sentence with custom dot and dash symbols and unsupported characters
encoded_string: str = encode('Привіт, світ! Ü', language='ukrainian', dot='*', dash='=', error='#')
print(encoded_string)
# Output: *==* *=* =*== *== ** = ==**== / *** *== ** = =*=*== / #
from MorseCodePy import encode

# Encoding a Russian sentence with markup
encoded_string: str = encode('До встречи!', language='russian', markup=True)
print(encoded_string)

# Output: [Д] -.. [О] --- / [В] .-- [С] ... [Т] - [Р] .-. [Е] . [Ч] ---. [И] .. [!] -.-.--

decode(code, /, language, *, dot, dash, error, markup)

Decode the Morse code into a string

  • code: Input Morse code string
  • language: Language for decoding (e.g., english, french, spanish, russian, ukrainian, numbers, special)
  • dot: (optional) Symbol representing dots (default is .)
  • dash: (optional) Symbol representing dashes (default is -)
  • separator (optional) Symbol separating words (default is /)
  • error: (optional) Symbol representing errors when the index is not found in the dictionary (default is *)
  • markup: (optional) If True, shows the original Morse code sequence in brackets before the decoded character (default is False)
from MorseCodePy import decode

# Decoding Morse code to Spanish text
decoded_string: str = decode('-- --- .-. ... . / -.-. --- -.. .', language='spanish')
print(decoded_string)
# Output: morse code
from MorseCodePy import decode

# Decoding Morse code numbers with custom symbols
decoded_string: str = decode('****- **--- / *---- -----', language='numbers', dot='*', error='#')
print(decoded_string)
# Output: 42 10

chart(*, dot, dash)

Print Morse code chart in the console

  • dot: (optional) Symbol representing dots (default is ·)
  • dash: (optional) Symbol representing dashes (default is -)
from MorseCodePy import chart

chart(dot='.', dash='_')

Command Lines

MorseCodePy also has terminal commands! You can encode, decode, view a Morse code chart, list supported languages, and more directly from the terminal. All the commands are very similar to the original Python function, so I recommend reading the documentation for them first.

encode

Encode text into Morse code

Command: morsecodepy encode <text> <language> [--dot DOT] [--dash DASH] [--separator SEPARATOR] [--error ERROR] [--markup]

morsecodepy encode "Python is fun!" english

decode

Decode Morse code into text

Command: morsecodepy decode <code> <language> [--dot DOT] [--dash DASH] [--separator SEPARATOR] [--error ERROR] [--markup]

morsecodepy decode "-- --- .-. ... . / -.-. --- -.. ." spanish

chart

Print out the code chart

Command: morsecodepy chart [--dot DOT] [--dash DASH]

morsecodepy chart --dot '*' --dash '='

languages

Print out the list of supported languages

Command: morsecodepy languages


Contact

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

morsecodepy-4.2.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

morsecodepy-4.2.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file morsecodepy-4.2.1.tar.gz.

File metadata

  • Download URL: morsecodepy-4.2.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for morsecodepy-4.2.1.tar.gz
Algorithm Hash digest
SHA256 f95aff2d19fb966f0faeab092334c0128e367bd90298d19abd238315c0579b63
MD5 ff00e7284cff032ed810feaa77407bb9
BLAKE2b-256 ab8abc1a5bd1021680da46c53e5c5c7626afc64947eafc16690e5f20ea99fc5c

See more details on using hashes here.

File details

Details for the file morsecodepy-4.2.1-py3-none-any.whl.

File metadata

  • Download URL: morsecodepy-4.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for morsecodepy-4.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b40e3a53d5d40b7b07155943d38ba68edb1070a727f0cae467a33fd46c10765b
MD5 9b811c73f29de33b02af6ec7eb3dc9bc
BLAKE2b-256 bc34ae12d3aa40fae62257b6a4c721efb68b0d4fbb02f7de5e95c4e8c94dc34c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page