-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnato.py
More file actions
executable file
·80 lines (64 loc) · 1.43 KB
/
nato.py
File metadata and controls
executable file
·80 lines (64 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
"""
@file nato.py
@brief Translates to and from the NATO alphabet.
@author Evan Elias Young
@date 2018-07-27
@date 2022-02-04
@copyright Copyright 2022 Evan Elias Young. All rights reserved.
"""
from string import ascii_lowercase as shorts
longs: list[str] = [
"Alpha",
"Bravo",
"Charlie",
"Delta",
"Echo",
"Foxtrot",
"Golf",
"Hotel",
"India",
"Juliett",
"Kilo",
"Lima",
"Mike",
"November",
"Oscar",
"Papa",
"Quebec",
"Romeo",
"Sierra",
"Tango",
"Uniform",
"Victor",
"Whiskey",
"X-ray",
"Yankee",
"Zulu",
]
def encode(string: str) -> str:
"""Will encode a string into NATO speak.
Args:
string (string): The string to encode.
Returns:
string: The NATO speak.
"""
ret: list[str] = [longs[shorts.index(c)] for c in string.lower() if c in shorts]
return " ".join(ret)
def decode(string: str) -> str:
"""Will decode NATO speak into a string.
Args:
string (string): The NATO speak.
Returns:
string: The original string.
"""
ret: list[str] = [w[0] for w in string.split(" ")]
return "".join(ret)
if __name__ == "__main__":
print("Hello Console!")
print(encode("My name is Evan"))
print(
decode(
"Mike Yankee November Alpha Mike Echo India Sierra Echo Victor Alpha November"
)
)