Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Calculate the following in a script file. Terminate each line with a semicolon; use disp() to display final answers to the command window. 1. Binary-to-decimal

image text in transcribed
image text in transcribed
Calculate the following in a script file. Terminate each line with a semicolon; use disp() to display final answers to the command window. 1. Binary-to-decimal conversion The decimal value of a binary number is calculated from the equation Where b, is the nih bit (either 0 or 1) and N is the number of bits in the binary number. As an illustrative example, the binary number 1010 0110 has the decimal value X = 1.2? +025 +1.25 +0-24 +0-22 +1.2? +1-24 +0-2 = 128 +32 + 4 + 2 = 166 A. Write a script to calculate the decimal value of a 32-bit binary number by the following method: a. Create a row vector, n, containing the integers from 31 through in descending order. (Do not type all 32 numbers - use the operator or linspace.) b. Create a row vector of Os and 1s representing the bits of the binary number. (For the example given above, the row vector would be b = [1, 0, , 0, 0, 1, 1, 0]) c. Perform element-by-element array operations to create a row vector containing the terms b, 2". d. Use the sum function to calculate X Test your method on the following numbers (helpfully provided in the template): 1011 0110 0010 0000 0111 1000 1111 0001 1111 1111 1111 1111 1111 1111 1111 1111 1000 0000 0000 0000 0000 0000 0000 0000 1010 1010 1010 1010 1010 1010 1010 1010 B. Use the built-in function, bin2 dec (), to check your answers, and include these checks in your script. (But note that the input argument of bin2dec is a character array, not a numerical array.) C. Of the four decimal values that you calculated in part A, calculate the ratio of the second number to the third one and look at the result. It shows an interesting property of binary numbers. 2. A Digital Message A. Convert the matrix to a column vector of decimal numbers using the method from problem 1. You may think that a loop is needed to iterate over the rows of the matrix, but it is not. Modify the approach of problem 1 as follows: a. Create a MATRIX in which EACH ROW contains the integers from 7 to 0. (ASCII is an 8-bit code.) HINT: create a single row vector then use concatenation to create the matrix. b. Use this matrix in place of the row vector in step c of problem 1 c. Take the sum of EACH ROW. REMEMBER: by default, the sum function operates by columns B. Use the char() function to convert the column of decimal ASCII values to characters, and take the transpose to display it as a word. (What's the message? If you can't read it, you did something wrong.) 3. Encoding a password by hashing (Courtesy of Prof. Jon Brown) In cryptography, a hash algorithm is often used to mask passwords so that they are not stored as plain text. A hash algorithm is code that takes data of any length and converts it to a seemingly random data (the "hash") of a fixed length. These algorithms are useful in password management because it is easy to convert from the data to the hash (to compare an input password to the stored one), but very difficult to do the reverse (to convert a stolen password database to usable passwords). A simple hash algorithm is to convert all input data to a single character: 1. Input the password 2. Subtract 32 from the character array - this will turn it into a numerical array containing the ASCII code of each letter minus 32 3. Add all the numbers in the array using the sum() function. 4. Apply the mod() function to the sum, with the second argument being 95. This will return the remainder when the sum is divided by 95, which will be a number between 0 and 94. 5. Convert back to a character by adding 32 and using the char() function A. Apply this hash algorithm to the character array from problem 2 B. B. Apply the hash algorithm to the word 'Tennessee'. If you did everything right, you should get the same result as in part A

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Master The Art Of Data Storytelling With Visualizations

Authors: Alexander N Donovan

1st Edition

B0CNMD9QRD, 979-8867864248

More Books

Students also viewed these Databases questions

Question

My opinions/suggestions are valued.

Answered: 1 week ago