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’.
The Reflection
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[])
Step by step
Solved in 3 steps