Hello, factor-talk!
I am new to Factor, but love it more than any programming language I've learned
to date.
I just write an implementation of the RC4 cryptography algorithm. After
setting up the initial key schedule, I have a word called "next-byte" that
takes an <arc4> object and provides the next byte in an infinite sequence of
pseudo-random bytes and advances the <arc4> object's internal stream counters.
A second word, "cipher", takes a string of plaintext an an <arc4> object and
returns the ciphertext, which is the result of bitxor-ing the characters of the
string with the bytes from the pseudo-random sequence.[1]
Now, coming from other languages, I immediately though, "Aha! I should write
an RC4 input stream that stores an <arc4> and another input stream and, when
read from, outputs the ciphertext." Something like:
TUPLE: arc4-reader arc4 reader ;
M: stream-read1 … ; #! read one from underlying stream, then bitxor with the
next byte from the <arc4>
M: stream-read … ; #! implemented in terms of stream-read1
#! … further implementations of stream methods
As I started doing that, though, I got lost trying to implement the different
stream words. Maybe I needed to use the 'locals' vocab to simplify my
approach, but I ended up sinking several hours into what I thought would be a
small change. I even looked for an "infinite sequence" object to wrap around
an <arc4> and pass to >sequence-reader<, but it turns out that sequences have
to know their lengths, so that's right out.
In any case, I abandoned that branch of the project and just made a "cipher"
word which operates on strings.
But, in the back of my mind, there was this nagging question: "isn't decorating
a stream a common pattern?" If I were to encipher a big chunk of binary,
passing it around as a byte array doesn't seem like the best idea. Digging
deeper (thanks, awesome help browser!) it looks like the "compression"
vocabulary operates on byte arrays, not streams, which is surprising to me
having worked in Java, which has "GzipInput" and "GzipOutput" streams.
In the same vein, does Furnace handle gzip-compressed responses? Should it, or
should that be handled by an upstream proxy?
I'm on the verge of writing a stream-wrappers vocabulary to handle this kind of
approach, but I wanted to explain the problem as I see it to the list and see
if I've just missed something totally essential about how Factor works. Thanks
for making this language great!
best,
- Fred Alger.
[1] Code from my latest check-in is available here:
http://arc4.fredalger.net/vinfo?name=dfc1c064950859c3d6e8ee2e13e4d029970bba8d
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk