Skip to content

Instantly share code, notes, and snippets.

@314maro
Created May 24, 2013 17:33
Show Gist options
  • Save 314maro/5645143 to your computer and use it in GitHub Desktop.
Save 314maro/5645143 to your computer and use it in GitHub Desktop.
import Data.Char
import Foreign.C.String
foreign import ccall "unistd.h crypt" c_crypt :: CString -> CString -> CString
trip ('#':str) = crypt str salt >>= return . ('◆':) . reverse . take 10 . reverse
where
substr x y = take y . drop x
salt0 = substr 1 2 $ str ++ "H."
salt1 = map (\x -> if ord x < ord '.' || ord x > ord 'z' then '.' else x) salt0
table = zip ":;<=>?@[\\]^_`" "ABCDEFGabcdef"
salt = map (\x -> maybe x id $ lookup x table) salt1
crypt x y = do
x' <- newCString x
y' <- newCString y
peekCString $ c_crypt x' y'
trip _ = error "えー"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment