February 2025

S M T W T F S
      1
23456 78
9101112131415
16171819202122
232425262728 

Style Credit

Expand Cut Tags

No cut tags
Saturday, August 6th, 2005 01:49 pm
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!
Tags:
Friday, August 19th, 2005 06:32 am (UTC)
Thank you! This will come in handy as a writing tool, as well as simply something fun to play with.
Friday, August 19th, 2005 12:43 pm (UTC)
You're welcome!

By the way, the Chipmunk Basic software (http://www.nicholson.com/rhn/basic/) which I used to write the program is available online at the link. Needless to say, the code is pretty clear anyway, and probably easy to translate; if you do so, I'd like to know so I can link it.
Friday, August 19th, 2005 08:47 pm (UTC)
Actually, all I had to do was walk it over to our office photo tech, who's got Visual Basic on his machine. One copy and paste later (and a little tweaking so that it would no longer change characters into ASCII 0-32 control codes and occasionally EOF the string), a window with an input and output text box, and I had a cute little Windows executable inside of 15 minutes. Let me know if you want a copy of that.
Friday, August 19th, 2005 09:54 pm (UTC)
Ah! That sounds very nice, thank you and your friend! I don't have Visual Basic or Windows (iBook G4 right here), but I'd like to post that code anyway, if you (and he) don't mind. It sounds like that version is rather more useful than mine in any case, if for no other reason than that Visual Basic is Popular and Chipmunk Basic is Not. It's probably easier to recode for whole file I/O as well, which is a feature I thought would be convenient too.