Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cbcEncrypt :: Char -> Char -> String -> String
- cbcEncrypt k iv plainText = generateCypher plainTextLength
- where
- plainTextLength = length plainText
- generateCypher :: Int -> String
- -- Generate the cypher text based on length of the plain text
- -- Function uses the CBC model defined as
- -- c_1 = (x_1 + iv) + k
- -- c_i = (x_i + c_(i-1)) + k for 1 < i ≤ l
- -- where "+" reffers to the addition operation defined in the add Haskell
- -- function and x is the plain text string
- generateCypher 0 = []
- generateCypher currentIndex
- | currentIndex == 1
- = [add (add currentEl iv) k]
- | otherwise
- = previousList ++ [add (add currentEl previousListLastEl) k]
- where
- currentEl = plainText !! (currentIndex - 1)
- previousList = generateCypher (currentIndex - 1)
- previousListLastEl = previousList !! (length previousList - 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement