diff --git a/README.md b/README.md index 186a83d..fdf2fbe 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This package provides password management tools in Python. The package consists - `encrypt_password`: - Encrypts a password using a simple substitution cipher. This function applies a character mapping based on a shuffled character set, providing basic encryption. - `decrypt_password`: - - Decrypts a message that was encrypted using the `encrypt_password` function. It reverses the encryption process by mapping each character of the encrypted message back to its original character. + - Decrypts a password that was encrypted using the `encrypt_password` function. It reverses the encryption process by mapping each character of the encrypted message back to its original character. This Python package is useful for users seeking an integrated solution for password management, offering a user-friendly experience. With key functionalities consolidated in one package, users can effortlessly generate strong passwords, evaluate their strength, and grasp encryption and decryption methods through our straightforward substitution cipher. diff --git a/docs/example.ipynb b/docs/example.ipynb index 234581c..d1cad7a 100644 --- a/docs/example.ipynb +++ b/docs/example.ipynb @@ -244,7 +244,7 @@ "source": [ "### Encrypt a Password\n", "\n", - "The `encrypt_password` function encrypts a message using a simple substitution cipher, by substituting each character with a corresponding character from a shuffled set. It uses the same set of characters as the decryption function, so they can work in tandem. Its first argument, `message`, requires a string input, while the second optional argument, `random_seed`, accepts an integer value." + "The `encrypt_password` function encrypts a password using a simple substitution cipher, by substituting each character with a corresponding character from a shuffled set. It uses the same set of characters as the decryption function, so they can work in tandem. Its first argument, `password`, requires a string input, while the second optional argument, `random_seed`, accepts an integer value." ] }, { @@ -317,7 +317,7 @@ "metadata": {}, "source": [ "### Decrypt a Password\n", - "The `decrypt_password` function decrypts a password that has previously been encrypted with the `encrypt_password` function. It requires the same seed that was used in the `encrypt_password`. It takes two arguments, the first `encrypted_message` is the encrypted password passed in as a string. The `random_seed` argument is the seed that was used to encrypt the password, passed in as an integer value.\n", + "The `decrypt_password` function decrypts a password that has previously been encrypted with the `encrypt_password` function. It requires the same seed that was used in the `encrypt_password`. It takes two arguments, the first `encrypted_password` is the encrypted password passed in as a string. The `random_seed` argument is the seed that was used to encrypt the password, passed in as an integer value.\n", "\n", "#### Decryption Defaults\n", "The next time Bob tries to log in to Facebook, he can't remember his password. Bob knows where he saved his encrypted password on his computer, but he cannot find the seed, so he tries to decrypt his encrypted password with the default settings." diff --git a/src/passwordler/decrypt_password.py b/src/passwordler/decrypt_password.py index 8af5135..9b33309 100644 --- a/src/passwordler/decrypt_password.py +++ b/src/passwordler/decrypt_password.py @@ -1,9 +1,9 @@ import random from ._internals import original, getKeyMap -def decrypt_password(encrypted_message, random_seed = 123): +def decrypt_password(encrypted_password, random_seed = 123): """ - Decrypt an encrypted password or message using a simple substitution cipher. + Decrypt an encrypted password using a simple substitution cipher. The function uses a substitution cipher to decrypt an encrypted string. The original set is replaced with a randomly shuffled character from the same set. @@ -11,26 +11,26 @@ def decrypt_password(encrypted_message, random_seed = 123): matches. Parameters: - - encrypted_message (str): The encrypted message to be decrypted. + - encrypted_password (str): The encrypted password to be decrypted. - random_seed (int): Seed for the random number generator to ensure that encryption and decryption match. Default is 123. Returns: - - str: The decrypted message. + - str: The decrypted password. The function uses a substitution cipher where each character in the original set is replaced with a randomly shuffled character from the same set. The random seed is utilized to maintain consistent decryption results when needed. Example: - >>> original_message = 'Monty Python' - >>> encrypted_message = encrypt_password(original_message, random_seed = 123) - >>> decrypted_message = decrypt_password(encrypted_message, random_seed = 123) + >>> original_password = 'Monty Python' + >>> encrypted_password = encrypt_password(original_password, random_seed = 123) + >>> decrypted_password = decrypt_password(encrypted_password, random_seed = 123) Output: 'Monty Python' """ - if not isinstance(encrypted_message, str): + if not isinstance(encrypted_password, str): raise TypeError( - f"string expected as encrypted message, got '{type(encrypted_message)}'" + f"string expected as encrypted password, got '{type(encrypted_password)}'" ) if not isinstance(random_seed, int): @@ -38,9 +38,9 @@ def decrypt_password(encrypted_message, random_seed = 123): f"integer expected as random_seed, got '{type(random_seed)}'" ) - if encrypted_message == '': + if encrypted_password == '': raise ValueError( - 'encrypted_message cannot be empty string') + 'encrypted_password cannot be empty string') random.seed(random_seed) @@ -48,14 +48,14 @@ def decrypt_password(encrypted_message, random_seed = 123): random.shuffle(decryption) keyMap = getKeyMap(decryption, isDecryption=True) - decrypted_msg = [] + decrypted_pass = [] - for character in encrypted_message: + for character in encrypted_password: if character in keyMap: - decrypted_msg.append(keyMap[character]) + decrypted_pass.append(keyMap[character]) else: - decrypted_msg.append(character) + decrypted_pass.append(character) - decrypted_msg = ''.join(decrypted_msg) + decrypted_pass = ''.join(decrypted_pass) - return decrypted_msg \ No newline at end of file + return decrypted_pass \ No newline at end of file diff --git a/src/passwordler/encrypt_password.py b/src/passwordler/encrypt_password.py index b99549d..2195d69 100644 --- a/src/passwordler/encrypt_password.py +++ b/src/passwordler/encrypt_password.py @@ -3,33 +3,33 @@ import random from ._internals import original, getKeyMap -def encrypt_password(message, random_seed=123): +def encrypt_password(password, random_seed=123): """ - Encrypt a message using a simple substitution cipher. + Encrypt a password using a simple substitution cipher. - This function encrypts a message by substituting each character with a corresponding character + This function encrypts a password by substituting each character with a corresponding character from a shuffled set, using the same set of characters as the decryption function. The shuffle - is controlled by a random seed to ensure reproducible results, allowing encrypted messages + is controlled by a random seed to ensure reproducible results, allowing encrypted passwords to be consistently decrypted using the matching seed. Characters not included in the - substitution set remain unchanged in the encrypted message. + substitution set remain unchanged in the encrypted password. Parameters: - - message (str): The message to be encrypted. + - password (str): The password to be encrypted. - random_seed (int): Seed for the random number generator to ensure consistent encryption results. Default value is 123. Returns: - - str: The encrypted message. + - str: The encrypted password. Example: - >>> original_message = 'Monty Python' - >>> encrypted_message = encrypt_password(original_message, random_seed = 123) - >>> decrypted_message = decrypt_password(encrypted_message, random_seed = 123) + >>> original_password = 'Monty Python' + >>> encrypted_password = encrypt_password(original_password, random_seed = 123) + >>> decrypted_password = decrypt_password(encrypted_password, random_seed = 123) Output: 'Monty Python' """ - if not isinstance(message, str): + if not isinstance(password, str): raise TypeError( - f"string expected as encrypted message, got '{type(message)}'" + f"string expected as encrypted password, got '{type(password)}'" ) if not isinstance(random_seed, int): @@ -37,9 +37,9 @@ def encrypt_password(message, random_seed=123): f"integer expected as random_seed, got '{type(random_seed)}'" ) - if message == '': + if password == '': raise ValueError( - 'encrypted_message cannot be empty string') + 'encrypted_password cannot be empty string') random.seed(random_seed) @@ -47,14 +47,14 @@ def encrypt_password(message, random_seed=123): random.shuffle(encryption) keyMap = getKeyMap(encryption) - encrypted_msg = [] + encrypted_pass = [] - for character in message: + for character in password: if character in original: - encrypted_msg.append(keyMap[character]) + encrypted_pass.append(keyMap[character]) else: - encrypted_msg.append(character) + encrypted_pass.append(character) - encrypted_msg = ''.join(encrypted_msg) + encrypted_pass = ''.join(encrypted_pass) - return encrypted_msg + return encrypted_pass diff --git a/tests/test_decrypt_password.py b/tests/test_decrypt_password.py index dceb8ae..c015576 100644 --- a/tests/test_decrypt_password.py +++ b/tests/test_decrypt_password.py @@ -7,7 +7,7 @@ def test_decrypt_password_type_error(): """ Test if the function returns a TypeError if the type of the input is not correct. """ - with pytest.raises(TypeError, match="string expected as encrypted message"): + with pytest.raises(TypeError, match="string expected as encrypted password"): decrypt_password(123) with pytest.raises(TypeError, match="integer expected as random_seed"): @@ -16,9 +16,9 @@ def test_decrypt_password_type_error(): def test_decrypt_password_value_error(): """ - Test if the function returns a ValueError if the input for the encrypted_message is an emptry string. + Test if the function returns a ValueError if the input for the encrypted_password is an emptry string. """ - with pytest.raises(ValueError, match="encrypted_message cannot be empty string"): + with pytest.raises(ValueError, match="encrypted_password cannot be empty string"): decrypt_password("") @@ -47,9 +47,9 @@ def test_decrypt_password_special_characters_input(): assert isinstance(result, str) -def test_decrypt_password_long_input_message(): +def test_decrypt_password_long_input_password(): """ - Test if the function handles longer messages correctly. + Test if the function handles longer passwords correctly. """ result = decrypt_password( "I say you are, and I should know. I followed a few!", random_seed=42 diff --git a/tests/test_encrypt_decrypt_password.py b/tests/test_encrypt_decrypt_password.py index e0d6f5c..b6231e8 100644 --- a/tests/test_encrypt_decrypt_password.py +++ b/tests/test_encrypt_decrypt_password.py @@ -8,8 +8,8 @@ def test_encryption_decryption(): """ Test if the encryption and decryption function match each other. """ - encrypted_message = encrypt_password("Monty Python", random_seed=123) + encrypted_password = encrypt_password("Monty Python", random_seed=123) assert ( - decrypt_password(encrypted_message, random_seed=123) == "Monty Python" - ), "The encrypted message is not the same as the initial message" + decrypt_password(encrypted_password, random_seed=123) == "Monty Python" + ), "The encrypted password is not the same as the initial message" diff --git a/tests/test_encrypt_password.py b/tests/test_encrypt_password.py index 3fd14a0..edecce3 100644 --- a/tests/test_encrypt_password.py +++ b/tests/test_encrypt_password.py @@ -7,7 +7,7 @@ def test_encrypt_password_type_error(): """ Test if the function returns a TypeError if the type of the input is not correct. """ - with pytest.raises(TypeError, match="string expected as encrypted message"): + with pytest.raises(TypeError, match="string expected as encrypted password"): encrypt_password(123) with pytest.raises(TypeError, match="integer expected as random_seed"): @@ -16,9 +16,9 @@ def test_encrypt_password_type_error(): def test_encrypt_password_value_error(): """ - Test if the function returns a ValueError if the input for the encrypted_message is an emptry string. + Test if the function returns a ValueError if the input for the encrypted_password is an emptry string. """ - with pytest.raises(ValueError, match="encrypted_message cannot be empty string"): + with pytest.raises(ValueError, match="encrypted_password cannot be empty string"): encrypt_password('') @@ -32,22 +32,22 @@ def test_encrypt_password_no_seed(): def test_encrypt_normal(): """ - Test that a standard message is correctly encrypted. - The encrypted message should be different from the original message. + Test that a standard password is correctly encrypted. + The encrypted password should be different from the original password. """ - message = "testmessage" - encrypted = encrypt_password(message, 123) - assert encrypted != message + password = "testmessage" + encrypted = encrypt_password(password, 123) + assert encrypted != password assert isinstance(encrypted, str) def test_encrypt_non_standard_characters(): """ Test that non-standard characters (not in the original character set) - are unchanged in the encrypted message. + are unchanged in the encrypted password. """ - message = "test \t\n\r\x0b\x0c" - encrypted = encrypt_password(message, 123) + password = "test \t\n\r\x0b\x0c" + encrypted = encrypt_password(password, 123) print(encrypted) assert all(char in encrypted for char in " \t\n\r\x0b\x0c")