Question
Please write your code in R and submit your script and results for each of the following. 1-Store the following binary number as a character
Please write your code in R and submit your script and results for each of the following.
1-Store the following binary number as a character string s: 110011. (10 points)
2-Convert this into a character vector v. (10 points)
3-Expand the character vector v to 8 bits as follows: swap v[3] and v[4] . (10 points)
4-Replicate v[3] and v[4] . The result (call it ev) should be a character vector of size 8. (10 points)
5- Write a function called expand() that takes a binary vector of size 6 as input and returns a binary vector of size 8 as output. (20 points)
6-Create two character vectors S11 and S12 such that S11 contains the binary representations of the numbers (5,2,1,6,3,4,7,0), and S12 contains those of the numbers (1,4,6,2,0,7,5,3). (10 points)
7-Let b=1101. Extract the last three characters. Convert the last three characters into decimal and store it in a variable called tempVal. Write an if-then-else statement such that if b[1] == 0 retrieve the value of S11[tempval]. If b[1]==1 retrieve the value of S12[tempval] and store it in a variable tempRet. (Hint: You might need to shift the indices by 1) (10 points)
8-Write a function called S11_function that takes a block of 4-character binary (such as 1110) and, using the two s-boxes from question 6, returns a 3-character binary number using the logic that if the first character is 0 then use S11, otherwise use S12. (20 points)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started