I have been tasked with the following brief, however i am unsure on specific parts of it, I am not asking for code, just guidance on how to learn how to do it myself. Thank you.
I have figured out a way to do part 1 and 2, i.e create a constructor method, and a display method, however for two permutation keys, I do not know how to combine their permutations (a row vector of length 26 cannot strictly be combined with another row vector of length 26)
Any help would be greatly appreciated.
Thank you in advanced.
Build a class to store keys. A key is any permutation of the alphabet. We will store a key internally as a permutation of the numbers 1 to 26, in a row vector of length 26, but make the display function such that it shows the corresponding letters. The identity permutation, the alphabet, is stored as the vector 1:26, and you can generate a random permutation with randperm(26). The coursework files availble on Moodle include a script tests.m with useful tests and test data. The tests use random keys, so you could run them multiple times to be extra sure.
Build a class PermutationKey that stores and handles permutation keys. It should have the following:
Properties:
• A property perm that stores a key as a permutation on the numbers 1 to 26. It should not store it as a string of letters.
Methods:
- A constructor method that takes a permutation p of the numbers 1 to 26 and creates a PermutationKey storing that permutation as its perm property.
- A display method that shows a PermutationKey as a permutation of the alphabet.
- A method mtimes(l,m) that takes two keys and gives their composition:(l ◦ m) (i) = l (m (i)) .Using the name mtimes means you can write l * m for l ◦ m.
- A method invertion(K) that gives the inverse of the key K. For every number x between 1 and 26, if K.perm(x) = y then K.invertion.perm(y) = x.
- A method encryption(k,m) that encrypts a message (a character vector) m with the key k. First, turn the message into all uppercase. Then apply the key to each uppercase letter in the message, leaving other characters (spaces, punctuation, un- derscores, etc.) as is. Make sure to convert from the ASCII indices (65–90) of the alphabet to the permutation indices (1–26) and back.
- A method decryption(k,m) that decrypts a message m with the key k, by encrypting with the inverse key.
- All these methods should be implemented in the same file PermutationKey.m