145 lines
3.7 KiB
Markdown
145 lines
3.7 KiB
Markdown
# dotdash
|
|
|
|
dotdash is a tiny C++ playground for experimenting with Morse code encoding and decoding. Enter complete Morse code sequences to decode them, or type text to see the corresponding Morse code patterns.
|
|
|
|
## Morse Code Standard
|
|
|
|
This implementation follows the **Latin Morse code standard** as defined in the [International Morse Code specification](https://morsefm.com/fr/morse-code-chart/). It supports:
|
|
|
|
- All letters (A-Z)
|
|
- All digits (0-9)
|
|
- Standard punctuation: `. , ? ! ' / ( ) & : ; = + - _ " $ @`
|
|
- Space character for word separation
|
|
|
|
The Morse code mappings are compliant with the standard Latin alphabet Morse code used internationally.
|
|
|
|
## How it works
|
|
|
|
Both decode and encode modes use standard input/output with `getline` to read full lines of input.
|
|
|
|
Decode mode reads a complete Morse code sequence (e.g., "... --- ...") and displays each segment with its decoded character, followed by the final decoded message.
|
|
|
|
The parser:
|
|
|
|
- Trims leading and trailing whitespace
|
|
- Uses spaces to separate Morse code letters (spaces in input do not create spaces in the decoded output)
|
|
- Collapses multiple consecutive spaces into a single separator
|
|
- Treats `/` as a word separator (adds a space to the decoded output)
|
|
- Handles empty sequences between separators correctly
|
|
- Ignores invalid characters (non-`.`, `-`, ` `, `/`) and displays a warning
|
|
- Invalid Morse code sequences (that don't match any known pattern) are decoded as `?`
|
|
|
|
**Note:** The `/` character has a dual role: in decode mode it's used as a word separator, while in encode mode it encodes as `-..-.` (the forward slash punctuation). This is because the forward slash is not a valid Morse code character, but it's a common punctuation mark used in Morse code.
|
|
|
|
Encode mode reads text input and displays the Morse code pattern for each character, along with the complete Morse sequence. Unsupported characters (those not in the Morse code mapping) are silently skipped and do not appear in the output.
|
|
|
|
## Building
|
|
|
|
This project has no external dependencies beyond a C++23 compiler. Build with:
|
|
|
|
```bash
|
|
make
|
|
```
|
|
|
|
## Using the app
|
|
|
|
After building, run `./dotdash`.
|
|
|
|
The program starts in **decode mode**:
|
|
|
|
- Enter a complete Morse code sequence (e.g., "... --- ...")
|
|
- Use spaces to separate letters (spaces don't appear in the decoded output)
|
|
- Use `/` to separate words (adds a space in the decoded output)
|
|
- Multiple consecutive spaces are automatically collapsed
|
|
- Press `Enter` to see the decoded output
|
|
- Invalid characters are ignored with a warning
|
|
- Press `e` to switch to encode mode
|
|
|
|
In **encode mode**:
|
|
|
|
- Enter text to see Morse code patterns
|
|
- The program shows the Morse code pattern for each character
|
|
- The complete Morse sequence is displayed
|
|
- Press `d` to switch back to decode mode
|
|
|
|
In both modes:
|
|
|
|
- Type `exit` to quit the program
|
|
|
|
## Examples
|
|
|
|
### Decode Mode
|
|
|
|
Enter a complete Morse code sequence:
|
|
|
|
```
|
|
Enter morse sequence: ... --- ...
|
|
|
|
... -> S
|
|
--- -> O
|
|
... -> S
|
|
|
|
Final message: SOS
|
|
```
|
|
|
|
With word separator:
|
|
|
|
```
|
|
Enter morse sequence: .. .----. -- / .-. .. -.-. ....
|
|
.. -> I
|
|
.----. -> '
|
|
-- -> M
|
|
.-. -> R
|
|
.. -> I
|
|
-.-. -> C
|
|
.... -> H
|
|
|
|
Final message: I'M RICH
|
|
```
|
|
|
|
### Encode Mode
|
|
|
|
Type text to see Morse code:
|
|
|
|
```
|
|
Enter text to encode: SOS
|
|
|
|
S -> ...
|
|
O -> ---
|
|
S -> ...
|
|
|
|
Final sequence: ... --- ...
|
|
```
|
|
|
|
With word separator:
|
|
|
|
```
|
|
Enter text to encode: une phrase
|
|
|
|
u -> ..-
|
|
n -> -.
|
|
e -> .
|
|
|
|
[Space]
|
|
p -> .--.
|
|
h -> ....
|
|
r -> .-.
|
|
a -> .-
|
|
s -> ...
|
|
e -> .
|
|
|
|
Final sequence: ..- -. . / .--. .... .-. .- ... .
|
|
```
|
|
|
|
## TODO
|
|
|
|
- [ ] Add a way to play with the Morse code audio while using the decode mode
|
|
|
|
## Status
|
|
|
|
This is an experimental codebase for learning Morse code and playing with C++ programming.
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|