The Reflection algorithm can be used to encrypt a C-string (character array terminated with the null character) before it is transmitted over the Internet. The Reflection algorithm works as follows:  Each letter in the message is converted to the letter in that is 13 positions to the right of that letter in the English alphabet. If the end of the alphabet is reached, counting continues from the first letter in the alphabet. The case of the letters must be maintained. For example, 'M' →'Z', 'x' → 'k', 'A' → 'N' The numeric characters ('0' to '9') are shifted 5 positions to the right of that number in the character set '0' to '9'. If ‘9’ is reached, counting continues from ‘0’. For example, '0' → '5', '2' →'7', '8' → '3'  All other characters are left as they are. a) What would the following string be encrypted to by the Reflection algorithm? “Call me at 662-2002 Ext 85393”  b) Write a function, getPosition, which finds the position of a letter in the alphabet regardless of the case of the letter or the position of a numeric character in the range ‘0’ – ‘9’. The function header of getPosition is as follows: int getPosition(char ch) NB: getPosition (‘z’) should return 26, getPosition (‘B’) should return 2 and getPosition (‘5’)shouldreturn5.  c) Write a function, encrypt, which given a character, ch, encrypts the character using the Reflection algorithm. The function finds the position of ch and uses this to encrypt it. It returns the encrypted character. The function header of encrypt is as follows: char encrypt (char ch) NB: encrypt (‘a’) should return ‘n’, encrypt (‘Z’) should return ‘M’ and encrypt (‘5’) should return ‘0’.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

The Reflection algorithm can be used to encrypt a C-string (character array terminated with the null character) before it is transmitted over the Internet. The Reflection algorithm works as follows:


 Each letter in the message is converted to the letter in that is 13 positions to the right of that letter in the English alphabet. If the end of the alphabet is reached, counting continues from the first letter in the alphabet. The case of the letters must be maintained. For example,
'M' →'Z', 'x' → 'k', 'A' → 'N'
The numeric characters ('0' to '9') are shifted 5 positions to the right of that number in the character set '0' to '9'. If ‘9’ is reached, counting continues from ‘0’. For example,
'0' → '5', '2' →'7', '8' → '3'
 All other characters are left as they are.


a) What would the following string be encrypted to by the Reflection algorithm?
“Call me at 662-2002 Ext 85393” 


b) Write a function, getPosition, which finds the position of a letter in the alphabet regardless of the case of the letter or the position of a numeric character in the range ‘0’ – ‘9’. The function header of getPosition is as follows:
int getPosition(char ch)
NB: getPosition (‘z’) should return 26, getPosition (‘B’) should return 2 and
getPosition (‘5’)shouldreturn5. 


c) Write a function, encrypt, which given a character, ch, encrypts the character using the Reflection algorithm. The function finds the position of ch and uses this to encrypt it. It returns the encrypted character. The function header of encrypt is as follows:
char encrypt (char ch)
NB: encrypt (‘a’) should return ‘n’, encrypt (‘Z’) should return ‘M’ and encrypt
(‘5’) should return ‘0’. 


d) Write a function, decrypt, which converts a character, ch, to its original form and returns
it to the caller. The function header of decrypt is as follows: char decrypt (char ch)
NB: decrypt(‘e’) should return ‘r’, decrypt (‘E’) should return ‘R’ and decrypt (‘9’) should return ‘4’. 


e) Write a function, reflectMessage, which accepts a C-string containing the message to be encrypted and a C-string to hold the encrypted message as parameters and encrypts the C- string using the Reflection algorithm. The function heading of reflectMessage is as follows:
void reflectMessage (char message[], char encryptedMessage[])

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY