summaryrefslogtreecommitdiff
path: root/080_blog/00065_Base64-Encoder-(Haskell)
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2019-02-19 12:25:40 +0100
committerMiguel <m.i@gmx.at>2019-02-19 12:25:40 +0100
commit5c530e67256f8ecbd93336ba4e876acbba73f716 (patch)
tree7744eed3a34d0a7c3ca6deddd71a02801858a767 /080_blog/00065_Base64-Encoder-(Haskell)
parentb71633cad69d0b8fade8419cfd7a333615ad3aee (diff)
cleaning up more..
Diffstat (limited to '080_blog/00065_Base64-Encoder-(Haskell)')
-rw-r--r--080_blog/00065_Base64-Encoder-(Haskell)/index.md51
1 files changed, 0 insertions, 51 deletions
diff --git a/080_blog/00065_Base64-Encoder-(Haskell)/index.md b/080_blog/00065_Base64-Encoder-(Haskell)/index.md
deleted file mode 100644
index 830ed8d..0000000
--- a/080_blog/00065_Base64-Encoder-(Haskell)/index.md
+++ /dev/null
@@ -1,51 +0,0 @@
-Miguel's Naive Base64 Encoder
-==============================
- February 19, 2018
-
-Coded on a winter afterfnoon on 19th Feb 2018 A.D. to fully understand
-base64 encoding and play with haskell, which is always an indisputable
-pleasure.
-
-The following lines were written in full awareness that 'libraries' for
-this very purpose, which perform way better, are in existence.
-
-Coded in big anger due to nick's stories about saving his binary format,
-encrypted passwords in an ascii config file, featuring
-strange letters and characters.
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.haskell .numberLines}
--- File: base64.hs --
-
-import Data.Char
-import Text.Printf
-import qualified Data.List as L
-import qualified Data.List.Split as T
-
-toBase64 x = maskBase64 x . toBase64core . asciiToBin . binFill $ x
-toBase64core = map base64toDigit . map binToDec . T.chunksOf 6
-
-base64toDigit x = (['A'..'Z']++['a'..'z']++['0'..'9']++['+','/']) !! x
-binToDec = sum . map (2^) . L.findIndices (=='1') . reverse
-asciiToBin = concat . map (\y -> printf "%08b" y) . map ord
-binFill x = x ++ (take (fill64length x) $ cycle "\000")
-
-maskBase64 o x = take (length x - l ) x ++ (take l $ cycle "=")
- where l = (fill64length o)
-
-fill64length x | m==0 = 0
- | otherwise = 3-m
- where m=mod (length x) 3
-
-main = do
- line <- getLine
- putStrLn $ toBase64 line
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Example usage, with decoding via `base64 -d`
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.bash}
-miguel@megaloman:~$ echo -n "secret haskell" | runghc base64.hs
-c2VjcmV0IGhhc2tlbGw=
-miguel@megaloman:~$ echo -n "c2VjcmV0IGhhc2tlbGw=" | base64 -d # decode to check
-secret haskell
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~