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

Pages: 1-4041-

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.

Name: Anonymous 2006-11-04 7:43 (sage)

>>2
You wouldn't happen to know of a standard function that does what the taketail function I wrote does?

Name: Anonymous 2006-11-04 8:42 (sage)

>>3
Doubt it. If there were one in the standard library, its definition would likely be exactly as you wrote (only more general with the types, of course).

Name: Anonymous 2006-11-04 8:43 (sage)

>>3
Ooooooor you could do something with "drop" and "length". That's just one complete pass, instead of two reverses. Not that this kind of a mickey mouse optimization matters in this case...

Name: Anonymous 2006-11-04 9:29

If n is list length and k is take length then
taketail i x = (reverse (take i (reverse x)))has a time cost of roughly n + 2k
taketail3 i x =
    let d = max 0 (length x - i)
    in drop d x
has a time cost of roughly 2n - k

Name: Anonymous 2006-11-04 10:40 (sage)

Looks like I got served thar.

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); }

Name: Anonymous 2006-11-04 11:35 (sage)

>>8
But these lack the clarity of the Haskell version. (Also, char salt[3]={0}; doesn't do what you might think it did, though the result is the same. For instance, char salt[3]={42}; would set the first element to 42 and the rest to 0.)

Name: Anonymous 2006-11-04 11:39 (sage)

Only a functional programming nut could call that code "clear" or "consice".

Name: Anonymous 2006-11-04 13:01

>>9
What?  = {0} is used to initialize arrays with zeros, nothing else.

Name: Anonymous 2006-11-04 13:04

javascript ftw.
first, include http://javascript.internet.com/passwords/javacrypt.js.
then, do this:
String.prototype.translate = function (s1, s2) {
 var o = new Object();
 for (i=0; i<s1.length; i++) o[s1[i]] = s2[i];
 var a=this;
 for (i=0; i<a.length; i++) if (o[a[i]]) a[i] = o[a[i]];
 return a;
};
alert(Javacrypt.crypt(((key=prompt('key?'))+'H..').substring(1,3).replace(/[^\.-z]/g,'.').translate(':;<=>?@[\\]^_`','ABCDEFGabcdef'),key)[0].substring(3));

Name: Anonymous 2006-11-04 14:11 (sage)

>>12
You know, code doesn't become any better the fewer newlines you use.

Name: Anonymous 2006-11-04 14:26 (sage)

>>13
Actually, it does.

Name: Anonymous 2006-11-05 0:18

>>13
the long line in >>12 is a single statement. note that there is only one ';' that isn't in a string literal, at the end of the line.

Name: Anonymous 2006-11-05 13:42 (sage)

>>15
So? Shitty code is shitty code.

Name: Anonymous 2006-11-06 0:28

>>1

"Glasgow exts"?

Why do ugly languages like Haskell and Prolog all seem to come from Scotland?  Are they really that fucking drunk as I always thought?

Name: Anonymous 2006-11-06 4:07

>>17
You gigantic retard.

Name: Anonymous 2006-11-06 16:42

shorter (and therefore obviously superior) perl version:
($s=substr(($k=shift).'H..',1))=~y/:-@[-`\0--{-/A-Ga-f./;
die substr crypt($k,$s),-10

Name: Anonymous 2006-11-06 17:51

>>19
Forget it, it's NP-complete.

Name: Anonymous 2006-11-10 13:32

Shitty obfuscated Perl is shitty obfuscated

Name: Anonymous 2006-11-10 15:01

>>21
>>19 isn't obfuscated at all...
well, except for maybe the "($s=...)=~y/..." thing... i'm not entirely sure how that part works...

Name: Anonymous 2006-11-12 5:01

[code]pop=~/(.(.*))/;($s="$2H.")=~y/:-@[-` --{-/A-Ga-f./;die substr crypt($1,$s),3[code]

Name: Anonymous 2006-11-13 4:26

>>22
See what I mean? You claim that it's not even trying to be obfuscated, and yet you're still not sure of what something does. That's Perl for you.

Naturally obfuscated Perl is naturally obfuscated.

Name: Anonymous 2006-11-15 1:34

AGE for !java

Name: Anonymous 2006-11-15 12:08

>>22
it binds $s (which is returned from the =) to the translation. please learn basic C operators.

Name: Anonymous 2006-11-15 12:12

>>1
how about you implement crypt() in haskell instead of making a 50-line implementation of "tr"?

Name: Anonymous 2006-11-15 12:17

>>27
Show me the specs ;)

Name: Anonymous 2006-11-15 13:04

Name: Anonymous 2006-11-15 16:52

>>27
Yes yes, let's all reimplement standard UNIX libc calls for every last program. That's so much more readable and has absolutely no chance at all of repeating the same bugs over and over!

Name: Anonymous 2006-11-15 18:02

Péter pue.

Name: Anonymous 2006-11-17 15:50

Perl sucks because there's a hundred ways of doing any given task.  Haskell, on the other hand, fucking rocks!!

http://www.willamette.edu/~fruehr/haskell/evolution.html

Name: Anonymous 2006-11-17 16:17

s zzs vvxv
and s ZVZchr 122Zie
and s ZVZchr 122Zie
and s ZVZchr 122Zie
and s SxSlcfirstSe
and s YZZxZYvvxvYi and print
z
and s ZVZchr 122Zie
and s ZVZchr 122Zie
and s ZVZchr 122Zie
and s SxSlcfirstSe
and s YZZxZYvvxvYi and print

Name: Anonymous 2006-11-17 16:43

lolwhat?

Name: Anonymous 2006-11-25 16:30

>>33
perl program, prints its own source code

Name: Anonymous 2006-11-25 18:52

Fuck. Somebody ought to kill Larry Wall with fire.

Now, any tips on how does that work?

Name: Anonymous 2006-11-26 2:18

Name: Anonymous 2006-11-26 12:59

This is the ultimate proof that making regexes part of the language itself is a bad idea.

Name: Anonymous 2006-11-26 13:46 (sage)

>>19,23
even shorter:
$a=$_=pop;s/./$'H./;y/:-@[-` --{-/A-Ga-f./;die substr crypt($a,$_),3or
$a=$_=pop;s/./$'H./;y/:-@[-` --{-/A-Ga-f./;crypt($a,$_)=~/.../;die$'or
$a=$_=pop;s/./$'H./;y/:-@[-` --{-/A-Ga-f./;$_=crypt$a,$_;/.../;die$'

Name: Anonymous 2006-11-26 14:10

>>39

Wow, actual proof that some people on /prog/ actually program. Awesome.

Name: Anonymous 2006-11-26 17:10 (sage)

>>40
also proof that the code tags don't work right on here. newlines right after [/code] get removed.

Name: Anonymous 2006-11-28 17:49

...NET?

Name: Anonymous 2006-12-09 14:14

Okay guys, I just learned list comprehension, and using that, I managed to turn my five line permutation function into a one-line golden masterpiece (I can't even understand the code anymore!).  How's this for concise (LOL)!!

permutate :: Eq a => [a] -> [[a]]
permutate [] = [[]]
permutate xs = [y : ys | y <- xs, ys <- (permutate (filter (/= y) xs))]


Any ideas on how I can remove the Eq dependency (/=) elegantly?  I realize you usually want to be able to distinguish elements in a permutation, but it'd still be nice.  Hmm... thinking about the code, I just figured it out!  It does ys <- for every y <-.  Nice, that explains why it works :)

Now, I want to see you C fanboys do this in 2000 lines of code!!

Name: Anonymous 2006-12-09 14:26

>>43
I just realized this doesn't work if two elements are the same... removing the Eq dependency would fix that, however.

Name: Anonymous 2006-12-09 14:54

>>43
how is this shit any better than obfuscated perl
it takes just as much effort to understand

Name: Anonymous 2006-12-09 15:09

>>45
Haskell: ePenis++
Perl: ePenis--

Also, the Haskell solution is using simple language features, what's hard to understand about the solution is the actual algorithm used... I think, at least.

Name: Anonymous 2006-12-09 15:10

Name: Anonymous 2006-12-09 15:25

>>47
Ah, how elegant, thanks!  May I think of this solution as I masturbate tonight?

Name: Anonymous 2006-12-11 14:46

>>46
CommonLisp: (1+ ePenis)

Name: Anonymous 2006-12-14 18:38

>>43
You could get rid of the Eq dependency by zipping the items on the input list with elements [1..], and then instead of having an Eq constraint on the 'a' type variable you could go with Int's Eq instance. If the caller needs the outputs to appear at most once in the output lists, s/he can just nub the input and be done with it.

Name: Anonymous 2006-12-15 20:30

Your code is incorrect. These will fail (compare to 2channel):

#><
#kami

Name: sister preggo test in python 2006-12-18 9:45

>>> def do_her():
...     question = raw_input('do you really want to do her?')
...     if question in ('y','yes','oh yes') : return True
...     if question in ('n','no','im gay') : return False
...     print 'is she pregnant?:'
...     print do_her

Name: Anonymous 2006-12-18 10:11

>>51
>>8
it's a much simplified version of the tripcode algorithm,

anyway, this language is much better than all the other crap in this thread:
function do_tripcode: dup. "2" "1" substr. "H." swap. concat. "A-Ga-f." ":-@[-` --{-" tr. crypt. "10" "3" substr.
function main: do_tripcode, print.

Name: Anonymous 2006-12-18 10:35

lol stack-based shit. welcome to 1968

Name: Anonymous 2006-12-18 11:36

>>54
uh

Name: Anonymous 2006-12-18 12:33 (sage)

>>54
Hmm... I have no idea what you are talking about, so I'll just sage to keep it off the first page.

Name: Anonymous 2007-01-02 13:59

>>53
What language is that? I googled the keywords and didn't see a good match.

Name: Anonymous 2007-01-02 17:19

>>57
Could be Factor or Joy or some other Forth-with-first-class-functions

Name: flibberdyjibbett !sJh8mwqDUo 2007-01-02 18:03

>>58
Not Joy, but wikipedia gives this Qsort written in Joy
 DEFINE qsort ==
   [small]
   []
   [uncons [>] split]
   [[swap] dip cons concat]
   binrec .

Name: Anonymous 2007-01-02 18:13

Name: Anonymous 2007-01-02 20:43

HASKELL IS A WRITE-ONLY LANGUAGE

Name: Anonymous 2007-01-03 9:57

>>61
Incorrect, code written by novices is highly readable and thus easy to refactor into god-level unreadable Haskell.

Name: Anonymous 2007-01-03 10:26

>>61
It's not unreadable until you go entirely point-free and mix in some arrows for good measure.

Name: Anonymous 2007-01-03 10:34

Haskell is shit. I shouldn't have to achieve satori just to make a short program that takes 10 minutes in C.

Name: Anonymous 2007-01-03 11:03

>>53
If you can't tell me what language that is, maybe you can tell me how to google for "dup." instead of "dup".

Name: Anonymous 2007-01-03 12:15

>>65
I searched for "function dup substr concat swap crypt" in
msn.com and the first match was this thread.

Name: Anonymous 2007-01-03 12:19

dup. execute 'dup' (duplicates the value on top of the stack) instead of pushing it onto the stack" pop.
"2" "1" substr. push '2' and then '1' onto the stack and then execute 'substr'" pop.
you should be able to figure out the rest...
as for what language it is, it doesn't have a name yet, but it does have a working compiler (currently unreleased) and about half of the standard library is written.

Name: Anonymous 2007-01-03 12:22 (sage)

oops, just ignore the '" pop.' on the end of each of those lines...
thats how you do comments in this language, i replaced the " at the beginning with [/code] and forgot to take the stuff off the end of each comment.

Name: Anonymous 2007-01-03 12:24

>>67
Did you start from scratch, or adopt another compiler?

Name: Anonymous 2007-01-03 12:30 (sage)

>>69
started from scratch... the compiler is written in perl and compiles the code to c.

Name: Anonymous 2007-01-03 12:34

>>70
OK, but but probably used some Forth interpreter for guidance. Did you find one you especially like?

Name: Anonymous 2007-01-03 13:09 (sage)

>>67
So what's with the comma and the periods?

Name: Anonymous 2007-01-03 13:46 (sage)

>>71
actually, no. i didn't even think of the similarities with forth, as i've never used forth...
>>67
oops... the comma is a typo for a period.
the period means to pop the first value off the stack and execute it if it's a function or just discard it if it's not. so the function gets pushed onto the stack and then popped off and executed. except that the compiler doesn't actually do the push and pop.
and actually i guess you could use just a period instead of " pop." for comments...

Name: Anonymous 2007-01-03 18:12

>>64
Fail.

Name: Anonymous 2011-01-31 20:07

<-- check em dubz

Name: Sgt.Kabu࠿මkiman芛颛 2012-05-28 21:00

Bringing /prog/ back to its people

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