 /* 
    TEMPEST jammer v0.4
    (c) Nov 1999 by Mixter <mixter@newyorkoffice.com>
    
    Improved in Feb 2002 by: 
    Angel51 <angel51@altern.org>
    
    Projet PRINT Dijon - Pour se Réapproprier
    l'Informatique/l'Internet et les Nouvelles Technologies
    
    #hacking #hackings #hackers #sikurezza #despe (UnderNet)
    #squat (IrcNet)
    
    -> changed sequential jamming to chaotic jamming;
    -> added cases.
    
    This little program emits bogus electromagnetical signatures
    that should make TEMPEST surveillance techniques against monitors
    and graphics interface port hard to impossible
    Attention: This only works on linux in console mode
    This program can jam the graphic/monitor emissions only!
    
    Please compile with optimization turned on (-O)!
    e.g.: gcc -O3 tj.c -s -static -fomit-frame-pointer -o tj
  */  
  
/* based on: smoothcolor v1.0 by baldor & giemor */ 
  
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <asm/io.h>
  
#define START_COLOR 16
  
/* funny looking optimization stuff */ 
  
#define pal(color, r, g, b)    \
      outb (color, 0x3c8);     \
      outb (r, 0x3c9);         \
      outb (g, 0x3c9);         \
      outb (b, 0x3c9)
  
 int j;
 int i;
 struct timeval timev;

 void 
 docolor (int no) {
  
  /* Chaos Creation */ 
  gettimeofday (&timev, NULL);
  srand (timev.tv_usec);
  j = 1 + (18.0 * rand () / (RAND_MAX + 1.0));

  /* DEBUG
  printf("j = %d\n", j);
  printf("tv_usec: %06ld\n", timev.tv_usec);
   */ 

switch (j) {
 case 0:
  for (i = 0; i < 63; i++)
  pal (no, i, i, i);
 break;
 case 1:
  for (i = 0; i < 63; i++)
  pal (no, i, 0, i);
 break;
 case 2:
  for (i = 0; i < 63; i++)
  pal (no, i, i, 63);
 break;
 case 3:
  for (i = 0; i < 63; i++)
  pal (no, 63, i, i);
 break;
 case 4:
  for (i = 0; i < 63; i++)
  pal (no, 63, i, 63);
 break;
 case 5:
  for (i = 0; i < 63; i++)
  pal (no, 0, 0, i);
 break;
 case 6:
  for (i = 0; i < 63; i++)
  pal (no, i, 0, 0);
 break;
 case 7:
  for (i = 0; i < 63; i++)
  pal (no, 63, 0, i);
 break;
 case 8:
  for (i = 0; i < 63; i++)
  pal (no, i, 0, 63);
 break;
 case 9:
  for (i = 0; i < 63; i++)
  pal (no, 63, i, 0);
 break;
 case 10:
  for (i = 63; i > 0; i--)
  pal (no, i, i, 0);
 break;
 case 11:
  for (i = 63; i > 0; i--)
  pal (no, 0, i, i);
 break;
 case 12:
  for (i = 63; i > 0; i--)
  pal (no, i, 63, i);
 break;
 case 13:
  for (i = 63; i > 0; i--)
  pal (no, 63, 63, i);
 break;
 case 14:
  for (i = 63; i > 0; i--)
  pal (no, i, 63, 63);
 break;
 case 15:
  for (i = 63; i > 0; i--)
  pal (no, 0, i, 0);
 break;
 case 16:
  for (i = 63; i > 0; i--)
  pal (no, i, 63, 0);
 break;
 case 17:
  for (i = 63; i > 0; i--)
  pal (no, 0, i, 63);
 break;
 case 18:
  for (i = 63; i > 0; i--)
  pal (no, 0, 63, i);
 break;
    }
}

int 
main (void) {

 int z;
 
 printf ("\n[TEMPEST jammer v0.4 by Mixter & Angel51]\n\n");
 if ((getuid () != 0) && (geteuid () != 0)) {
  printf ("You need to be root to run this program!\n");
  exit (1);
 }

 if (fork () != 0)
 return (0);		/* go into background */

 ioperm (0x3c8, 3, 1);
 ioperm (0x3c9, 3, 1);
 
 nice (20);

 while (1)
  for (z = START_COLOR; z < 64; z++) {
   docolor (z);
   /* DEBUG
   printf("z = %d\n", z);
    */ 
  }

 ioperm (0x3c8, 3, 0);
 ioperm (0x3c9, 3, 0);

}


