From 8ecf4981eef52529fe32ee117060ae85f1acf54e Mon Sep 17 00:00:00 2001 From: Victor Rodrigues da Silva <63797831+VictorRS27@users.noreply.github.com> Date: Wed, 14 Dec 2022 13:33:44 -0300 Subject: [PATCH 01/11] Add autoclave cipher --- ciphers/autoclave.py | 111 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 ciphers/autoclave.py diff --git a/ciphers/autoclave.py b/ciphers/autoclave.py new file mode 100644 index 000000000000..24f8bce15c28 --- /dev/null +++ b/ciphers/autoclave.py @@ -0,0 +1,111 @@ +def encrypt(plaintext, key) -> str: + """ + Function that encrypt a given plaintext (string) + and key (string), returning the encrypted ciphertext + + @params + plaintext - a normal text to be encrypted (string) + key - a small text or word to start the replacing (sFtring) + + @return + A string with the ciphertext + + >>> encrypt("hello world", "coffee") + 'jsqqs avvwo' + """ + if type(plaintext) != str: + raise TypeError("plaintext must be a string") + if type(key) != str: + raise TypeError("key must be a string") + + if plaintext == "": + raise ValueError("plaintext is empty") + if key == "": + raise ValueError("key is empty") + + key = key + plaintext + plaintext = plaintext.lower() + key = key.lower() + plaintext_iterator = 0 + key_iterator = 0 + ciphertext = "" + while plaintext_iterator < len(plaintext): + if ( + ord(plaintext[plaintext_iterator]) < 97 + or ord(plaintext[plaintext_iterator]) > 122 + ): + ciphertext += plaintext[plaintext_iterator] + plaintext_iterator += 1 + elif ord(key[key_iterator]) < 97 or ord(key[key_iterator]) > 122: + key_iterator += 1 + else: + ciphertext += chr( + ( + (ord(plaintext[plaintext_iterator]) - 97 + ord(key[key_iterator])) + - 97 + ) + % 26 + + 97 + ) + key_iterator += 1 + plaintext_iterator += 1 + return ciphertext + + +def decrypt(ciphertext: str, key: str) -> str: + """ + Function that decrypt a given ciphertext (string) + and key (string), returning the decrypted ciphertext + + @params + ciphertext - a normal text to be decrypted (string) + key - a small text or word used to encrypt (string) + + @return + A string with the ciphertext + + >>> decrypt("jsqqs avvwo", "coffee") + 'hello world' + """ + if type(ciphertext) != str: + raise TypeError("ciphertext must be a string") + if type(key) != str: + raise TypeError("key must be a string") + + if ciphertext == "": + raise ValueError("ciphertext is empty") + if key == "": + raise ValueError("key is empty") + ciphertext_iterator = 0 + key_iterator = 0 + plaintext = "" + while ciphertext_iterator < len(ciphertext): + if ( + ord(ciphertext[ciphertext_iterator]) < 97 + or ord(ciphertext[ciphertext_iterator]) > 122 + ): + plaintext += ciphertext[ciphertext_iterator] + else: + plaintext += chr( + (ord(ciphertext[ciphertext_iterator]) - ord(key[key_iterator])) % 26 + + 97 + ) + key += chr( + (ord(ciphertext[ciphertext_iterator]) - ord(key[key_iterator])) % 26 + + 97 + ) + key_iterator += 1 + ciphertext_iterator += 1 + return plaintext + + +operation = int(input("Type 1 to encrypt or 2 to decrypt:")) +if operation == 1: + plaintext = str(input("Typeplaintext to be encrypted:\n")) + key = str(input("Type the key:\n")) + print(encrypt(plaintext, key)) +elif operation == 2: + ciphertext = str(input("Type the ciphertext to be decrypted:\n")) + key = str(input("Type the key:\n")) + print(decrypt(ciphertext, key)) +decrypt("jsqqs avvwo", "coffee") From 3ebfbd72b9b6696d738bd71eb4571064e9ace7b5 Mon Sep 17 00:00:00 2001 From: Victor Rodrigues da Silva <63797831+VictorRS27@users.noreply.github.com> Date: Sun, 18 Dec 2022 16:56:08 -0300 Subject: [PATCH 02/11] Update autoclave with the given suggestions --- ciphers/autoclave.py | 96 ++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 40 deletions(-) diff --git a/ciphers/autoclave.py b/ciphers/autoclave.py index 24f8bce15c28..c2e2de3607d7 100644 --- a/ciphers/autoclave.py +++ b/ciphers/autoclave.py @@ -1,29 +1,39 @@ -def encrypt(plaintext, key) -> str: +""" +https://en.wikipedia.org/wiki/Autokey_cipher +> An autokey cipher (also known as the autoclave cipher) is a cipher that incorporates the message +(the plaintext into the key. +The key is generated from the message in some automated fashion, sometimes by selecting certain letters from the text or, more commonly, +by adding a short primer key to the front of the message. +""" + +def encrypt(plaintext: str, key: str) -> str: """ Function that encrypt a given plaintext (string) - and key (string), returning the encrypted ciphertext - - @params - plaintext - a normal text to be encrypted (string) - key - a small text or word to start the replacing (sFtring) - - @return - A string with the ciphertext - + and key (string), returning the encrypted cyphertext >>> encrypt("hello world", "coffee") 'jsqqs avvwo' + >>> encrypt("coffee is good as python", "TheAlgorithms") + 'vvjfpk wj ohvp su ddylsv' + >>> encrypt("coffee is good as python", 2) + Traceback (most recent call last): + ... + TypeError: key must be a string + >>> encrypt("", "TheAlgorithms") + Traceback (most recent call last): + ... + ValueError: plaintext is empty """ - if type(plaintext) != str: + if not isinstance(plaintext, str): raise TypeError("plaintext must be a string") - if type(key) != str: + if not isinstance(key, str): raise TypeError("key must be a string") - if plaintext == "": + if not plaintext: raise ValueError("plaintext is empty") - if key == "": + if not key: raise ValueError("key is empty") - key = key + plaintext + key += plaintext plaintext = plaintext.lower() key = key.lower() plaintext_iterator = 0 @@ -54,28 +64,32 @@ def encrypt(plaintext, key) -> str: def decrypt(ciphertext: str, key: str) -> str: """ - Function that decrypt a given ciphertext (string) - and key (string), returning the decrypted ciphertext - - @params - ciphertext - a normal text to be decrypted (string) - key - a small text or word used to encrypt (string) - - @return - A string with the ciphertext - + Function that decrypt a given cyphertext (string) + and key (string), returning the decrypted cyphertext >>> decrypt("jsqqs avvwo", "coffee") 'hello world' + >>> decrypt("vvjfpk wj ohvp su ddylsv", "TheAlgorithms") + 'coffee is good as python' + >>> decrypt("vvjfpk wj ohvp su ddylsv", "") + Traceback (most recent call last): + ... + ValueError: key is empty + >>> decrypt(527.26, "TheAlgorithms") + Traceback (most recent call last): + ... + TypeError: ciphertext must be a string """ - if type(ciphertext) != str: + if not isinstance(ciphertext, str): raise TypeError("ciphertext must be a string") - if type(key) != str: + if not isinstance(key, str): raise TypeError("key must be a string") - if ciphertext == "": + if not ciphertext: raise ValueError("ciphertext is empty") - if key == "": + if not key: raise ValueError("key is empty") + + key = key.lower() ciphertext_iterator = 0 key_iterator = 0 plaintext = "" @@ -98,14 +112,16 @@ def decrypt(ciphertext: str, key: str) -> str: ciphertext_iterator += 1 return plaintext - -operation = int(input("Type 1 to encrypt or 2 to decrypt:")) -if operation == 1: - plaintext = str(input("Typeplaintext to be encrypted:\n")) - key = str(input("Type the key:\n")) - print(encrypt(plaintext, key)) -elif operation == 2: - ciphertext = str(input("Type the ciphertext to be decrypted:\n")) - key = str(input("Type the key:\n")) - print(decrypt(ciphertext, key)) -decrypt("jsqqs avvwo", "coffee") +if __name__ == "__main__": + import doctest + doctest.testmod() + operation = int(input("Type 1 to encrypt or 2 to decrypt:")) + if operation == 1: + plaintext = str(input("Typeplaintext to be encrypted:\n")) + key = str(input("Type the key:\n")) + print(encrypt(plaintext, key)) + elif operation == 2: + ciphertext = str(input("Type the ciphertext to be decrypted:\n")) + key = str(input("Type the key:\n")) + print(decrypt(ciphertext, key)) + decrypt("jsqqs avvwo", "coffee") From 820d22a555e774d6f232e7a70a2fc422933d9413 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 18 Dec 2022 19:58:03 +0000 Subject: [PATCH 03/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ciphers/autoclave.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ciphers/autoclave.py b/ciphers/autoclave.py index c2e2de3607d7..fe19d5a6091c 100644 --- a/ciphers/autoclave.py +++ b/ciphers/autoclave.py @@ -1,11 +1,12 @@ """ https://en.wikipedia.org/wiki/Autokey_cipher > An autokey cipher (also known as the autoclave cipher) is a cipher that incorporates the message -(the plaintext into the key. +(the plaintext into the key. The key is generated from the message in some automated fashion, sometimes by selecting certain letters from the text or, more commonly, by adding a short primer key to the front of the message. """ + def encrypt(plaintext: str, key: str) -> str: """ Function that encrypt a given plaintext (string) @@ -88,7 +89,7 @@ def decrypt(ciphertext: str, key: str) -> str: raise ValueError("ciphertext is empty") if not key: raise ValueError("key is empty") - + key = key.lower() ciphertext_iterator = 0 key_iterator = 0 @@ -112,8 +113,10 @@ def decrypt(ciphertext: str, key: str) -> str: ciphertext_iterator += 1 return plaintext + if __name__ == "__main__": import doctest + doctest.testmod() operation = int(input("Type 1 to encrypt or 2 to decrypt:")) if operation == 1: From 4c4f557d305e0cc994675be010a93acaa0e5237e Mon Sep 17 00:00:00 2001 From: Victor Rodrigues da Silva <63797831+VictorRS27@users.noreply.github.com> Date: Sun, 18 Dec 2022 18:33:35 -0300 Subject: [PATCH 04/11] Fixing errors --- ciphers/autoclave.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ciphers/autoclave.py b/ciphers/autoclave.py index fe19d5a6091c..9c6c66e4e651 100644 --- a/ciphers/autoclave.py +++ b/ciphers/autoclave.py @@ -1,8 +1,9 @@ """ https://en.wikipedia.org/wiki/Autokey_cipher -> An autokey cipher (also known as the autoclave cipher) is a cipher that incorporates the message -(the plaintext into the key. -The key is generated from the message in some automated fashion, sometimes by selecting certain letters from the text or, more commonly, +> An autokey cipher (also known as the autoclave cipher) is a cipher that +incorporates the message (the plaintext) into the key. +The key is generated from the message in some automated fashion, +sometimes by selecting certain letters from the text or, more commonly, by adding a short primer key to the front of the message. """ @@ -10,7 +11,7 @@ def encrypt(plaintext: str, key: str) -> str: """ Function that encrypt a given plaintext (string) - and key (string), returning the encrypted cyphertext + and key (string), returning the encrypted ciphertext >>> encrypt("hello world", "coffee") 'jsqqs avvwo' >>> encrypt("coffee is good as python", "TheAlgorithms") @@ -65,8 +66,8 @@ def encrypt(plaintext: str, key: str) -> str: def decrypt(ciphertext: str, key: str) -> str: """ - Function that decrypt a given cyphertext (string) - and key (string), returning the decrypted cyphertext + Function that decrypt a given ciphertext (string) + and key (string), returning the decrypted ciphertext >>> decrypt("jsqqs avvwo", "coffee") 'hello world' >>> decrypt("vvjfpk wj ohvp su ddylsv", "TheAlgorithms") From 3a2e91df6dad89337d863e7787d08dfb53dce338 Mon Sep 17 00:00:00 2001 From: Victor Rodrigues da Silva <63797831+VictorRS27@users.noreply.github.com> Date: Sun, 18 Dec 2022 18:53:09 -0300 Subject: [PATCH 05/11] Another fixes --- ciphers/autoclave.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/ciphers/autoclave.py b/ciphers/autoclave.py index 9c6c66e4e651..67b35dcfccd6 100644 --- a/ciphers/autoclave.py +++ b/ciphers/autoclave.py @@ -116,9 +116,6 @@ def decrypt(ciphertext: str, key: str) -> str: if __name__ == "__main__": - import doctest - - doctest.testmod() operation = int(input("Type 1 to encrypt or 2 to decrypt:")) if operation == 1: plaintext = str(input("Typeplaintext to be encrypted:\n")) From b72a63664dc9353476d7fb7298ce534294fc55fc Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 18 Dec 2022 23:04:38 +0100 Subject: [PATCH 06/11] Update and rename autoclave.py to autokey.py --- ciphers/{autoclave.py => autokey.py} | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) rename ciphers/{autoclave.py => autokey.py} (87%) diff --git a/ciphers/autoclave.py b/ciphers/autokey.py similarity index 87% rename from ciphers/autoclave.py rename to ciphers/autokey.py index 67b35dcfccd6..8683e6d37001 100644 --- a/ciphers/autoclave.py +++ b/ciphers/autokey.py @@ -1,6 +1,6 @@ """ https://en.wikipedia.org/wiki/Autokey_cipher -> An autokey cipher (also known as the autoclave cipher) is a cipher that +An autokey cipher (also known as the autoclave cipher) is a cipher that incorporates the message (the plaintext) into the key. The key is generated from the message in some automated fashion, sometimes by selecting certain letters from the text or, more commonly, @@ -10,8 +10,8 @@ def encrypt(plaintext: str, key: str) -> str: """ - Function that encrypt a given plaintext (string) - and key (string), returning the encrypted ciphertext + Encrypt a given plaintext (string) and key (string), returning the + encrypted ciphertext. >>> encrypt("hello world", "coffee") 'jsqqs avvwo' >>> encrypt("coffee is good as python", "TheAlgorithms") @@ -66,8 +66,8 @@ def encrypt(plaintext: str, key: str) -> str: def decrypt(ciphertext: str, key: str) -> str: """ - Function that decrypt a given ciphertext (string) - and key (string), returning the decrypted ciphertext + Decrypt a given ciphertext (string) and key (string), returning the decrypted + ciphertext. >>> decrypt("jsqqs avvwo", "coffee") 'hello world' >>> decrypt("vvjfpk wj ohvp su ddylsv", "TheAlgorithms") @@ -116,13 +116,16 @@ def decrypt(ciphertext: str, key: str) -> str: if __name__ == "__main__": + import doctest + + doctest.testmod() operation = int(input("Type 1 to encrypt or 2 to decrypt:")) if operation == 1: - plaintext = str(input("Typeplaintext to be encrypted:\n")) - key = str(input("Type the key:\n")) + plaintext = input("Typeplaintext to be encrypted:\n") + key = input("Type the key:\n") print(encrypt(plaintext, key)) elif operation == 2: - ciphertext = str(input("Type the ciphertext to be decrypted:\n")) - key = str(input("Type the key:\n")) + ciphertext = input("Type the ciphertext to be decrypted:\n") + key = input("Type the key:\n") print(decrypt(ciphertext, key)) decrypt("jsqqs avvwo", "coffee") From b605697850cdd10572ac2f20e4b836aee95c565b Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 18 Dec 2022 23:05:29 +0100 Subject: [PATCH 07/11] Rename gaussian_naive_bayes.py to gaussian_naive_bayes.py.broken.txt --- ...gaussian_naive_bayes.py => gaussian_naive_bayes.py.broken.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename machine_learning/{gaussian_naive_bayes.py => gaussian_naive_bayes.py.broken.txt} (100%) diff --git a/machine_learning/gaussian_naive_bayes.py b/machine_learning/gaussian_naive_bayes.py.broken.txt similarity index 100% rename from machine_learning/gaussian_naive_bayes.py rename to machine_learning/gaussian_naive_bayes.py.broken.txt From 05be756da757db5c57cc1fc74c98c85dbbcac935 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 18 Dec 2022 23:05:58 +0100 Subject: [PATCH 08/11] Rename gradient_boosting_regressor.py to gradient_boosting_regressor.py.broken.txt --- ...ing_regressor.py => gradient_boosting_regressor.py.broken.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename machine_learning/{gradient_boosting_regressor.py => gradient_boosting_regressor.py.broken.txt} (100%) diff --git a/machine_learning/gradient_boosting_regressor.py b/machine_learning/gradient_boosting_regressor.py.broken.txt similarity index 100% rename from machine_learning/gradient_boosting_regressor.py rename to machine_learning/gradient_boosting_regressor.py.broken.txt From 876e857758237e0e72873ae5c5915688dc1d8be8 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 18 Dec 2022 23:09:22 +0100 Subject: [PATCH 09/11] Rename random_forest_classifier.py to random_forest_classifier.py.broken.txt --- ...orest_classifier.py => random_forest_classifier.py.broken.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename machine_learning/{random_forest_classifier.py => random_forest_classifier.py.broken.txt} (100%) diff --git a/machine_learning/random_forest_classifier.py b/machine_learning/random_forest_classifier.py.broken.txt similarity index 100% rename from machine_learning/random_forest_classifier.py rename to machine_learning/random_forest_classifier.py.broken.txt From cce6b5aa60e4076e8c1979ae294f338252b68baa Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 18 Dec 2022 23:15:35 +0100 Subject: [PATCH 10/11] Rename random_forest_regressor.py to random_forest_regressor.py.broken.txt --- ..._forest_regressor.py => random_forest_regressor.py.broken.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename machine_learning/{random_forest_regressor.py => random_forest_regressor.py.broken.txt} (100%) diff --git a/machine_learning/random_forest_regressor.py b/machine_learning/random_forest_regressor.py.broken.txt similarity index 100% rename from machine_learning/random_forest_regressor.py rename to machine_learning/random_forest_regressor.py.broken.txt From fe836730b2682a7d44491a4691ed22a265a02318 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 18 Dec 2022 23:23:46 +0100 Subject: [PATCH 11/11] Rename equal_loudness_filter.py to equal_loudness_filter.py.broken.txt --- ...ual_loudness_filter.py => equal_loudness_filter.py.broken.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename audio_filters/{equal_loudness_filter.py => equal_loudness_filter.py.broken.txt} (100%) diff --git a/audio_filters/equal_loudness_filter.py b/audio_filters/equal_loudness_filter.py.broken.txt similarity index 100% rename from audio_filters/equal_loudness_filter.py rename to audio_filters/equal_loudness_filter.py.broken.txt