Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ciphers #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add Rot13 cipher
tredontho committed Oct 3, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit f7b7898d81051c6194f323f6a93dc25b4c443fde
16 changes: 16 additions & 0 deletions src/Ciphers/Rot13.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Ciphers.Rot13 where

import Data.Char (isAsciiLower, isAsciiUpper)

-- See https://en.wikipedia.org/wiki/ROT13

-- | "Rotates" each character in a string by 13.
-- Note: This only rotates alphabetic characters, any other character is left
-- as-is
dencrypt :: String -> String
dencrypt = map rotate

rotate :: Char -> Char
rotate c | isAsciiLower c = ([c..'z'] ++ ['a'..'z']) !! 13
| isAsciiUpper c = ([c..'Z'] ++ ['A'..'Z']) !! 13
| otherwise = c