1. Define a function: vigenere :: String -> (String -> String, String -> String).
such that vigenere key returns a pair of functions which respectively encrypt and decrypt strings using the Vigenère cipher with key as the key.
For a description of the Vigenère cipher, see the Wikipedia page. Your implementation should convert all lower case letters in the key and in the input strings to upper case, and remove all non-alphabetic characters and whitespace.
Copyright By PowCoder代写 加微信 powcoder
2.As a polyalphabetic subsitution cipher, Vigenère is vulnerable to frequency analysis if the length of the key is known. If the key length is given by n, we can construct n separate frequency lists for a given ciphertext: the first for the 1st, n+1th, 2n+1th… characters, the second for the 2nd, n+2th, 2n+2th… characters, and so on.
Define a function: frequency :: Int -> String -> [[(Char, Int)]]
such that frequency n ct returns a list of n frequency lists for the characters in ct.
Each frequency list comprises a list of pairs of type (Char, Int) that records the number of times that each character appears. Only include characters that appear at least once. Frequency lists are sorted in order of decreasing frequency. If there are two characters with the same frequency, their entries should appear in alphabetical order.
You should assume that the ciphertext ct given as input to frequency contains only characters in the range A-Z.
3.We can represent a maze on a rectangular grid as a list of paths. Each path consists of a pair of coordinates which are the ends of the path, where a coordinate is a pair of non-negative integers (x, y). All paths run either horizontally (same y-value for both ends) or vertically (same x-value for both ends). The order of the ends of a paths is not important; the path ((0, 2), (2, 2)) is equivalent to the path ((2, 2), (0, 2)). Similarly, the order of the paths in the maze is unimportant.
Write a function: renderMaze :: [((Integer, Integer), (Integer, Integer))] -> [String]
which renders the maze row-by-row as a list of strings. Each character in each string represents a coordinate within the maze. If a path is present at that coordinate, the character should be a hash symbol #. If a path is not present, the character should be a space.
For example, if we have defined:
maze = [((0,0),(0,3)), ((0,2),(2,2)), ((2,1),(4,1)),
((4,0),(4,2)), ((4,2),(5,2)), ((2,1),(2,5)),
((1,5),(4,5))]
then renderMaze maze should return:
[“# # “,
The grid in the rendering should run from (0,0) in the top left corner to (maxX,maxY) in the bottom right, where maxX and maxY are the largest x and y values to appear in any path in the maze.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com