main :: IO ()
main = do
  args <- getArgs
  let (opts, _, _) = getOpt Permute flags args
  let opts' = M.fromList $ fmap (\a -> (tokey a, a)) opts
  let lookupOpts = flip M.lookup opts'
  input <- getInput
  run (lookupOpts "d" <|> lookupOpts "e") (lookupOpts "k") input
  where
    getInput = do
      c <- hGetChar stdin
      if c == '\n'
        then return []
        else (c:) <$> getInput
    -- getInput = getLine
    run (Just Encrypt) (Just (Key key)) input = putStrLn $ encrypt key input
    run (Just Decrypt) (Just (Key key)) input = putStrLn $ decrypt key input
    run _              _                _     = die "please use this software correctly."
main :: IO ()
main = do
  args <- getArgs
  let (opts, _, _) = getOpt Permute flags args
  let opts' = M.fromList $ fmap (\a -> (tokey a, a)) opts
  let lookupOpts = flip M.lookup opts'
  input <- getInput
  run (lookupOpts "d" <|> lookupOpts "e") (lookupOpts "k") input
  where
    getInput = do
      c <- hGetChar stdin
      if c == '\n'
        then return []
        else (c:) <$> getInput
    -- getInput = getLine
    run (Just Encrypt) (Just (Key key)) input = putStrLn $ encrypt key input
    run (Just Decrypt) (Just (Key key)) input = putStrLn $ decrypt key input
    run _              _                _     = die "please use this software correctly."
main = do
  args <- getArgs
  let (opts, _, _) = getOpt Permute flags args
  let opts' = M.fromList $ fmap (\a -> (tokey a, a)) opts
  let lookupOpts = flip M.lookup opts'
  input <- getInput
  run (lookupOpts "d" <|> lookupOpts "e") (lookupOpts "k") input
  where
    getInput = do
      c <- hGetChar stdin
      if c == '\n'
        then return []
        else (c:) <$> getInput
    -- getInput = getLine
    run (Just Encrypt) (Just (Key key)) input = putStrLn $ encrypt key input
    run (Just Decrypt) (Just (Key key)) input = putStrLn $ decrypt key input
    run _              _                _     = die "please use this software correctly."