Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i want code in haskell not pyhton 18. The Haskell built-in functions fromEnum and toEnum can be used to convert Chars to Ints and vice

image text in transcribed

i want code in haskell not pyhton

18. The Haskell built-in functions fromEnum and toEnum can be used to convert Chars to Ints and vice versa respectively. For example, fromEnum ' a ' returns 97 , fromEnum ' b ' returns 98 , etc., all the way to fromEnum ' z ' which returns 122 (that is, 97+25 ). Similarly, toEnum 97 returns ' a ', toEnum 98 returns ' b ' etc. a) Write a Haskell function, shift (k,v), using fromEnum and toEnum, that takes a pair consisting of an Int k and a lower-case Char v as arguments, and returns a lower-case Char which is obtained by circularly shifting the input Char vk times to the right using the 26-character English alphabet: abcdefghijklmnopqrstuvwxyz. E.g., *Main> shift (3,a) 'd' *Main> shift (3, 'y') 'b' You may want to use the library function mod, which outputs its first argument modulo its second argument (in other words, the remainder of the first argument divided by the second argument). E.g., *Main> mod 163 1 Main> mod 173 2 b) Use shift (k, v) (even if you couldn't write it correctly, in part a. above, you can still use it for the rest of this question) to write another function CipherEncode sk that takes two same length arguments, a string and a list of integers, and produces a new string consisting of the elements of the input string each shifted to the right circularly by the times specified by the corresponding elements of the list argument (the input string must contain lower case characters only). E.g., CipherEncode "ab" [2,3] should generate "ce" as the output. c) Write another function CipherDecode sk that takes two same length arguments, a string and a list of integers, and produces a new string consisting of the elements of the input string shifted to the left circularly by the times specified by the corresponding elements of the list argument (again the input string must contain lower case characters only.) You may consider using the negate function that changes the sign of an integer argument

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions