This project implements a Morse code converter using a binary tree data structure. It supports both encoding plaintext messages into Morse code and decoding Morse code back into plaintext.
- Encoding: Converts plaintext messages to Morse code.
- Decoding: Converts Morse code messages back to plaintext.
- Binary Tree Visualization: Visualizes the binary tree used for Morse code conversion.
The binary tree is structured to include the first four levels, which are sufficient to encode all 26 letters of the alphabet.
- Python 3.x
- Clone the repository:
git clone https://github.com/yourusername/morse-code-binary-tree.git
- Navigate to the project directory:
cd morse-code-binary-tree
Run the main.py
script to start the Morse code converter:
python main.py
- When prompted, choose to encode a message by entering
E
. - Enter your message (e.g.,
SOS
). - The program will output the Morse code equivalent of your message.
- When prompted, choose to decode a message by entering
D
. - Enter your Morse code message, using spaces to separate each Morse code character (e.g.,
... --- ...
forSOS
). - The program will output the decoded plaintext message.
Do you want to (E)ncode or (D)ecode a message? (E/D): E
Enter a message to convert into Morse Code: (e.g. SOS): SOS
Morse Code:
... --- ...
Do you want to (E)ncode or (D)ecode a message? (E/D): D
Enter a Morse Code message to decode (use space to separate letters): ... --- ...
Decoded Message:
SOS
main.py
: The main program file containing the Morse code conversion logic.tree.py
: Contains the code to draw the binary tree structure.
- The program constructs a binary tree where each node represents a character.
- It traverses the tree to find the corresponding Morse code for each character in the input message.
- The program reads the Morse code input.
- It traverses the binary tree based on the sequence of dots and dashes to find the corresponding character.
Contributions are welcome! Please open an issue or submit a pull request.