2021-05-19 11:48:56 +03:00

44 lines
1.2 KiB
Haskell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module Main where
import Data.Bits
import Data.Char
import Data.List
import Data.Maybe
{-
- https://kmb.cybber.ru/crypto/frequency_analysis_substitution/main.html
- Здесь будет конвертатор в base32/64
- Шифр цезаря
- Шифр простой замены
- Шифр Атбаша
-}
-- Шифр Атбаша. Простой шифр с заменой алфавита
-- a = e, r=d и т.д.
atbashEnc :: String -> String
atbashEnc input = do
let alp = ['a'..'z']
let encAlp = "qadewsrgfthuyjkiolpzcxvnbm"
map (\x -> encAlp !! (fromJust (elemIndex x alp))) input
-- Декодер
atbashDec :: String -> String
atbashDec input = do
let alp = ['a'..'z']
let encAlp = "qadewsrgfthuyjkiolpzcxvnbm"
map (\x -> alp !! (fromJust (elemIndex x encAlp))) input
-- Простейший шифр, просто сдвигает алфавит на 1
-- a = b, b = c, ...
simpliestEnc :: String -> String
simpliestEnc input =
map (\x -> chr(ord(x) + 1)) input
main :: IO ()
main = do
putStrLn "Simpliest encoding, just +1 to each letter:"
print (simpliestEnc "abcdefz")
putStrLn "atbash Encryption:"
print . atbashEnc $ "test"
print . atbashDec $ ( atbashEnc "test" )