I'm getting a few error on syntax and return statements. Can you help me fix my code. The code is listed underneath of t

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

I'm getting a few error on syntax and return statements. Can you help me fix my code. The code is listed underneath of t

Post by answerhappygod »

I'm getting a few error on syntax and return statements. Can youhelp me fix my code. The code is listed underneath of theinsructions.
Overview: In this week, you have studied additional Pythonlanguage syntax including Arrays and Strings. In particular, youused the numpy, regular expressions, and Panda libraries to helpmanipulate and store data. The Lab for this week demonstrates yourknowledge of this additional Python functionality. Be sure to usethe examples in the textbook reading along with the associatelibraries, functions and processes when completing the assignmentsfor this week.
Submission requirements for this project include 2 files.(Zipping them into one file is acceptable and encouraged):
• Python Numpy and Pandas Application Code
• Word or PDF file containing your test and pylint results alongwith the Password cracking activity results
Python Applications for this lab: (total 100 points):
This lab consists of three parts. 1.
(60 points) allows a user to enter and validate their phonenumber and zipcode+4. Then the user will enter values of two, 3x3matrices and then select from options including, addition,subtraction, matrix multiplication, and element by elementmultiplication. You should use numpy.matmul() for matrixmultiplication (e.g. np.matmul(a, b) ). The program should computethe appropriate results and return the results, the transpose ofthe results, the mean of the rows for the results, and the mean ofthe columns for the results.
When entering data, the application should use regularexpressions and/or Pandas functionality to check the format of thephone number and zipcode. You should check that each value isnumeric for the matrices. The user interface should continue to rununtil the user indicates they are ready to exit.
A user interface might look similar to this:
***************** Welcome to the Python MatrixApplication***********
Do you want to play the Matrix Game?
Enter Y for Yes or N for No: Y
Enter your phone number (XXX-XXX-XXXX:
555-555-55
Your phone number is not in correct format. Please renter:
555-555-5555
Enter your zip code+4 (XXXXX-XXXX):
21022-3213 2
Enter your first 3x3 matrix:
1 2 4
4 2 1
3 8 9
Your first 3x3 matrix is:
1 2 4
4 2 1
3 8 9
Enter your second 3x3 matrix:
3 2 1
7 2 5
5 2 1
Your first 3x3 matrix is:
3 2 1
7 2 5
5 2 1
Select a Matrix Operation from the list below:
a. Addition
b. Subtraction
c. Matrix Multiplication
d. Element by element multiplication
a
You selected Addition.
The results are:
4 4 5
11 4 6
8 10 10
The Transpose is:
4 11 8
4 4 10
5 6 10
The row and column mean values of the results are:
Row: 4.33, 7, 9.33
Column: 7.66, 6, 7 3
Do you want to play the Matrix Game?
Enter Y for Yes or N for No: N
*********** Thanks for playing Python Numpy ***************
If an inappropriate entry is detected, the program should promptfor a correct value and continue to do so until a correct value isentered.
Hints:
1. Use numpy, pandas and regular expressions as appropriate.
2. Create and use functions as often as possible
3. Both integers and float values are acceptable
4. Use comments to document your code
5. Test with many combinations.
6. Use pylint to verify the code style – the goal is a 10!
2. (15 points) Document your testing results using yourprogramming environment. You should also include and discuss yourpylint results for the application. The test document shouldinclude a test table that includes the input values, the expectedresults and the actual results. A screen capture should be includedthat shows the actual test results of running each test case foundin the test table. Be sure to include multiple test cases toprovide full coverage for all code and for each function youdevelop and test.
3. (25 points) Password crackers can easily be written usingPython code. You can also generate a hashed password using Pythonwith a variety of hash algorithms. For this exercise, you willcreate use Python code to generate ten (10) passwords withdifferent hashing algorithms and then use a popular online passwordcracking website to see if the passwords can be cracked.
For example, the following Python code can be used to hash apassword input using MD-5, SHA-256 and SHA-512 algorithms.
import hashlib
# input a message to encode
print('Enter a message to encode:')
message = input()
# encode it to bytes using UTF-8 encoding
message = message.encode()
# hash with MD5 (very weak)
print(hashlib.md5(message).hexdigest()) 4
# Lets try a stronger SHA-2 family
print(hashlib.sha256(message).hexdigest())
print(hashlib.sha512(message).hexdigest())
When you run this at the command prompt, you enter a passwordand then you will receive the hashed values for the MD-5, SHA-256and SHA-512 algorithms, respectively.
I M Getting A Few Error On Syntax And Return Statements Can You Help Me Fix My Code The Code Is Listed Underneath Of T 1
I M Getting A Few Error On Syntax And Return Statements Can You Help Me Fix My Code The Code Is Listed Underneath Of T 1 (43.6 KiB) Viewed 49 times
In this case, hello05 was entered and resulted in the 3 outputs.Notice, the SHA-512 is quite long and extends over two lines.
If we take those 3 output hashes and input them into theCrackstation.net URL, the passwords are hacked in each case:
I M Getting A Few Error On Syntax And Return Statements Can You Help Me Fix My Code The Code Is Listed Underneath Of T 2
I M Getting A Few Error On Syntax And Return Statements Can You Help Me Fix My Code The Code Is Listed Underneath Of T 2 (151.71 KiB) Viewed 49 times
5 Notice in each case, the original password of hello05 wascracked.
You can salt a password by adding some random text of a phraseto the beginning of your actual password. This will add somestrength to preventing a quick decryption. For this simple Pythoncode, you can simulate a salt by adding a string to the front ofpassword and then run the output into the Crackstation. Forexample, consider this salted password:
wellwhatdoyouknowaboutthathello05
In this case the phase “wellwhatdoyouknowaboutthat” is placed infront of hello05. The resulting output hashes are:9aa8390dd622412e6a5ec75f35a661d994e0cb79b0dbbe82ea06c37af830f21bf926593618c6859141e553e61c75980005f1d3eaaf9fc6b72410d16f78df7db42599367160c60f46888d6a888e68beef0b696ddb9c57debaaba2869d45f23cdf0538b31449c9191d0254645b5b16ff61
When use those hash values as input into the Crackstation, thedecoder fails:
I M Getting A Few Error On Syntax And Return Statements Can You Help Me Fix My Code The Code Is Listed Underneath Of T 3
I M Getting A Few Error On Syntax And Return Statements Can You Help Me Fix My Code The Code Is Listed Underneath Of T 3 (176.49 KiB) Viewed 49 times
6 For your activity, experiment with the Python script usingMD-5, SHA-256 and SHA-512 hash algorithms for at least 20 differentpasswords. Be sure to experiment with “easy” passwords, saltedpasswords as well as randomly generated passwords (e.g. from sitessuch as Norton password generator(https://my.norton.com/extspa/passwordma ... th=pwd-gen).
For your report, prepare a table that shows the input password,the resulting hashes and if the Crackstation.net site was able tocrack the password. An example table is shown below:
Table 1. Password Cracking Activity Results
I M Getting A Few Error On Syntax And Return Statements Can You Help Me Fix My Code The Code Is Listed Underneath Of T 4
I M Getting A Few Error On Syntax And Return Statements Can You Help Me Fix My Code The Code Is Listed Underneath Of T 4 (61.77 KiB) Viewed 49 times
Password Hash output Did Crackstation work?
Be sure to describe what you learned from this password crackingactivity and what would you recommend as possible strong passwordsafter completing this activity in your report?
Show transcribed data
I'm getting a few errors for syntax and return statements. Canyou help me fix the code.
import numpy as npimport refirst=np.zeros((3,3))second=np.zeros((3,3))def addition(first,second):print("you selected addition. the results are")return np.add(first,second)def substraction(first,second):print("you selected substraction. the results are")return np.sub(first,second)def multiplication(first,second):print("you selected multiplication. the results are")return np.matmul(first,second)def elemultiplication(first,second):print("you selected element by multiplication. the resultsare")return np.multiply(first,second)
while 1:print("Do you want to play the Matrix Game?")op=input("Enter Y for Yes or N for No:")print("Enter your phone number(xxx-xxx-xxxx):")while 1:ph=input()if(re.match("\d{3}[-]\d{3}[-]\d{4}", ph)):breakelse:print("Your phone number is not in correct format pleasereenter")print("Enter your zip code +4 (xxxxx-xxxx):")while 1:zp=input()if(re.match("\d{5}[-]\d{4}", zp)):breakelse:print("Your zip code is not in correct format pleasereenter")print("Enter your first 3x3 matrix")for i in range(3):for j in range(3):first[j]=input()print("your first 3x3 matrix is")for i in range(3):for j in range(3):print(first[j],end=' ')print()print("Enter your second 3x3 matrix")for i in range(3):for j in range(3):second[j]=input()print("your second 3x3 matrix is")for i in range(3):for j in range(3):print(second[j],end=' ')print()print("select a Matrix operation from the list below \n a. additionb. substraction\n c. matrix multiplication\n d. element by elementmultiplication\n")op=input()res=np.zeros((3,3))if(op=='a'):res=addition(first,second)elif(op=='b'):res=substraction(first,second)elif(op=='c'):res=multiplication(first,second)elif(op=='d'):res=elemultiplication(first,second)else:print("invalid option")for i in range(3):for j in range(3):print(res[j],end=' ')print()print("The transpose is")for i in range(3):for j in range(3):print(res[j],end=' ')print()print("The row and column mean values of the matrix are")rw=np.zeros(3)cl=np.zeros(3)for i in range(3):for j in range(3):rw+=res[j]cl[j]+=res[j]print("Row:",rw[0]/3,rw[1]/3,rw[2]/3)print("column:",cl[0]/3,cl[1]/3,cl[2]/3)
Command Prompt
Enter up to 20 non-salted hashes, one per line: Supports: LM, NTLM, md2, md4, md5, md5(md5_hex), md5-half, sha1, sha224, sha256, sha384, sha512, ripeMD160, whirlpool, MySQL 4.1+ (sha1(sha1_bin)), QubesV3.1BackupDefaults
Enter up to 20 non-salted hashes, one per line: Supports: LM, NTLM, md2, md4, md5, md5(md5_hex), md5-half, sha1, sha224, sha256, sha384, sha512, ripeMD160, whirlpool, MySQL 4.1+ (sha1(sha1_bin)), QubesV3.1BackupDefaults
\begin{tabular}{|l|l|l|} \hline Password & Hash output & Did Crackstation work? \\ \hline password01 & af88a0ae641589b908fa8b31f0fcf6e1 4 b8f353889 d9a05 d17946e26 d014efe99407cba8bd9d 0102d4aab10ce6229043 746a5a2664633cb15829e80cc8 d5dd7368 b1 d939756e 7b069df9df482e2afc3c44029ec71ffbf7cc9916719d861 b60fc34b5 bd6a4f2cb0fe7747d99d5b219162 & \\ \hline… & & \\ \hline \end{tabular}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply