Skip to content

Numerous significant improvements Beta #12811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 137 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
6891142
Add doctests for butterfly_pattern.py
lighting9999 Jun 28, 2025
22083ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2025
d9b07df
Update minimum_spanning_tree_kruskal2.py
lighting9999 Jun 28, 2025
97b33b2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2025
158128c
Update lru_cache.py
lighting9999 Jun 28, 2025
cecabe3
Update lru_cache.py
lighting9999 Jun 28, 2025
9d16049
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2025
2c17e86
Update lfu_cache.py
lighting9999 Jun 28, 2025
fcadabe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2025
1e71b72
Update lfu_cache.py
lighting9999 Jun 28, 2025
34da76f
Update stack_with_doubly_linked_list.py
lighting9999 Jun 28, 2025
ae755a6
Update skew_heap.py
lighting9999 Jun 28, 2025
fb07e07
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2025
be9ff5b
Update skew_heap.py
lighting9999 Jun 28, 2025
8abfbf1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2025
bd9bdf9
Update skew_heap.py
lighting9999 Jun 28, 2025
60cb936
Update skew_heap.py
lighting9999 Jun 28, 2025
3627416
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2025
d42704a
Update skew_heap.py
lighting9999 Jun 28, 2025
c78fbf7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2025
6e7bd44
Update skew_heap.py
lighting9999 Jun 28, 2025
24baa2b
Update test_digital_image_processing.py
lighting9999 Jun 29, 2025
127378f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
f3f0898
Update test_digital_image_processing.py
lighting9999 Jun 29, 2025
aa46117
Update test_digital_image_processing.py
lighting9999 Jun 29, 2025
fe0c1b6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
eed74bf
Update minimum_spanning_tree_prims2.py
lighting9999 Jun 29, 2025
8404a25
Update minimum_spanning_tree_prims2.py
lighting9999 Jun 29, 2025
a978c35
Update minimum_spanning_tree_prims2.py
lighting9999 Jun 29, 2025
a7e4603
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
dd16651
Update minimum_spanning_tree_prims2.py
lighting9999 Jun 29, 2025
3793d09
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
98e9282
Update matrix_class.py
lighting9999 Jun 29, 2025
54f2730
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
d5ab844
Update matrix_class.py
lighting9999 Jun 29, 2025
d1d1bcc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
a961455
Update matrix_class.py
lighting9999 Jun 29, 2025
8eace88
Update matrix_class.py
lighting9999 Jun 29, 2025
ac0dfd3
Update matrix_class.py
lighting9999 Jun 29, 2025
b863139
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
8166650
Update skew_heap.py
lighting9999 Jun 29, 2025
5508c20
Update skew_heap.py
lighting9999 Jun 29, 2025
f157d20
Update skew_heap.py
lighting9999 Jun 29, 2025
a24fd46
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
b4117d8
Update skew_heap.py
lighting9999 Jun 29, 2025
f0beacc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
6b07de6
Update skew_heap.py
lighting9999 Jun 29, 2025
0febfb5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
78fe5bb
Update skew_heap.py
lighting9999 Jun 29, 2025
283601d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
e013166
Update skew_heap.py
lighting9999 Jun 29, 2025
cf707b5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
b33f0b0
Update skew_heap.py
lighting9999 Jun 29, 2025
f0a4b6a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
4f0910c
Update skew_heap.py
lighting9999 Jun 29, 2025
180d8d5
Update skew_heap.py
lighting9999 Jun 29, 2025
c5693db
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
84ec049
Update skew_heap.py
lighting9999 Jun 29, 2025
1273319
Update skew_heap.py
lighting9999 Jun 29, 2025
a1a379c
Update minimum_spanning_tree_prims2.py
lighting9999 Jun 29, 2025
bf11752
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
4226641
fix sum_of_digits.py
lighting9999 Jun 29, 2025
a2b2951
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
3361c55
Update skew_heap.py
lighting9999 Jun 29, 2025
96ade05
Update skew_heap.py
lighting9999 Jun 29, 2025
bf93372
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
072a3d6
fix skew_heap.py
lighting9999 Jun 29, 2025
ed6be0a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
a35036f
fix l001 skew_heap.py
lighting9999 Jun 29, 2025
208adb1
Update skew_heap.py
lighting9999 Jun 29, 2025
06cb5d3
Update atbash.py
lighting9999 Jun 29, 2025
b1e0e3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
23772e7
Update pascal_triangle.py
lighting9999 Jun 29, 2025
adc0210
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
13d179b
Update pascal_triangle.py
lighting9999 Jun 29, 2025
21e2c45
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
4ad424a
Update shuffled_shift_cipher.py
lighting9999 Jun 29, 2025
c901985
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 29, 2025
7bbfdca
Update diff_views_of_binary_tree.py
lighting9999 Jul 4, 2025
9ab3e07
Update binary_search_tree.py
lighting9999 Jul 4, 2025
fef70fe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
33b0846
Delete data_structures/binary_tree/red_black_tree.py
lighting9999 Jul 4, 2025
bac8021
Add red_black_tree.py
lighting9999 Jul 4, 2025
e7f3e0a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
b6ed393
Update red_black_tree.py
lighting9999 Jul 4, 2025
00f7847
Update red_black_tree.py
lighting9999 Jul 4, 2025
52891a4
Update red_black_tree.py
lighting9999 Jul 4, 2025
99ea24e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
be02fd5
Update red_black_tree.py
lighting9999 Jul 4, 2025
11c74ec
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
76b34e8
Update red_black_tree.py
lighting9999 Jul 4, 2025
6c499c1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
fbd60e6
Update binary_search_tree.py
lighting9999 Jul 4, 2025
91cb294
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
de2c080
Update diff_views_of_binary_tree.py
lighting9999 Jul 4, 2025
1a25ad6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
e6ad021
Update avl_tree.py
lighting9999 Jul 4, 2025
28a57e8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
c7d9326
Update binary_search_tree.py
lighting9999 Jul 4, 2025
c8747af
Update red_black_tree.py
lighting9999 Jul 4, 2025
8cccecf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
71cba73
Update red_black_tree.py
lighting9999 Jul 4, 2025
4bb794d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
17ea820
Update red_black_tree.py
lighting9999 Jul 4, 2025
2762dbc
Update red_black_tree.py
lighting9999 Jul 4, 2025
03d7920
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
2adfd0b
Update avl_tree.py
lighting9999 Jul 4, 2025
7504e8d
Update binary_search_tree.py
lighting9999 Jul 4, 2025
0ea5a47
Update treap.py
lighting9999 Jul 4, 2025
44ce050
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
3bea2fa
Update local_weighted_learning.py
lighting9999 Jul 4, 2025
42ee813
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
b8116a1
Update sha256.py
lighting9999 Jul 4, 2025
26a0655
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
d73d647
Update mfcc.py
lighting9999 Jul 4, 2025
ae67342
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
9219789
Update hill_cipher.py
lighting9999 Jul 4, 2025
bea40aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
3f70e94
Update requirements.txt
lighting9999 Jul 4, 2025
2aa8610
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
4268f2e
Update hill_cipher.py
lighting9999 Jul 4, 2025
30d5ff2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
fa453bc
Update hill_cipher.py
lighting9999 Jul 4, 2025
a24b482
Update hill_cipher.py
lighting9999 Jul 4, 2025
fa54f68
Update pyproject.toml
lighting9999 Jul 4, 2025
d971725
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
6e83656
Update hill_cipher.py
lighting9999 Jul 4, 2025
5fa46b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
8185cc0
Update hill_cipher.py
lighting9999 Jul 4, 2025
a5cc16e
Update hill_cipher.py
lighting9999 Jul 4, 2025
77e427e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
b1d0d1f
Update hill_cipher.py
lighting9999 Jul 4, 2025
9ed3bbe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
5b090a3
Update hill_cipher.py
lighting9999 Jul 4, 2025
3c4e968
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
1755567
Update hill_cipher.py
lighting9999 Jul 4, 2025
c762326
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 23 additions & 41 deletions ciphers/atbash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,34 @@
import string


