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 78 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 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
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}")
33 changes: 15 additions & 18 deletions ciphers/shuffled_shift_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"""
:return: passcode of the cipher object
"""
return "".join(self.__passcode)
return self.__passcode

def __neg_pos(self, iterlist: list[int]) -> list[int]:
"""
Expand All @@ -56,19 +56,19 @@
iterlist[i] *= -1
return iterlist

def __passcode_creator(self) -> list[str]:
def __passcode_creator(self) -> str:
"""
Creates a random password from the selection buffer of
1. uppercase letters of the English alphabet
2. lowercase letters of the English alphabet
3. digits from 0 to 9

:rtype: list
:rtype: str
:return: a password of a random length between 10 to 20
"""
choices = string.ascii_letters + string.digits
password = [random.choice(choices) for _ in range(random.randint(10, 20))]
return password
return "".join(password)

def __make_key_list(self) -> list[str]:
"""
Expand Down Expand Up @@ -104,15 +104,14 @@
temp_list: list[str] = []

# algorithm for creating a new shuffled list, keys_l, out of key_list_options
for i in key_list_options:
temp_list.extend(i)
for char in key_list_options:
temp_list.append(char)

# checking breakpoints at which to pivot temporary sublist and add it into
# keys_l
if i in breakpoints or i == key_list_options[-1]:
if char in breakpoints or char == key_list_options[-1]:
keys_l.extend(temp_list[::-1])
temp_list.clear()

# returning a shuffled keys_l to prevent brute force guessing of shift key
return keys_l

Expand All @@ -135,14 +134,13 @@

"""
decoded_message = ""
key_len = len(self.__key_list)

# decoding shift like Caesar cipher algorithm implementing negative shift or
# reverse shift or left shift
for i in encoded_message:
position = self.__key_list.index(i)
decoded_message += self.__key_list[
(position - self.__shift_key) % -len(self.__key_list)
]
for char in encoded_message:
position = self.__key_list.index(char)
decoded_message += self.__key_list[(position - self.__shift_key) % key_len]

return decoded_message

Expand All @@ -157,19 +155,18 @@

"""
encoded_message = ""
key_len = len(self.__key_list)

# encoding shift like Caesar cipher algorithm implementing positive shift or
# forward shift or right shift
for i in plaintext:
position = self.__key_list.index(i)
encoded_message += self.__key_list[
(position + self.__shift_key) % len(self.__key_list)
]
for char in plaintext:
position = self.__key_list.index(char)
encoded_message += self.__key_list[(position + self.__shift_key) % key_len]

return encoded_message


def test_end_to_end(msg: str = "Hello, this is a modified Caesar cipher") -> str:

Check failure on line 169 in ciphers/shuffled_shift_cipher.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (PT028)

ciphers/shuffled_shift_cipher.py:169:32: PT028 Test function parameter `msg` has default argument
"""
>>> test_end_to_end()
'Hello, this is a modified Caesar cipher'
Expand Down
Loading
Loading