Question: Use matlab or octave to code. DO NOT USE if statements, while or for loops, reshape commands. Only use vectors, matrices, strings, and functions. 5.


Use matlab or octave to code. DO NOT USE if statements, while or for loops, reshape commands. Only use vectors, matrices, strings, and functions.
5. (Substitution Cipher) A substitution cipher is a more complicated way to encrypt text than a Caesar cipher. The basic version of a substitution cipher converts each given character in a message by permuting the letters of the alphabet based on a fixed permutation. The permutation itself can be simply viewed as a permutation of the numbers 1 through 26. Any permutation of these numbers can easily be represented by vector of length 26 consisting of the integers from 1 to 26, each appearing exactly once. For instance, the vector [2, 3, 4, 5, 26, 1] represents the permutation that converts 1 to 2, 2 to 3, ..., 25 to 26, and 26 to 1. For this problem, you should write two separate functions: the first handles the con- version of just a single character while the second works on a string of length 3. subs_char Function: . Input Variables: a single character to be converted using the substitution cypher a permutation (as described above) to be used in the encryption Output variables: a single character of encrypted text subs_cipher Function: Input Variables: a length 3 string of lower case letters representing a short plain text message a permutation (as described above) to be used in the encryption Output variables: a length 3 string representing the results of the encryption Hint: For the subs_char function, you'll need to convert the character to a number between 1 and 26 and use this as an index in the permutation vector. A possible sample case is: represents the permutation that converts 1 to 2, 2 to 3,..., 25 to 26, and 26 to 1. For this problem, you should write two separate functions: the first handles the con- version of just a single character while the second works on a string of length 3. . subs_char Function: Input Variables: a single character to be converted using the substitution cypher a permutation (as described above) to be used in the encryption Output variables: a single character of encrypted text subs_cipher Function: Input Variables: a length 3 string of lower case letters representing a short plain text message a permutation (as described above) to be used in the encryption Output variables: a length 3 string representing the results of the encryption Hint: For the subs_char function, you'll need to convert the character to a number between 1 and 26 and use this as an index in the permutation vector. A possible sample case is: >> cchar = subs_char('a', [2:26, 1]) cchar = b >> ctext subs_cipherlabc', [ 5, 7, 1, 2:4, 6, 8:26 ]) ctext = ega >> ctext = subs_cipher ('abc', randperm(26)) ctext = gts
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
