From 518f4e5b714fb1ebbe729020ee492fedc902d37a Mon Sep 17 00:00:00 2001 From: yanvoi Date: Sat, 8 Apr 2023 16:19:04 +0200 Subject: [PATCH 01/15] refactored the code --- ciphers/mixed_keyword_cypher.py | 79 +++++++++++++++++---------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/ciphers/mixed_keyword_cypher.py b/ciphers/mixed_keyword_cypher.py index 806004faa079..b8a57ac4c8b6 100644 --- a/ciphers/mixed_keyword_cypher.py +++ b/ciphers/mixed_keyword_cypher.py @@ -1,7 +1,9 @@ -def mixed_keyword(key: str = "college", pt: str = "UNIVERSITY") -> str: - """ +from string import ascii_uppercase + - For key:hello +def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY") -> str: + """ + For keyword: hello H E L O A B C D @@ -19,50 +21,49 @@ def mixed_keyword(key: str = "college", pt: str = "UNIVERSITY") -> str: 'Y': 'T', 'Z': 'Y'} 'XKJGUFMJST' """ - key = key.upper() - pt = pt.upper() - temp = [] - for i in key: - if i not in temp: - temp.append(i) - len_temp = len(temp) - # print(temp) - alpha = [] - modalpha = [] - for j in range(65, 91): - t = chr(j) - alpha.append(t) - if t not in temp: - temp.append(t) - # print(temp) - r = int(26 / 4) - # print(r) + keyword = keyword.upper() + plaintext = plaintext.upper() + + unique_chars = [] + for char in keyword: + if char not in unique_chars: + unique_chars.append(char) + + num_unique_chars_in_keyword = len(unique_chars) + + alphabet = list(ascii_uppercase) + # add the rest of the alphabet to the unique_chars list + for char in alphabet: + if char not in unique_chars: + unique_chars.append(char) + + rows = int(26 / 4) + # k is an index variable k = 0 - for _ in range(r): - s = [] - for _ in range(len_temp): - s.append(temp[k]) + modified_alphabet = [] + for _ in range(rows): + row = [] + for _ in range(num_unique_chars_in_keyword): + row.append(unique_chars[k]) if k >= 25: break k += 1 - modalpha.append(s) - # print(modalpha) - d = {} - j = 0 + modified_alphabet.append(row) + + mapping = {} k = 0 - for j in range(len_temp): - for m in modalpha: - if not len(m) - 1 >= j: + for j in range(num_unique_chars_in_keyword): + for row in modified_alphabet: + if not len(row) - 1 >= j: break - d[alpha[k]] = m[j] + mapping[alphabet[k]] = row[j] if not k < 25: break k += 1 - print(d) - cypher = "" - for i in pt: - cypher += d[i] - return cypher + + # create the encrypted text by mapping the plaintext to the modified alphabet + return "".join(mapping[char] for char in plaintext) -print(mixed_keyword("college", "UNIVERSITY")) +if __name__ == "__main__": + print(mixed_keyword("college", "UNIVERSITY")) From 16c9268fde23e81520c6564984e1620036f63ce6 Mon Sep 17 00:00:00 2001 From: yanvoi Date: Sun, 9 Apr 2023 11:57:53 +0200 Subject: [PATCH 02/15] the code will now pass the test --- ciphers/mixed_keyword_cypher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ciphers/mixed_keyword_cypher.py b/ciphers/mixed_keyword_cypher.py index b8a57ac4c8b6..9dd993990100 100644 --- a/ciphers/mixed_keyword_cypher.py +++ b/ciphers/mixed_keyword_cypher.py @@ -61,6 +61,7 @@ def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY") -> st break k += 1 + print(mapping) # create the encrypted text by mapping the plaintext to the modified alphabet return "".join(mapping[char] for char in plaintext) From a6d64ffb0bc42f360c2c8abcd3f04087af5efb74 Mon Sep 17 00:00:00 2001 From: yanvoi Date: Mon, 10 Apr 2023 09:11:16 +0200 Subject: [PATCH 03/15] looked more into it and fixed the logic --- ciphers/mixed_keyword_cypher.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/ciphers/mixed_keyword_cypher.py b/ciphers/mixed_keyword_cypher.py index 9dd993990100..775769533ddf 100644 --- a/ciphers/mixed_keyword_cypher.py +++ b/ciphers/mixed_keyword_cypher.py @@ -23,7 +23,9 @@ def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY") -> st """ keyword = keyword.upper() plaintext = plaintext.upper() + alphabet = list(ascii_uppercase) + # create a list of unique characters in the keyword unique_chars = [] for char in keyword: if char not in unique_chars: @@ -31,35 +33,41 @@ def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY") -> st num_unique_chars_in_keyword = len(unique_chars) - alphabet = list(ascii_uppercase) - # add the rest of the alphabet to the unique_chars list + # add any uppercase letters from the alphabet + # that are not in the keyword to the unique_chars list. for char in alphabet: if char not in unique_chars: unique_chars.append(char) - rows = int(26 / 4) + rows = (26 // num_unique_chars_in_keyword) + 1 # k is an index variable k = 0 + # create a modified version of the alphabet by dividing it into rows number of rows + # and mapping the letters in the unique_chars list to the rows modified_alphabet = [] for _ in range(rows): row = [] for _ in range(num_unique_chars_in_keyword): row.append(unique_chars[k]) - if k >= 25: - break k += 1 + # break out of the loop if we have reached the end of the alphabet + if k >= 26: + break modified_alphabet.append(row) mapping = {} k = 0 for j in range(num_unique_chars_in_keyword): for row in modified_alphabet: - if not len(row) - 1 >= j: + # if current row is too short, break out of loop + if len(row) <= j: break + + # map current letter to letter in modified alphabet mapping[alphabet[k]] = row[j] - if not k < 25: - break k += 1 + if k >= 26: + break print(mapping) # create the encrypted text by mapping the plaintext to the modified alphabet From 642ccc39ab853334b0bb4101c5d76be554fa7281 Mon Sep 17 00:00:00 2001 From: yanvoi Date: Mon, 10 Apr 2023 10:35:20 +0200 Subject: [PATCH 04/15] made the code easier to read, added comments and fixed the logic --- ciphers/mixed_keyword_cypher.py | 47 +++++++++++++-------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/ciphers/mixed_keyword_cypher.py b/ciphers/mixed_keyword_cypher.py index 775769533ddf..9cbe30dd03bf 100644 --- a/ciphers/mixed_keyword_cypher.py +++ b/ciphers/mixed_keyword_cypher.py @@ -30,43 +30,34 @@ def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY") -> st for char in keyword: if char not in unique_chars: unique_chars.append(char) - + # the number of those unique characters will determine the number of rows num_unique_chars_in_keyword = len(unique_chars) - # add any uppercase letters from the alphabet - # that are not in the keyword to the unique_chars list. - for char in alphabet: - if char not in unique_chars: - unique_chars.append(char) + # create a shifted version of the alphabet + shifted_alphabet = unique_chars + [ + char for char in alphabet if char not in unique_chars + ] - rows = (26 // num_unique_chars_in_keyword) + 1 - # k is an index variable - k = 0 - # create a modified version of the alphabet by dividing it into rows number of rows - # and mapping the letters in the unique_chars list to the rows - modified_alphabet = [] - for _ in range(rows): - row = [] - for _ in range(num_unique_chars_in_keyword): - row.append(unique_chars[k]) - k += 1 - # break out of the loop if we have reached the end of the alphabet - if k >= 26: - break - modified_alphabet.append(row) + # create a modified alphabet by splitting the shifted alphabet into rows + modified_alphabet = [ + shifted_alphabet[k : k + num_unique_chars_in_keyword] + for k in range(0, 26, num_unique_chars_in_keyword) + ] + # map the alphabet characters to the modified alphabet characters + # going 'vertically' through the modified alphabet - consider columns first mapping = {} - k = 0 - for j in range(num_unique_chars_in_keyword): + letter_index = 0 + for column in range(num_unique_chars_in_keyword): for row in modified_alphabet: - # if current row is too short, break out of loop - if len(row) <= j: + # if current row (the last one) is too short, break out of loop + if len(row) <= column: break # map current letter to letter in modified alphabet - mapping[alphabet[k]] = row[j] - k += 1 - if k >= 26: + mapping[alphabet[letter_index]] = row[column] + letter_index += 1 + if letter_index >= 26: break print(mapping) From 3520c166ecd1f48f9bfa36e6c73e76ca70f3d8a7 Mon Sep 17 00:00:00 2001 From: yanvoi Date: Mon, 10 Apr 2023 12:16:47 +0200 Subject: [PATCH 05/15] got rid of redundant code + plaintext can contain chars that are not in the alphabet --- ciphers/mixed_keyword_cypher.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ciphers/mixed_keyword_cypher.py b/ciphers/mixed_keyword_cypher.py index 9cbe30dd03bf..163300af7d17 100644 --- a/ciphers/mixed_keyword_cypher.py +++ b/ciphers/mixed_keyword_cypher.py @@ -24,11 +24,12 @@ def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY") -> st keyword = keyword.upper() plaintext = plaintext.upper() alphabet = list(ascii_uppercase) + alphabet_set = set(alphabet) # create a list of unique characters in the keyword unique_chars = [] for char in keyword: - if char not in unique_chars: + if char in alphabet_set and char not in unique_chars: unique_chars.append(char) # the number of those unique characters will determine the number of rows num_unique_chars_in_keyword = len(unique_chars) @@ -57,12 +58,10 @@ def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY") -> st # map current letter to letter in modified alphabet mapping[alphabet[letter_index]] = row[column] letter_index += 1 - if letter_index >= 26: - break print(mapping) # create the encrypted text by mapping the plaintext to the modified alphabet - return "".join(mapping[char] for char in plaintext) + return "".join(mapping[char] if char in mapping else char for char in plaintext) if __name__ == "__main__": From 3a099f50503015106dc865e349f1c71e9a9c8c78 Mon Sep 17 00:00:00 2001 From: yanvoi Date: Fri, 12 May 2023 09:04:04 +0200 Subject: [PATCH 06/15] fixed the reduntant conversion of ascii_uppercase to a list --- ciphers/mixed_keyword_cypher.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ciphers/mixed_keyword_cypher.py b/ciphers/mixed_keyword_cypher.py index 163300af7d17..5cb019e83f14 100644 --- a/ciphers/mixed_keyword_cypher.py +++ b/ciphers/mixed_keyword_cypher.py @@ -1,7 +1,7 @@ from string import ascii_uppercase -def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY") -> str: +def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY", alphabet: str = ascii_uppercase) -> str: """ For keyword: hello @@ -23,7 +23,6 @@ def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY") -> st """ keyword = keyword.upper() plaintext = plaintext.upper() - alphabet = list(ascii_uppercase) alphabet_set = set(alphabet) # create a list of unique characters in the keyword @@ -65,4 +64,4 @@ def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY") -> st if __name__ == "__main__": - print(mixed_keyword("college", "UNIVERSITY")) + print(mixed_keyword("college", "UNIVERSITY", ascii_uppercase)) From 738f193280ed11dec46000ed5e1a28decb478679 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 12 May 2023 07:06:45 +0000 Subject: [PATCH 07/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ciphers/mixed_keyword_cypher.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ciphers/mixed_keyword_cypher.py b/ciphers/mixed_keyword_cypher.py index 5cb019e83f14..9f267e0ace6f 100644 --- a/ciphers/mixed_keyword_cypher.py +++ b/ciphers/mixed_keyword_cypher.py @@ -1,7 +1,11 @@ from string import ascii_uppercase -def mixed_keyword(keyword: str = "college", plaintext: str = "UNIVERSITY", alphabet: str = ascii_uppercase) -> str: +def mixed_keyword( + keyword: str = "college", + plaintext: str = "UNIVERSITY", + alphabet: str = ascii_uppercase, +) -> str: """ For keyword: hello From b284ab15493e00e493b2ea02e97ebb5b3ac037eb Mon Sep 17 00:00:00 2001 From: yanvoi Date: Fri, 12 May 2023 11:50:58 +0200 Subject: [PATCH 08/15] keyword and plaintext won't have default values --- ciphers/mixed_keyword_cypher.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ciphers/mixed_keyword_cypher.py b/ciphers/mixed_keyword_cypher.py index 9f267e0ace6f..0009cafb2f2a 100644 --- a/ciphers/mixed_keyword_cypher.py +++ b/ciphers/mixed_keyword_cypher.py @@ -1,11 +1,7 @@ from string import ascii_uppercase -def mixed_keyword( - keyword: str = "college", - plaintext: str = "UNIVERSITY", - alphabet: str = ascii_uppercase, -) -> str: +def mixed_keyword(keyword: str, plaintext: str, alphabet: str = ascii_uppercase) -> str: """ For keyword: hello @@ -68,4 +64,5 @@ def mixed_keyword( if __name__ == "__main__": + # example use print(mixed_keyword("college", "UNIVERSITY", ascii_uppercase)) From ad436cea7d9a4082345c4c1520c1916d4fbf2191 Mon Sep 17 00:00:00 2001 From: yanvoi Date: Fri, 12 May 2023 14:50:47 +0200 Subject: [PATCH 09/15] ran the ruff command --- ciphers/rsa_cipher.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ciphers/rsa_cipher.py b/ciphers/rsa_cipher.py index de26992f5eeb..90342b0aeae7 100644 --- a/ciphers/rsa_cipher.py +++ b/ciphers/rsa_cipher.py @@ -76,10 +76,9 @@ def encrypt_and_write_to_file( key_size, n, e = read_key_file(key_filename) if key_size < block_size * 8: sys.exit( - "ERROR: Block size is %s bits and key size is %s bits. The RSA cipher " + "ERROR: Block size is {} bits and key size is {} bits. The RSA cipher " "requires the block size to be equal to or greater than the key size. " - "Either decrease the block size or use different keys." - % (block_size * 8, key_size) + "Either decrease the block size or use different keys.".format(block_size * 8, key_size) ) encrypted_blocks = [str(i) for i in encrypt_message(message, (n, e), block_size)] @@ -101,10 +100,9 @@ def read_from_file_and_decrypt(message_filename: str, key_filename: str) -> str: if key_size < block_size * 8: sys.exit( - "ERROR: Block size is %s bits and key size is %s bits. The RSA cipher " + "ERROR: Block size is {} bits and key size is {} bits. The RSA cipher " "requires the block size to be equal to or greater than the key size. " - "Did you specify the correct key file and encrypted file?" - % (block_size * 8, key_size) + "Did you specify the correct key file and encrypted file?".format(block_size * 8, key_size) ) encrypted_blocks = [] From be6f043284bcd5f16886ce73481a342d1fb5d007 Mon Sep 17 00:00:00 2001 From: Rohan Anand <96521078+rohan472000@users.noreply.github.com> Date: Mon, 24 Apr 2023 10:58:30 +0530 Subject: [PATCH 10/15] Update linear_discriminant_analysis.py and rsa_cipher.py (#8680) * Update rsa_cipher.py by replacing %s with {} * Update rsa_cipher.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update linear_discriminant_analysis.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update linear_discriminant_analysis.py * Update linear_discriminant_analysis.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update linear_discriminant_analysis.py * Update linear_discriminant_analysis.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update linear_discriminant_analysis.py * Update machine_learning/linear_discriminant_analysis.py Co-authored-by: Christian Clauss * Update linear_discriminant_analysis.py * updated --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss --- ciphers/rsa_cipher.py | 1 + machine_learning/linear_discriminant_analysis.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ciphers/rsa_cipher.py b/ciphers/rsa_cipher.py index 9c41cdc5d472..2c5273190c01 100644 --- a/ciphers/rsa_cipher.py +++ b/ciphers/rsa_cipher.py @@ -76,6 +76,7 @@ def encrypt_and_write_to_file( key_size, n, e = read_key_file(key_filename) if key_size < block_size * 8: sys.exit( + "ERROR: Block size is {} bits and key size is {} bits. The RSA cipher " "ERROR: Block size is {} bits and key size is {} bits. The RSA cipher " "requires the block size to be equal to or greater than the key size. " "Either decrease the block size or use different keys.".format( diff --git a/machine_learning/linear_discriminant_analysis.py b/machine_learning/linear_discriminant_analysis.py index 88c047157893..c0a477be10c7 100644 --- a/machine_learning/linear_discriminant_analysis.py +++ b/machine_learning/linear_discriminant_analysis.py @@ -399,7 +399,7 @@ def main(): if input("Press any key to restart or 'q' for quit: ").strip().lower() == "q": print("\n" + "GoodBye!".center(100, "-") + "\n") break - system("cls" if name == "nt" else "clear") # noqa: S605 + system("clear" if name == "posix" else "cls") # noqa: S605 if __name__ == "__main__": From 33b34c4a1c1620bcc5cff195b2bab4eaba9d2550 Mon Sep 17 00:00:00 2001 From: yanvoi Date: Wed, 17 May 2023 06:49:05 +0200 Subject: [PATCH 11/15] fixed some difficulties --- ciphers/rsa_cipher.py | 1 - machine_learning/linear_discriminant_analysis.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ciphers/rsa_cipher.py b/ciphers/rsa_cipher.py index 2c5273190c01..9c41cdc5d472 100644 --- a/ciphers/rsa_cipher.py +++ b/ciphers/rsa_cipher.py @@ -76,7 +76,6 @@ def encrypt_and_write_to_file( key_size, n, e = read_key_file(key_filename) if key_size < block_size * 8: sys.exit( - "ERROR: Block size is {} bits and key size is {} bits. The RSA cipher " "ERROR: Block size is {} bits and key size is {} bits. The RSA cipher " "requires the block size to be equal to or greater than the key size. " "Either decrease the block size or use different keys.".format( diff --git a/machine_learning/linear_discriminant_analysis.py b/machine_learning/linear_discriminant_analysis.py index c0a477be10c7..3837d48c02d5 100644 --- a/machine_learning/linear_discriminant_analysis.py +++ b/machine_learning/linear_discriminant_analysis.py @@ -399,7 +399,7 @@ def main(): if input("Press any key to restart or 'q' for quit: ").strip().lower() == "q": print("\n" + "GoodBye!".center(100, "-") + "\n") break - system("clear" if name == "posix" else "cls") # noqa: S605 + system("cls" if name == "nt" else "clear") # noqa: S605 if __name__ == "__main__": From 66e28eeaf60fb16a79d0c27173d1cfdedffba0d7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 17 May 2023 04:50:01 +0000 Subject: [PATCH 12/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- machine_learning/linear_discriminant_analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/machine_learning/linear_discriminant_analysis.py b/machine_learning/linear_discriminant_analysis.py index 3837d48c02d5..88c047157893 100644 --- a/machine_learning/linear_discriminant_analysis.py +++ b/machine_learning/linear_discriminant_analysis.py @@ -399,7 +399,7 @@ def main(): if input("Press any key to restart or 'q' for quit: ").strip().lower() == "q": print("\n" + "GoodBye!".center(100, "-") + "\n") break - system("cls" if name == "nt" else "clear") # noqa: S605 + system("cls" if name == "nt" else "clear") # noqa: S605 if __name__ == "__main__": From 0bf2ed28a30f764c82e43d5ed328883f4a2dd77f Mon Sep 17 00:00:00 2001 From: yanvoi Date: Thu, 8 Jun 2023 08:12:45 +0200 Subject: [PATCH 13/15] added comments, made printing mapping optional, added 1 test --- ciphers/mixed_keyword_cypher.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ciphers/mixed_keyword_cypher.py b/ciphers/mixed_keyword_cypher.py index 0009cafb2f2a..ee26f0a55a42 100644 --- a/ciphers/mixed_keyword_cypher.py +++ b/ciphers/mixed_keyword_cypher.py @@ -1,7 +1,9 @@ from string import ascii_uppercase -def mixed_keyword(keyword: str, plaintext: str, alphabet: str = ascii_uppercase) -> str: +def mixed_keyword( + keyword: str, plaintext: str, verbose: bool = True, alphabet: str = ascii_uppercase +) -> str: """ For keyword: hello @@ -14,18 +16,22 @@ def mixed_keyword(keyword: str, plaintext: str, alphabet: str = ascii_uppercase) Y Z and map vertically - >>> mixed_keyword("college", "UNIVERSITY") # doctest: +NORMALIZE_WHITESPACE + >>> mixed_keyword("college", "UNIVERSITY", True) # doctest: +NORMALIZE_WHITESPACE {'A': 'C', 'B': 'A', 'C': 'I', 'D': 'P', 'E': 'U', 'F': 'Z', 'G': 'O', 'H': 'B', 'I': 'J', 'J': 'Q', 'K': 'V', 'L': 'L', 'M': 'D', 'N': 'K', 'O': 'R', 'P': 'W', 'Q': 'E', 'R': 'F', 'S': 'M', 'T': 'S', 'U': 'X', 'V': 'G', 'W': 'H', 'X': 'N', 'Y': 'T', 'Z': 'Y'} 'XKJGUFMJST' + + >>> mixed_keyword("college", "UNIVERSITY", False) # doctest: +NORMALIZE_WHITESPACE + 'XKJGUFMJST' """ keyword = keyword.upper() plaintext = plaintext.upper() alphabet_set = set(alphabet) # create a list of unique characters in the keyword + # their order matters, it determines how we will map plaintext characters to the ciphertext unique_chars = [] for char in keyword: if char in alphabet_set and char not in unique_chars: @@ -58,11 +64,12 @@ def mixed_keyword(keyword: str, plaintext: str, alphabet: str = ascii_uppercase) mapping[alphabet[letter_index]] = row[column] letter_index += 1 - print(mapping) + if verbose: + print(mapping) # create the encrypted text by mapping the plaintext to the modified alphabet return "".join(mapping[char] if char in mapping else char for char in plaintext) if __name__ == "__main__": # example use - print(mixed_keyword("college", "UNIVERSITY", ascii_uppercase)) + print(mixed_keyword("college", "UNIVERSITY")) From 05d02838001af47a6cdd2363c25aba6519ab8b2d Mon Sep 17 00:00:00 2001 From: yanvoi Date: Thu, 8 Jun 2023 08:16:31 +0200 Subject: [PATCH 14/15] shortened the line that was too long --- ciphers/mixed_keyword_cypher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/mixed_keyword_cypher.py b/ciphers/mixed_keyword_cypher.py index ee26f0a55a42..bc2f099530ef 100644 --- a/ciphers/mixed_keyword_cypher.py +++ b/ciphers/mixed_keyword_cypher.py @@ -30,8 +30,8 @@ def mixed_keyword( plaintext = plaintext.upper() alphabet_set = set(alphabet) - # create a list of unique characters in the keyword - # their order matters, it determines how we will map plaintext characters to the ciphertext + # create a list of unique characters in the keyword - their order matters + # it determines how we will map plaintext characters to the ciphertext unique_chars = [] for char in keyword: if char in alphabet_set and char not in unique_chars: From ad8c99fb7aa0b820f08c8ba6f82f56527adb3398 Mon Sep 17 00:00:00 2001 From: Jan Wojciechowski <96974442+yanvoi@users.noreply.github.com> Date: Fri, 9 Jun 2023 09:28:47 +0200 Subject: [PATCH 15/15] Update ciphers/mixed_keyword_cypher.py Co-authored-by: Tianyi Zheng --- ciphers/mixed_keyword_cypher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/mixed_keyword_cypher.py b/ciphers/mixed_keyword_cypher.py index bc2f099530ef..b984808fced6 100644 --- a/ciphers/mixed_keyword_cypher.py +++ b/ciphers/mixed_keyword_cypher.py @@ -2,7 +2,7 @@ def mixed_keyword( - keyword: str, plaintext: str, verbose: bool = True, alphabet: str = ascii_uppercase + keyword: str, plaintext: str, verbose: bool = False, alphabet: str = ascii_uppercase ) -> str: """ For keyword: hello