Skip to content

Instantly share code, notes, and snippets.

@astro
Created March 15, 2010 14:24
Show Gist options
  • Save astro/332872 to your computer and use it in GitHub Desktop.
Save astro/332872 to your computer and use it in GitHub Desktop.
-- |Based on http://cvs.silcnet.org/source/lib/silccrypt/silchash.c#L438
module BubblePrint where
import Data.Char (ord, chr)
import Data.Bits ((.&.), shiftR)
import Prelude hiding ((>>), (/))
(&) = (.&.)
(>>) = shiftR
(%) = mod
(/) = div
encode :: String -> String
encode = ("x" ++) . (++ "x") . encode' 1 . map ord
encode' :: Int -> [Int] -> String
encode' check [] = voc a : con b : voc c : ""
where a = check % 6
b = 16
c = check / 6
encode' check [x] = voc a : con b : voc c : ""
where a = (((x >> 6) & 3) + check) % 6
b = (x >> 2) & 15
c = ((x & 3) + (check / 6)) % 6
encode' check (x:x':xs) = voc a : con b : voc c : con d : '-' : con e : encode' check' xs
where a = (((x >> 6) & 3) + check) % 6
b = (x >> 2) & 15;
c = ((x & 3) + (check / 6)) % 6
d = (x' >> 4) & 15
e = x' & 15
check' = (check * 5 + x * 7 + x') % 36
voc :: Int -> Char
voc = ("aeiouy" !!)
con :: Int -> Char
con = ("bcdfghklmnprstvzx" !!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment