Write an encryption and decryption program which would
Read file A and use its contents as bitstring which would
be input for this transformation(Its XOR btw), assuming the initial "previous bit" as 0:
If previous bit is equal to next bit write 0 into File B, else write 1 into File B.
The decryption program must take File B and produce File A.
Whoever does it in least characters wins.
Name:
Anonymous2009-06-16 10:47
wins what?
Name:
Anonymous2009-06-16 11:10
>>2
You'll have the honor of having your code sent to a professor for grading.
Name:
Anonymous2009-06-16 11:38
He didn't specify a language
Name:
Anonymous2009-06-16 12:13
Don't start all your homework threads with "Challenge".
Anyway, encoder:
import sys,array
p=0;f=array.array('B',sys.stdin.read())
for i in xrange(len(f)*8):
if f[i/8]>>(i&7)&1==p:f[i/8]&=~(1<<(i&7))
else:f[i/8]|=1<<(i&7);p=p+1&1
f.tofile(sys.stdout)
Decoder:
import sys,array
p=0;f=array.array('B',sys.stdin.read())
for i in xrange(len(f)*8):
if f[i/8]>>(i&7)&1:p=~p
if p:f[i/8]|=1<<(i&7)
else:f[i/8]&=~(1<<(i&7))
f.tofile(sys.stdout)
Both are exactly 178 bytes, which makes me feel kind of good about it :). It's not a winning entry by any means, but I'd appreciate if some Guido's bitch could show me how to do this better (as in smaller), as I'm pretty new to this language.