packbat: A bat wearing a big asexual-flag (black-gray-white-purple) backpack. (Half-Face)
packbat ([personal profile] packbat) wrote2005-08-06 01:49 pm
Entry tags:

Rand/m line noise geneba4or

I was chatting with [livejournal.com profile] nanakikun about his Coded Arms fic, and the negative reaction to the l33t he used to represent data corruption. He asked how else he should represent signal noise. We got an idea. I was delegated to execute it.

A few hours later, the first draft of a ChipmunkBasic random line noise generator was born.


10 ' Line Noise Simulator v0.1 - Robin Zimmermann 2005 Aug 6
20 ' p2s(n) = 2^(n-1)
30 dim p2s(8)
40 for i = 1 to 8
50 p2s(i) = 2^(i-1)
60 next i
70 ' Optional random number seed input
80 input "Input random number seed (y/n)? ",a$
90 if left$(a$,1) = "y"
100 input "Random number seed: ",n
110 randomize n
120 endif
130 ' choose input/output protocol
135 print
140 print "1: Line input conversion"
150 print "2: File input conversion (not yet implemented)"
160 print "3: Character input realtime conversion (not yet implemented)"
170 ' Insert new conversion types here.
180 print "99: Exit program."
190 print
200 input "Enter code for desired conversion type: ",n
210 print
220 select case n
230  case 1
240 goto 1000
250  case 2,3
260 print "That type does not exist, please choose another."
270 print
280 goto 140
290 case 99
300 print "Goodbye."
310 end
320 case else 
330 print "That is an illegial input.  Please try again."
340 print
350 goto 140
360 end select
1000 ' Input noise level
1010 input "Percentage of bits to be corrupted: ",percent
1020 rate = percent/100
1022 if rate >= 0.5 then goto 1010
1030 x = 100*(1-(1-rate)^8)
1040 print
1050 print "This will correspond to ";str$(x);" % of bytes (characters) corrupted."
1060 input "Is this acceptable (y/n) ? ",a$
1070 print
1080 if left$(a$,1) = "y" then goto 1100
1090 goto 1010
1100 ' Input/Output Loop
1110 egg$ = "Input plaintext to be scrambled.  Input a blank line to exit."
1111 ' Ignore this line.  It only exists because of its cardinal.
1112 ' 1113, however, initializes output variable omelette$
1113 omelette$ = ""
1120 while not egg$ = ""
1130 for i = 1 to len(egg$)
1140 egg = asc(mid$(egg$,i,1))
1150 ' egg = current character.  Now to loop over the bits.
1160 for j = 1 to 8
1170 beat = rnd(1)
1180 ' beat chooses whether to flip current bit
1190 if beat <= rate then let egg = egg xor p2s(j)
1200 ' egg xor p2s(j) flips bit j
1210 next j
1220 omelette$ = omelette$+chr$(egg)
1230 next i
1240 print
1250 print omelette$
1260 print
1270 input egg$
1280 omelette$ = ""
1290 wend
1300 goto 140



I have found that error rate percentages between 1 and 2 percent yield output that is readable, but clearly damaged. The ovumate metaphors in the variable names at the end are completely meaningless, of course.

And, just for fun, my Creative Commons license for those who wish to use this code:



Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.






EnÍoy yous ne!r-incomprelwible-duemto-damagE text generatiof!

Post a comment in response:

If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org