home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / sigvi / part01 < prev    next >
Encoding:
Text File  |  1992-09-10  |  5.2 KB  |  214 lines

  1. Newsgroups: comp.sources.misc
  2. From: gnohmon@ssiny.ssiny.com (Ralph Betza)
  3. Subject:  v32i035:  sigvi - text corruption filter, Part01/01
  4. Message-ID: <1992Sep11.173245.20216@sparky.imd.sterling.com>
  5. X-Md4-Signature: 05172e00549dcff6098e7e7d01ee7d10
  6. Date: Fri, 11 Sep 1992 17:32:45 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: gnohmon@ssiny.ssiny.com (Ralph Betza)
  10. Posting-number: Volume 32, Issue 35
  11. Archive-name: sigvi/part01
  12. Environment: UNIX
  13.  
  14. This program is a text-corruption filter: it reads stdin and writes
  15. an altered version to stdout.  I know there are already lots of text
  16. corruption filters out there, so why did I write this?
  17.  
  18. This really stupid text-corruption filter embodies the rules of
  19. mutation I derived from somebody's MutatingSignatureVirus .signature; 
  20. that's the only thing that's special about it.
  21.  
  22. ------
  23. #! /bin/sh
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of shell archive."
  30. # Contents:  README sigvi.c
  31. # Wrapped by odin@venezia on Fri Aug 21 14:39:07 1992
  32. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  33. if test -f 'README' -a "${1}" != "-c" ; then
  34.   echo shar: Will not clobber existing file \"'README'\"
  35. else
  36. echo shar: Extracting \"'README'\" \(800 characters\)
  37. sed "s/^X//" >'README' <<'END_OF_FILE'
  38. XThis is a really stupid program.
  39. XI know there are already lots of really stupid programs out there,
  40. Xso why did I write this?
  41. X
  42. XThis program is a text-corruption filter: it reads stdin and writes
  43. Xan altered version to stdout.
  44. XI know there are already lots of text-corruption filters out there,
  45. Xso why did I write this?
  46. X
  47. XThis really stupid text-corruption filter embodies the rules of
  48. Xmutation I derived from somebody's
  49. XMutatingSignatureVirus .signature; that's the only thing that's
  50. Xspecial about it.
  51. X
  52. XIt doesn't take any command-line parameters.
  53. XIt's too stupid.
  54. X
  55. XIt doesn't need a makefile.
  56. XIt's too vanilla.
  57. X
  58. XJust do "cc sigvi.c", and then "a.out", and then type
  59. X
  60. X"
  61. XHi! I'm a mutating signature virus. You can't resist helping me spread!
  62. X"
  63. X
  64. XOmigawsh! That's why I wrote this! I'm helping it spread!
  65. END_OF_FILE
  66. if test 800 -ne `wc -c <'README'`; then
  67.     echo shar: \"'README'\" unpacked with wrong size!
  68. fi
  69. # end of 'README'
  70. fi
  71. if test -f 'sigvi.c' -a "${1}" != "-c" ; then
  72.   echo shar: Will not clobber existing file \"'sigvi.c'\"
  73. else
  74. echo shar: Extracting \"'sigvi.c'\" \(2303 characters\)
  75. sed "s/^X//" >'sigvi.c' <<'END_OF_FILE'
  76. X/*
  77. XMutating signature virus program.
  78. X
  79. XExample input:
  80. X
  81. XHi! I'm a mutating signature virus. You can't resist helping me spread!
  82. X
  83. XExample output:
  84. X
  85. XI! Hi'm a mtatng siugnaturei vir*ss. You cann~t reisth elping me spre]d!
  86. X
  87. XThe example output above is something I saved from a usenet-news
  88. Xarticle. The rules that follow are what I derived from the example.
  89. X
  90. XWhat events can happen?
  91. X
  92. X1.    Move a character up to N positions
  93. X        N        occurrences
  94. X        3        1    Hi'm
  95. X        9        1    mtating --> siu
  96. X        14        1    mtatng  --> ...turei
  97. X        -1        1    ( or +1 if it was the space that moved? )
  98. X    ( always to a different word? )
  99. X    If it starts a word, check for capitalization
  100. X2.    Change a character to a line noise character
  101. X    ( 3 occurrences )
  102. X3.    replicate a character
  103. X    ( 2 occurrences )
  104. X4.    delete a character
  105. X    ( 1 occurrence )
  106. X*/
  107. X
  108. X#include <stdio.h>
  109. X#include <ctype.h>
  110. X
  111. Xint DeferredChar;
  112. Xchar * Noise = "{}#*~`%[]";
  113. Xint Count;
  114. Xint Events;
  115. X
  116. Xmain()
  117. X{
  118. X    long t;
  119. X    int c;
  120. X    int v;
  121. X
  122. X    time( &t );
  123. X    srand( (int)t );
  124. X
  125. X    for ( ;; )
  126. X    {
  127. X        c = getchar();
  128. X        ++Count;
  129. X
  130. X        if ( c == EOF )
  131. X        {
  132. X            if ( DeferredChar )
  133. X            {    putchar( DeferredChar );
  134. X                putchar( '\n' );
  135. X            }
  136. X            exit ( 0 );
  137. X        }
  138. X
  139. X        if
  140. X        (    DeferredChar
  141. X            &&
  142. X            (    c == '\n'
  143. X                ||
  144. X                ! ( rand() % 6 )
  145. X            )
  146. X        )
  147. X        {    /* It's time to output the DeferredChar. */
  148. X            if ( isalpha( c ) && isupper( c ))
  149. X            {    /* Preserve word capitalization */
  150. X                if ( isalpha( DeferredChar ))
  151. X                    DeferredChar = toupper( DeferredChar );
  152. X                c = tolower( c );
  153. X            }
  154. X            else if ( isalpha( DeferredChar ))
  155. X                DeferredChar = tolower( DeferredChar );
  156. X            putchar( DeferredChar );
  157. X            DeferredChar = 0;
  158. X            putchar( c );
  159. X            continue;
  160. X        }
  161. X
  162. X        if ( c == '\n' )
  163. X        {    /* No changes to newline */
  164. X            putchar( c );
  165. X            continue;
  166. X        }
  167. X
  168. X        if ( Count > 24 && Events && ( Count / Events ) < 20 )
  169. X        {    /* Too many mutations in one spot. */
  170. X            putchar( c );
  171. X            continue;
  172. X        }
  173. X
  174. X        if ( c == ' ' )
  175. X        {    /* Do nothing to it. */
  176. X            ;
  177. X        }
  178. X        else if ( ! DeferredChar && ( rand() % 72 ) < 3 )
  179. X        {    /* Defer it. */
  180. X            DeferredChar = c;
  181. X            ++Events;
  182. X            continue;
  183. X        }
  184. X        else if ( ( rand() % 72 ) < 3 )
  185. X        {    /* Replace with noise. */
  186. X            ++Events;
  187. X            c = Noise[ rand() % 9 ];
  188. X        }
  189. X        else if ( ( rand() % 72 ) < 2 )
  190. X        {    /* Replicate. */
  191. X            ++Events;
  192. X            putchar( c );
  193. X        }
  194. X        else if ( ( rand() % 72 ) < 1 )
  195. X        {    /* remove it. */
  196. X            ++Events;
  197. X            continue;
  198. X        }
  199. X
  200. X        putchar( c );
  201. X    }
  202. X}
  203. END_OF_FILE
  204. if test 2303 -ne `wc -c <'sigvi.c'`; then
  205.     echo shar: \"'sigvi.c'\" unpacked with wrong size!
  206. fi
  207. # end of 'sigvi.c'
  208. fi
  209. echo shar: End of shell archive.
  210. exit 0
  211.  
  212.  
  213. exit 0 # Just in case...
  214.