Python Cyber Security - Function to suggest character substitutions for stronger passwords
4. Common Substitution Generator
Write a Python function that takes a password as input and returns a list of common character substitutions that could be used to create a stronger password.
For example, if the password is "myspass", the function should return
['my$pass', 'my5pass', 'mySpass', 'mysp@ss', 'mysp4ss', 'myspAss', 'myspa$s', 'myspa5s', 'myspaSs', 'myspas$', 'myspas5', 'myspasS', 'myspass!', 'myspass123', 'myspass@', 'myspass#', 'myspass$', 'myspass%', 'myspass&', 'myspass*', 'myspass-', 'myspass_', 'myspass=', 'myspass+']
Sample Solution:
Python Code:
Sample Output:
Input your password: pqre3sd ['pqr33sd', 'pqrE3sd', 'pqre3$d', 'pqre35d', 'pqre3Sd', 'pqre3sd!', 'pqre3sd123', 'pqre3sd@', 'pqre3sd#', 'pqre3sd$', 'pqre3sd%', 'pqre3sd&', 'pqre3sd*', 'pqre3sd-', 'pqre3sd_', 'pqre3sd=', 'pqre3sd+']
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python function that takes a password and returns a dictionary mapping each character to a list of common substitutions (e.g., 'a' to ['@', '4']).
- Write a Python program to generate a list of possible stronger passwords by replacing characters in the input password with their common substitutions.
- Write a Python script that, given a password, prints out all variant forms using at least one substitution for each character.
- Write a Python function that takes a password and returns all combinations of substitutions for its characters, filtering out duplicates.
Go to:
Previous: Check password strength.
Next: Check and print valid passwords from a file.
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.