def atbash_slow(sequence: str) -> str:
def atbash(text: str) -> str:
"""
>>> atbash_slow("ABCDEFG")
'ZYXWVUT'
Encodes or decodes text using the Atbash cipher.

>>> atbash_slow("aW;;123BX")
'zD;;123YC'
"""
output = ""
for i in sequence:
extract = ord(i)
if 65 <= extract <= 90:
output += chr(155 - extract)
elif 97 <= extract <= 122:
output += chr(219 - extract)
else:
output += i
return output


def atbash(sequence: str) -> str:
"""
>>> atbash("ABCDEFG")
'ZYXWVUT'

>>> atbash("aW;;123BX")
'zD;;123YC'
"""
letters = string.ascii_letters
letters_reversed = string.ascii_lowercase[::-1] + string.ascii_uppercase[::-1]
return "".join(
letters_reversed[letters.index(c)] if c in letters else c for c in sequence
)
The Atbash cipher substitutes each letter with its mirror in the alphabet:
A -> Z, B -> Y, C -> X, ... Z -> A (case is preserved)
Non-alphabetic characters are left unchanged.

Args:
text: The input string to encode/decode

def benchmark() -> None:
"""Let's benchmark our functions side-by-side..."""
from timeit import timeit
Returns:
The transformed string
"""
# Create translation tables for uppercase and lowercase
lowercase_map = str.maketrans(string.ascii_lowercase, string.ascii_lowercase[::-1])
uppercase_map = str.maketrans(string.ascii_uppercase, string.ascii_uppercase[::-1])

print("Running performance benchmarks...")
setup = "from string import printable ; from __main__ import atbash, atbash_slow"
print(f"> atbash_slow(): {timeit('atbash_slow(printable)', setup=setup)} seconds")
print(f"> atbash(): {timeit('atbash(printable)', setup=setup)} seconds")
# Apply both translation mappings
return text.translate(lowercase_map).translate(uppercase_map)


# Example usage
if __name__ == "__main__":
for example in ("ABCDEFGH", "123GGjj", "testStringtest", "with space"):
print(f"{example} encrypted in atbash: {atbash(example)}")
benchmark()
test_string = "Hello, World! 123"
encoded = atbash(test_string)
decoded = atbash(encoded)

print(f"Original: {test_string}")
print(f"Encoded: {encoded}")
print(f"Decoded: {decoded}")
Loading
Loading