Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell

Name: Anonymous 2006-11-04 7:02

ghc -fglasgow-exts -lcrypt trip.hs
% ./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))

Name: Anonymous 2006-11-04 7:12

Real men would do without unsafePerformIO. Plus your indent style gives me hives.

Still, this has got to be the most concise expression of the tripcode algorithm I've seen yet.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List