-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
The cipher code doesn't cycle around the letters when for example "zZ" is inputted as the string: it instead goes to the next unicode letters.
While a function using ord/chr and mods is feasible, I instead just used a recursive function that used a large number of guard blocks:
enumCipher :: String -> Int -> String
enumCipher str shift
| shift < 0 = enumCipher str (mod (26 - shift) 26)
| shift > 26 = enumCipher str (mod shift 26)
| shift == 0 = str
| otherwise = enumCipher (map shiftFunc str) (shift - 1)
where shiftFunc chr
| chr == 'z' = 'a'
| chr == 'Z' = 'A'
| otherwise = succ chr
Metadata
Metadata
Assignees
Labels
No labels