@@ -8,10 +8,10 @@ def atbash_slow(sequence: str) -> str:
88 """
99 Atbash cipher implementation using ordinal values.
1010 Encodes/decodes by reversing the alphabet.
11-
11+
1212 >>> atbash_slow("ABCDEFG")
1313 'ZYXWVUT'
14-
14+
1515 >>> atbash_slow("aW;;123BX")
1616 'zD;;123YC'
1717 """
@@ -31,20 +31,20 @@ def atbash(sequence: str) -> str:
3131 """
3232 Optimized Atbash cipher implementation using string translation.
3333 More efficient than ordinal-based approach.
34-
34+
3535 >>> atbash("ABCDEFG")
3636 'ZYXWVUT'
37-
37+
3838 >>> atbash("aW;;123BX")
3939 'zD;;123YC'
4040 """
4141 # Create translation tables
4242 letters = string .ascii_letters
4343 reversed_letters = string .ascii_lowercase [::- 1 ] + string .ascii_uppercase [::- 1 ]
44-
44+
4545 # Create translation mapping
4646 translation = str .maketrans (letters , reversed_letters )
47-
47+
4848 # Apply translation to each character
4949 return sequence .translate (translation )
5050
@@ -55,14 +55,11 @@ def benchmark() -> None:
5555 Measures execution time using Python's timeit module.
5656 """
5757 print ("Running performance benchmarks..." )
58- setup = (
59- "from string import printable; "
60- "from __main__ import atbash, atbash_slow"
61- )
58+ setup = "from string import printable; from __main__ import atbash, atbash_slow"
6259 # Time the slow implementation
6360 slow_time = timeit ("atbash_slow(printable)" , setup = setup )
6461 print (f"> atbash_slow(): { slow_time :.6f} seconds" )
65-
62+
6663 # Time the optimized implementation
6764 fast_time = timeit ("atbash(printable)" , setup = setup )
6865 print (f"> atbash(): { fast_time :.6f} seconds" )
@@ -73,6 +70,6 @@ def benchmark() -> None:
7370 examples = ("ABCDEFGH" , "123GGjj" , "testStringtest" , "with space" )
7471 for example in examples :
7572 print (f"{ example } encrypted in atbash: { atbash (example )} " )
76-
73+
7774 # Run performance comparison
7875 benchmark ()
0 commit comments