You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: encrypt-passwords/README.md
+6-4Lines changed: 6 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -11,10 +11,10 @@ This script can be ran interactively or silently, see the below to see how.
11
11
### Getting Started
12
12
To utilize this script in the command-line, please follow the below workflow:
13
13
14
-
(1) Clone the script into your environment.\
15
-
(2) Make sure latest version of Python 3 is installed on the environment.\
16
-
(3) Run the script interactively: `python3 encryptpw.py 1 -p <password>`.\
17
-
(4) Run the script interactively: `python3 encryptpw.py 2`.
14
+
1. Clone the script into your environment.
15
+
2. Make sure latest version of Python 3 is installed on the environment.
16
+
3. Run the script interactively: `python3 encryptpw.py 1 -p <password>`.
17
+
4. Run the script interactively: `python3 encryptpw.py 2`.
18
18
19
19
Additionally, this can be ran from your Python IDE of choice such as PyCharm, IDLE, Visual Studio Code, etc.
20
20
@@ -25,3 +25,5 @@ See below an image of the script in action:
25
25
Included is `encryptpw_unittest.py` to check for correctness. The tests provide few, basic tests to verify the addition, subtraction, multiplication and division functions are working properly. To run in the command-line, run the following command:
# Description: Encrypts passwords using the Fernet cryptography method.
7
7
8
8
importargparse, getpass
9
9
fromcryptography.fernetimportFernet
10
10
11
-
# Function to encrypt passwords using Fernet cryptography.
12
11
defencryption(password):
13
-
# Instance the Fernet class with the key variable...
14
12
key=Fernet.generate_key()
15
13
fernet=Fernet(key)
16
14
17
-
# Encoding to byte string before we can actually encrypt...
18
15
new_pass=fernet.encrypt(password.encode())
19
16
20
17
returnnew_pass
21
18
19
+
defoutput(password, result):
20
+
withopen("pass.txt", "w") astext_file:
21
+
print(f"{password}", file=text_file)
22
+
print(f"{result}", file=text_file)
23
+
text_file.close()
24
+
25
+
print("Key and encrypted password have been saved to pass.txt")
26
+
22
27
defmain():
23
28
parser=argparse.ArgumentParser(description="Encrypts user-inputted passwords using Fernet cryptography")
24
29
parser.add_argument("mode", metavar="mode", type=int, help="runs the script in interactive or silent mode: 1 for silent, 2 for interactive. If silent, run required command-line flags")
25
30
parser.add_argument("-p", "--password", help="password that will be encrypted")
26
31
27
32
args=parser.parse_args()
28
33
29
-
# If user chooses option 1, run script silently. Else, if user chooses option 2, run script interactively.
30
34
ifargs.mode==1:
31
-
# Print out the initial password along with the encrypted password.
32
35
result=encryption(args.password)
33
-
print(f"\nKey: {args.password}")
34
-
print(f"\nEncrypted Password: {result}\n")
36
+
output(args.password, result)
35
37
elifargs.mode==2:
36
38
welcome="""
37
39
Welcome to the Encrypt Passwords tool! This will take user-inputted passwords and
38
40
encrypt them using the Fernet cryptography method.
39
41
"""
40
42
print(welcome)
41
43
42
-
# Once password is received, print the key along with the encrypted password.
43
44
password=getpass.getpass(prompt="Please enter a password that will be used as a key to encrypt: ")
Copy file name to clipboardExpand all lines: python-calculator/README.md
+9-7Lines changed: 9 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -8,17 +8,19 @@ This script can be ran interactively or silently using command-line arguments. T
8
8
### Getting Started
9
9
To utilize this script in the command-line, please follow the below workflow:
10
10
11
-
(1) Clone the script into your environment.\
12
-
(2) Make sure latest version of Python 3 is installed on the environment.\
13
-
(3) Run the script silently: **python3 calculator.py 1 -n1 <number> -n2 <number> -o <operation>**.\
14
-
(4) Run the script interactively: **python3 calculator.py 2**
11
+
1. Clone the script into your environment.
12
+
2. Make sure latest version of Python 3 is installed on the environment.
13
+
3. Run the script silently: `python3 calculator.py 1 -n1 <number> -n2 <number> -o <operation>`.
14
+
4. Run the script interactively: `python3 calculator.py 2`
15
15
16
16
Additionally, this can be ran from your Python IDE of choice such as PyCharm, IDLE, Visual Studio Code, etc.
17
17
18
18
See below an image of the script in action:
19
-

19
+

20
20
21
-
### Testing
21
+
### Unit Testing
22
22
Included is `calculator_unittest.py` to check for correctness. The tests provide few, basic tests to verify the addition, subtraction, multiplication and division functions are working properly. To run in the command-line, run the following command:
# Ask if the user wishes to continue performing calculations; end if they do not.
80
-
next_choice=input("Would you like to continue? Enter 'yes' or 'no': ")
81
-
ifnext_choice=="yes":
70
+
next_choice=input("\nWould you like to continue? Enter 'yes'|'y' or 'no'|'n': ")
71
+
whilenext_choicenotin ("yes", "y", "no", "n"):
72
+
next_choice=input("Please enter 'yes'|'y' or 'no'|'n': ")
73
+
ifnext_choice=="yes"ornext_choice=="y":
82
74
continue
83
-
elifnext_choice=="no":
84
-
break
85
-
else:
86
-
print("Huh? Ending the program...")
75
+
elifnext_choice=="no"ornext_choice=="n":
76
+
print("Thank you for using the Python Calculator!")
87
77
break
88
78
else:
89
-
print("ERROR. You must choose a number in the range 1-7. Please try again...")
79
+
print("You must choose a number in the range 1-7. Please try again...\n")
80
+
continue
90
81
91
82
defmain():
92
83
parser=argparse.ArgumentParser(description="Performs the following operations: addition, subtraction, multiplication, division, remainder, squared, cubed.")
93
84
parser.add_argument('mode', metavar='mode', type=int, help="runs the script in interactive or silent mode: 1 for silent, 2 for interactive. If silent, run the other command-line flags as well.")
94
85
parser.add_argument("-n1", "--number1", type=int, help="first number to input")
95
86
parser.add_argument("-n2", "--number2", type=int, help="second number to input")
0 commit comments