Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
OTP4U (One Time Pad For You) - Runner.java

Runner.java

Caricato da: Teutoburgo
Scarica il programma completo

  1. /*
  2.  * Runner.java
  3.  *
  4.  * Created on July 5, 2003, 7:30 AM
  5.  */
  6.  
  7. package tk.teutoburgo.otp4u.gui;
  8.  
  9. import java.io.*;
  10. import tk.teutoburgo.otp4u.application.OTP4U;
  11. /**
  12.  *
  13.  * @author  Karl Dinwiddie
  14.  */
  15. public class Runner implements Runnable {
  16.     public static final short DO_ENCRYPT = 0;
  17.     public static final short DO_DECRYPT = 1, GENERATE=2, GK4K0=3,
  18.       PUBLIC=4, RANDOM=5, MIX=6, SEPARATE=7;
  19.     private StringBuffer messages = new StringBuffer(1024);
  20.     private RunListener runListener;
  21.     public static OTP4U otp4u = new OTP4U(OTP4U.GUI_TRUE);
  22.     private int nextAction;
  23.  
  24.     /** Creates a new instance of Runner */
  25.     public Runner(RunListener newRunListener) {
  26.         runListener = newRunListener;
  27.     }
  28.  
  29.     public String getMessages() {
  30.         return messages.toString();
  31.     }
  32.  
  33.     public void setNextAction(short action) {
  34.         nextAction = action;
  35.     }
  36.  
  37.     public void run() {
  38.         synchronized(this) {
  39.             try {
  40.                 runListener.log("Using configuration file:" + runListener.getConfigFile().getCanonicalPath());
  41.                 OTP4U.setConfigFile(runListener.getConfigFile());
  42.                 switch (nextAction) {
  43.                     case DO_ENCRYPT:
  44.                         otp4u.doEncryption(runListener.getTargetFile().getCanonicalPath());
  45.                         runListener.log("Encryption completed.");
  46.                         break;
  47.                     case DO_DECRYPT:
  48.                         otp4u.doDecryption(runListener.getTargetFile().getCanonicalPath());
  49.                         runListener.log("Decryption completed.");
  50.                         break;
  51.                      case GENERATE:
  52.                         otp4u.generateEntropyFile();
  53.                         runListener.log("Entropy source generated.");
  54.                         break;
  55.                      case GK4K0:
  56.                         otp4u.generateK4K0File();
  57.                         runListener.log("K4K0 generated.");
  58.                         break;
  59.                      case PUBLIC:
  60.                         otp4u.writePublicKey();
  61.                         runListener.log("Public key generated.");
  62.                         break;
  63.                      case RANDOM:
  64.                         otp4u.writeRandomKey();
  65.                         runListener.log("Random key generated.");
  66.                         break;
  67.                      case MIX:
  68.                         otp4u.mixGUI(runListener.getTargetFile().getCanonicalPath());
  69.                         runListener.log("Mixed key generated.");
  70.                         break;
  71.                      case SEPARATE:
  72.                         otp4u.separate();
  73.                         runListener.log("Key and ciphertext.dat files generated.");
  74.                         break;
  75.                 }
  76.             } catch(Throwable t) {
  77.                 runListener.handleThrowable(t);
  78.             }
  79.             System.out.println("notifyall");
  80.             notifyAll();
  81.         }
  82.     }
  83.  
  84.     public interface RunListener {
  85.         public void log(String msg);
  86.         public void handleThrowable(Throwable t);
  87.         public File getConfigFile();
  88.         public File getTargetFile();
  89.     }
  90. }