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 11:29

Still, this has got to be the most concise expression of the tripcode algorithm I've seen yet.
it's a much simplified version of the tripcode algorithm, and it's not all that concise...
perl1:
#!/usr/bin/perl
(($salt=substr $ARGV[0].'H..',1,2)=~tr/:;<=>?@[\\]^_`/ABCDEFGabcdef/)=~s/[^\.-z]/./g;
print substr(crypt($ARGV[0],$salt),-10),"\n";

c:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <openssl/des.h>
int main(int argc, char *argv[]) {
    const char saltchars[]=":;<=>?@[\\]^_`ABCDEFGabcdef";
    char key[16]={0};
    if(argc>1) strncpy(key,argv[1],8);
    else exit(1);
    char salt[3]={0};
    char trip[11]={0};
    int i=0;
    int j;
    strncpy(salt,key+1,2);
    if(strlen(key)==2) salt[1]='H';
    if(strlen(key)<2) {
        salt[0]='H';
        salt[1]='.'; }
    if(strlen(key)==0) salt[0]='.';
    for(i=0;i<2;i++) for(j=0;j<13;j++) if(salt[i]==saltchars[j]) salt[i]=saltchars[j+13];
    if(salt[0]<'0'||salt[0]>'z') salt[0]='.';
    if(salt[1]<'0'||salt[1]>'z') salt[1]='.';
    memcpy(trip,DES_crypt(key,salt)+3,10);
    puts(trip);
    return(0); }

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