Question: There are many algorithms that can be used to encrypt a message. One of these algorithms can be described as follows: Choose a code word.



There are many algorithms that can be used to encrypt a message. One of these algorithms can be described as follows: Choose a "code word. For example, "fortran. Assign integer values to each of the characters in the code word corre- sponding to their placement in the alphabet. In the case of the code word fortran, the integer values would be (6, 15, 18, 20, 18, 1, 14). Change each character in the message to be encrypted by adding the code word values determined above (in order) to each of the characters in the message to be encrypted. The code word is reused as many times as necessary. For example, suppose that we want to encrypt the message hello, we would first determine the integer values for each character in the message (8, 5, 12, 12, 15). Each of these values would be modified by adding the code word va ie. (8+6, 5+15, 12+18, 12+20, 15+18) = (14, 20, 30, 32, 33). The resulting values are then translated back to character values, using circular addition (ie. 33 would refer to the 7th letter of the alphabet). So the message hello would be encrypted as ntdfg. If there are spaces in the input message, they are assigned a value of 0. For example, using the fortran code word, hello there would be encrypted using (8+6, 5+15, 12+18, 12+20, 15+18, 0+1, 20+14, 8+6, 5+15, 18+18, 5+20) = (14, 20, 4, 6, 7, 1, 8, 14, 20, 10, 25), corresponding to ntdfgahntjy. The encrypted form of the message is usually broken up into equal length "words. For example, using a word length of 6, the above encrypted message would be ntdfga hntjy. Write a Fortran program to read in a code word, the encrypted word length, and a message to be encrypted, and output the encrypted form. Note that your code can be limited to only lowercase messages. Your program should make use of allocatable arrays. 2. When you have your encryption code working, move it into a function that is contained within a module. The module should contain variables for the code word and the "word length. Use your main program to test your module. 3. Add a function to your module to decrypt a message that has been encrypted as above. Test your decryption function within your main program. The following may be useful for this question: A section of a string can be extracted by specifying start and end indices. For example, if word is a string variable, then word(1:3) is the first 3 characters of The following may be useful for this question: A section of a string can be extracted by specifying start and end indices. For example, if word is a string variable, then word(1:3) is the first 3 characters of word. 1 O Returns the length of a character string, ignoring any LEN_TRIM(string) trailing blanks. IACHAR(C) returns the code for the ASCII character in the first character position of C. ACHAR(I) - returns the character located at position I in the ASCII sequence. There are many algorithms that can be used to encrypt a message. One of these algorithms can be described as follows: Choose a "code word. For example, "fortran. Assign integer values to each of the characters in the code word corre- sponding to their placement in the alphabet. In the case of the code word fortran, the integer values would be (6, 15, 18, 20, 18, 1, 14). Change each character in the message to be encrypted by adding the code word values determined above (in order) to each of the characters in the message to be encrypted. The code word is reused as many times as necessary. For example, suppose that we want to encrypt the message hello, we would first determine the integer values for each character in the message (8, 5, 12, 12, 15). Each of these values would be modified by adding the code word va ie. (8+6, 5+15, 12+18, 12+20, 15+18) = (14, 20, 30, 32, 33). The resulting values are then translated back to character values, using circular addition (ie. 33 would refer to the 7th letter of the alphabet). So the message hello would be encrypted as ntdfg. If there are spaces in the input message, they are assigned a value of 0. For example, using the fortran code word, hello there would be encrypted using (8+6, 5+15, 12+18, 12+20, 15+18, 0+1, 20+14, 8+6, 5+15, 18+18, 5+20) = (14, 20, 4, 6, 7, 1, 8, 14, 20, 10, 25), corresponding to ntdfgahntjy. The encrypted form of the message is usually broken up into equal length "words. For example, using a word length of 6, the above encrypted message would be ntdfga hntjy. Write a Fortran program to read in a code word, the encrypted word length, and a message to be encrypted, and output the encrypted form. Note that your code can be limited to only lowercase messages. Your program should make use of allocatable arrays. 2. When you have your encryption code working, move it into a function that is contained within a module. The module should contain variables for the code word and the "word length. Use your main program to test your module. 3. Add a function to your module to decrypt a message that has been encrypted as above. Test your decryption function within your main program. The following may be useful for this question: A section of a string can be extracted by specifying start and end indices. For example, if word is a string variable, then word(1:3) is the first 3 characters of The following may be useful for this question: A section of a string can be extracted by specifying start and end indices. For example, if word is a string variable, then word(1:3) is the first 3 characters of word. 1 O Returns the length of a character string, ignoring any LEN_TRIM(string) trailing blanks. IACHAR(C) returns the code for the ASCII character in the first character position of C. ACHAR(I) - returns the character located at position I in the ASCII sequence
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
