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

A c program to in strings using functions

Step A) Rearranging the letter stored in M as outlined below. Let the output of this step be message C 1
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 (m i , r i ) is
called a tuple. Here, m i is the character at index i of the message M and r i is the number at index i of the set
4.) Take a pair (m i , r i ). Find the position of r i in the Fibonacci series F. Let this position be j. The character
m i will be placed in the j th index of the intermediate output message C 1 .Step B) Each character in C 1 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.
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
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:
34 13 2 55 3 21 1 5 8
Sample Output:
Note: \n is the newline character.
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 7 th index of message C 1 . Letter 'o' is mapped to number 13. The position of 13 in the Fibonacci series
is 5. Hence letter 'o' is placed in the 5 th index of message C 1 . Similarly, every other letter is mapped. The
intermediate message C 1 is "shipyosjn".Each letter in C 1 is replaced by a character which




asked Nov 26, 2016 by Srinivas