home *** CD-ROM | disk | FTP | other *** search
/ Powerdrive 1997 February / POWERDRIVE0297.ISO / share / rollen / nethack / misc / nhdecode.c < prev    next >
C/C++ Source or Header  |  1994-12-13  |  1KB  |  37 lines

  1. #include <stdio.h>
  2.  
  3. /* nhdecode.c      Latest update: Wednesday, April 13th 1994.
  4.  *                 Creator: Boudewijn Wayers (wsbusr1@urc.tue.nl).
  5.  *
  6.  * This program reads from the standard input and writes on the
  7.  * standard output.
  8.  * It takes the (encoded) "rumors" or "oracles" file as input and
  9.  * decodes this file.
  10.  * No looking at the sources! Just a glimpse of the rumors file and
  11.  * half an hour of trying was enough to construct the encoding /
  12.  * decoding algorythm.
  13.  *
  14.  * PS: The following line does the same as the above program:
  15. main(){int _,l=0;while((_=getchar())!=-1)l=_=='\n'?putchar(_),0:(putchar(_^1<<l),++l%5);}
  16.  * I couldn't quite fit it on one line, but if someone can, please mail
  17.  * me the result, will you? For some reason, changing putchar to putc
  18.  * gives a "Bus error". Changing '\n' to 13 would make the program
  19.  * incompatible across machines.
  20.  */
  21.  
  22. main()
  23. {       int char,counter;
  24.     counter = 1;
  25.     while ((char=getchar()) != EOF)
  26.     {       if (char=='\n')
  27.         {       putchar(char);
  28.             counter = 1;
  29.         }
  30.         else
  31.         {    putchar(char^counter);
  32.             counter *= 2;
  33.             if (counter==32) counter=1;
  34.         }
  35.     }
  36. }
  37.