Class Encryption: Encrypting

Previous      Next      Java Source      Encrypted Hello.class file

import java.io.*;

public class Slide {
   public static void main (String args[]) {
      if (args.length != 3) {
         System.out.println("Usage: java Slide in-file out-file integer-key");
         return;
      }
      
      try {
         FileInputStream in = new FileInputStream(args[0]);
         FileOutputStream out = new FileOutputStream(args[1]);
         int key = Integer.parseInt(args[2]);
         int ch;
         while ((ch = in.read()) != -1) {
            byte c = (byte)((ch + key) % 256);
            out.write (c);
         }
         in.close();
         out.close();
      }
      catch (IOException e) {
         System.out.println("Error: "+e.getMessage());
      }
   }
}