#cemetech wrote:
[23:09:39] <+comic> Jonimus, wob comic wasn't a typo for wb? :O
[23:09:53] <+Jonimus> nope
[23:10:00] <+Jonimus> it was a corruption of web
[23:10:27] * IkariTari randomly flips bits in Jonimus
[23:11:10] <+Jonimus> now I want to right something to do that to ASCII and print the result
[23:11:20] <+Cathy> RIGHT?
[23:11:21] <+Jonimus> but lazy
[23:11:50] < IkariTari> let's see how fast I can do it
[23:11:53] * Cathy rights Jonimus' wrong
[23:12:11] <+Jonimus> lol both of you are doing it.
[23:12:20] <+Jonimus> I would think C would be a good choice there.
[23:09:53] <+Jonimus> nope
[23:10:00] <+Jonimus> it was a corruption of web
[23:10:27] * IkariTari randomly flips bits in Jonimus
[23:11:10] <+Jonimus> now I want to right something to do that to ASCII and print the result
[23:11:20] <+Cathy> RIGHT?
[23:11:21] <+Jonimus> but lazy
[23:11:50] < IkariTari> let's see how fast I can do it
[23:11:53] * Cathy rights Jonimus' wrong
[23:12:11] <+Jonimus> lol both of you are doing it.
[23:12:20] <+Jonimus> I would think C would be a good choice there.
Because it sounded like a quick lark, I went ahead and wrote a program (in Python) that can be used to randomly corrupt a file. Pass it the names of files to corrupt on the command line, and it does so.
Code:
import mmap, sys, random, os
for f in sys.argv[1:]:
target = open(f,'rb+')
buffer = mmap.mmap(target.fileno(), 0)
# flip 1% of the bits
flip_ratio = .01
file_size = os.stat(f).st_size
for _ in range(int(file_size * flip_ratio)):
idx = random.randint(0, (file_size * 8) - 1)
c = ord(buffer[idx / 8])
c ^= 1 << (idx % 8)
buffer[idx / 8] = chr(c)
buffer.close()
target.close()
I tested this on a file containing the following text:
Quote:
Jonimus was here.
durr hurr
And got the following out (with flip_ratio at .1 so it doesn't do nothing):durr hurr
Quote:
Bonimus was here.
durr iurr
durr iurr
This seemed amusing, so I made a thread. Dunno if there's actually anything to say about it.