Skip to content

Commit b1e0e3f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 06cb5d3 commit b1e0e3f

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

ciphers/atbash.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,35 @@
22

33
import string
44

5+
56
def atbash(text: str) -> str:
67
"""
78
Encodes or decodes text using the Atbash cipher.
8-
9+
910
The Atbash cipher substitutes each letter with its mirror in the alphabet:
1011
A -> Z, B -> Y, C -> X, ... Z -> A (case is preserved)
1112
Non-alphabetic characters are left unchanged.
12-
13+
1314
Args:
1415
text: The input string to encode/decode
15-
16+
1617
Returns:
1718
The transformed string
1819
"""
1920
# Create translation tables for uppercase and lowercase
20-
lowercase_map = str.maketrans(
21-
string.ascii_lowercase,
22-
string.ascii_lowercase[::-1]
23-
)
24-
uppercase_map = str.maketrans(
25-
string.ascii_uppercase,
26-
string.ascii_uppercase[::-1]
27-
)
28-
21+
lowercase_map = str.maketrans(string.ascii_lowercase, string.ascii_lowercase[::-1])
22+
uppercase_map = str.maketrans(string.ascii_uppercase, string.ascii_uppercase[::-1])
23+
2924
# Apply both translation mappings
3025
return text.translate(lowercase_map).translate(uppercase_map)
3126

27+
3228
# Example usage
3329
if __name__ == "__main__":
3430
test_string = "Hello, World! 123"
3531
encoded = atbash(test_string)
3632
decoded = atbash(encoded)
37-
33+
3834
print(f"Original: {test_string}")
3935
print(f"Encoded: {encoded}")
4036
print(f"Decoded: {decoded}")

0 commit comments

Comments
 (0)