GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

A problem in c involving carious concpets

Problem Statement: Encryption is a method to obscure the letters of a sentence to hide its content. It is used in the field of Cryptography to send messages between any two computers securely. Let there be two persons called Alice and Bob. Alice wants to email a message M to Bob. However, she does not want anyone to understand it. So, she uses an encryption algorithm to jumble up the order of letters and convert each letter to a different letter. A basic version of an encryption algorithm contains two steps. Step A) Rearranging the letter stored in M as outlined below. Let the output of this step be message C1 This is done as follows. 1.) Count the number of letters in the message M. Let this count be N. 2.) Consider the first N Fibonacci numbers (1, 2, 3, 5, 8, 13…). The numbers are in ascending order and denoted hereafter as F. The Fibonacci numbers in F are shuffled in a random order. Let this set of randomly ordered Fibonacci numbers be called R. 3.) Since the number of letters in M and the count of Fibonacci numbers in R is equal, the pair (mi, ri) is called a tuple. Here, mi is the character at index i of the message M and ri is the number at index i of the set R. 4.) Take a pair (mi, ri). Find the position of ri in the Fibonacci series F. Let this position be j. The character mi will be placed in the jth index of the intermediate output message C1. Step B) Each character in C1 is replaced by a letter some fixed number of positions (k position) down the English alphabets. For example, if k is 3, then letter 'a' becomes 'd', 'b' becomes 'e', ..., 'y' becomes 'b', 'z' becomes 'c'. The output of this step is the final encrypted message. Note: 'z' becomes 'c' (if k = 3). It wraps around in cyclic manner. Read Sample Input, Sample Output and Explanation to understand step A and B Your task is to encrypt the message M using the encryption technique described above. Note: A) Assume that the first number in Fibonacci series as 1 and the second as 2. B) Index/position in R and F starts at 0. ----------------------------------------------------------------------------------------------------------------------------- Input Format: The first line is an integer n representing the number of letters in the message M (max. of 20 letters in a sentence). The second line contains n Fibonacci numbers separated by space. (Representing R) The third line is a sentence containing only lower case English alphabets i.e. no spaces and punctuations. The fourth line is an integer representing the value of k (k varies between 0 and 25). Output Format: A single line containing the encrypted message followed by a newline ----------------------------------------------------------------------------------------------------------------------------- Sample Input: 9 34 13 2 55 3 21 1 5 8 johnisspy 5 Sample Output: xmnudtxos\n Note: \n is the newline character. Explanation: The original message is "john is spy". The message is entered without any spaces as "johnisspy". There are nine letters. The set R [34 13 2 55 3 21 1 5 8] has the first 9 Fibonacci numbers in a random order. Letter 'j' is mapped to number 34. The position of 34 in the Fibonacci series is 7. Hence, letter 'j' is placed in the 7th index of message C1. Letter 'o' is mapped to number 13. The position of 13 in the Fibonacci series is 5. Hence letter 'o' is placed in the 5th index of message C1. Similarly, every other letter is mapped. The intermediate message C1 is "shipyosjn". Each letter in C1 is replaced by a character which is five positions ahead in the alphabet (k=5). Letter 's' becomes 'x', 'h' becomes 'm', and so on. The final encrypted message is "xmnudtxos". Fibonacci Series (F) 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352 ASCII Range : 'a' – 'z' : 97 - 122 

asked Nov 26, 2016 by Srinivas
...