Name: Anonymous 2006-11-04 7:02
ghc -fglasgow-exts -lcrypt trip.hs
% ./a.out faggot
Ep8pui8Vw2
fap fap fap
% ./a.out faggot
Ep8pui8Vw2
fap fap fap
module Main where
import Data.Char
import Foreign.C.String
import System.Environment
import System.IO.Unsafe
foreign import ccall "crypt.h crypt" c_crypt :: CString -> CString -> IO CString
crypt :: String -> String -> String
crypt key salt =
taketail 10 $
unsafePerformIO $ peekCString $
unsafePerformIO $
withCString key $ \k ->
withCString salt $ \s ->
c_crypt k s
where
taketail :: Int -> [a] -> [a]
taketail i x = (reverse (take i (reverse x)))
makesalt :: String -> String
makesalt x =
map
fixsalt
(take 2
(if (length x) < 2 then ("H.") else (tail x)))
where
fixsalt :: Char -> Char
fixsalt c
| (inrange '0' '9' c) = c
| (inrange ':' '@' c) = (chr ((ord c) + 7))
| (inrange 'A' 'Z' c) = c
| (inrange '[' '`' c) = (chr ((ord c) + 6))
| (inrange 'a' 'z' c) = c
| c == '/' || c == '.' = c
| otherwise = '.'
where
inrange :: Ord a => a -> a -> a -> Bool
inrange low upp x = x >= low && x <= upp
tripcode :: String -> String
tripcode s = crypt s (makesalt s)
main :: IO ()
main = do
args <- getArgs
putStrLn (tripcode (head args))