Skip to main content

Easily Encode & Decode Morse Code

Project description

Logo

License

Requirements

Python Version pygame Version

Introduction

MorseCodePy is a versatile Python library that streamlines the encoding and decoding of text into Morse code and back. With support for multiple languages, including English, Russian, Ukrainian,Spanish, French, as well as provisions for handling numbers and other special characters. This library offers a powerful and user-friendly Morse code tool.


Usage

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

Encode a text string into Morse code.

  • string: The text string you want to encode.
  • language: The target language for encoding ( e.g., english, french, spanish, russian, ukrainian, numbers, special).
  • dot: (optional) Symbol to represent dots (default is .).
  • dash: (optional) Symbol to represent dashes (default is -).
  • error: (optional) Symbol to represent errors when an unknown character is encountered (default is *).
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: *==* *=* =*== *== ** = ==**== / *** *== ** = =*=*== / #

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

Decode Morse code into a text string.

  • code: The Morse code string you want to decode.
  • language: The target language for decoding ( e.g., english, french, spanish, russian, ukrainian, numbers, special).
  • dot: (optional) Symbol to represent dots (default is .).
  • dash: (optional) Symbol to represent dashes (default is -).
  • error: (optional) Symbol to represent errors when an unknown Morse code sequence is encountered (default is *).
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 a Morse code chart in the console.

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

chart(dot='·')  # Try it yourself :)

Note

When selecting a spoken language in the encode() or decode() functions, the output will automatically include numbers and special. However, if you choose only numbers or special, the output will contain exclusively their respective codes.


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.0.tar.gz (145.2 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: morsecodepy-4.0.tar.gz
  • Upload date:
  • Size: 145.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for morsecodepy-4.0.tar.gz
Algorithm Hash digest
SHA256 989df34a994a562c463388c233c7a5f02875c6553faef6775f7bec2ab54eac80
MD5 6ef34682f3cc07ba5d75a80f3fa1c1dd
BLAKE2b-256 4612fac2cbd010bfcdea11b0ecd0ec1473b5de1a177ec9f8173c21249ff2ab77

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