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

Pages: 1-

Challenge

Name: Anonymous 2009-06-16 10:40

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: Anonymous 2009-06-16 10:47

wins what?

Name: Anonymous 2009-06-16 11:10

>>2
You'll have the honor of having your code sent to a professor for grading.

Name: Anonymous 2009-06-16 11:38

He didn't specify a language

Name: Anonymous 2009-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.

xrange -> range doesn't count

Name: Anonymous 2009-06-16 13:01

>>4
Yes, he did: http://dis.4chan.org/read/prog/1245090210/
It'd be nice if he got implementations in plenty of languages, except C.

Name: Anonymous 2009-06-16 15:55

XOR isn't a real encryption.

Name: Anonymous 2009-06-16 16:01

>>7
Depends on what you XOR with. OTP

Name: Anonymous 2009-06-16 16:27

>>5
Terrible! What have you done to Python?

Name: Anonymous 2009-06-16 17:43

>>9
At least Python's digestive tract still works, it can digest things such as dead dogs.

Name: Anonymous 2009-06-16 17:59

>>8
Most stream ciphers and some block cipher modes use XOR too. There's nothing inherently wrong with it.

Name: Anonymous 2009-06-17 2:15

But he isn't using anything resembling a key. Its not XOR.

Name: Anonymous 2009-06-17 8:34

>>12
What does resembling a key have to do with XOR?

Name: Anonymous 2009-06-17 8:54

>>13
What about XOR gay?

Name: Anonymous 2009-06-17 9:16

>>14
Back to /b/, please.

Name: Anonymous 2011-02-04 19:18

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