Untitled


SUBMITTED BY: Guest

DATE: Dec. 9, 2012, 12:42 p.m.

FORMAT: Java

SIZE: 2.1 kB

HITS: 1127

  1. package vernam;
  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.util.Random;
  7. public class Main {
  8. static Random R;
  9. public static byte xor(byte a,byte b)
  10. {
  11. return (byte) (a ^ b);
  12. }
  13. public static int maxof(int a[])
  14. {
  15. int result=0,N=a.length;
  16. for (int i=0;i<N;i++)
  17. {
  18. if (i==0) result = a[0]; else
  19. if (a[i]>result) result = a[i];
  20. }
  21. return result;
  22. }
  23. public static int minof(int a[])
  24. {
  25. int result=0,N=a.length;
  26. for (int i=0;i<N;i++)
  27. {
  28. if (i==0) result = a[0]; else
  29. if (a[i]<result) result = a[i];
  30. }
  31. return result;
  32. }
  33. public static byte fgetc(FileInputStream f) throws IOException
  34. {
  35. int temp = f.read();
  36. if (temp == -1) return (byte)R.nextInt(); else return (byte)temp;
  37. }
  38. /*
  39. * @param args
  40. * @throws FileNotFoundException
  41. */
  42. public static void main(String[] args) throws FileNotFoundException, IOException {
  43. if (args.length != 3) {System.err.println("Usage: java -jar Wehrnam"
  44. + ".jar [file1] [file2] [output]"); return;}
  45. FileInputStream f1 = new FileInputStream(args[0]),
  46. f2 = new FileInputStream(args[1]);
  47. FileOutputStream ou = new FileOutputStream(args[2]);
  48. int temp[] = new int[2];
  49. temp[0] = f1.available();temp[1] = f2.available();
  50. int/* min = minof(temp),*/max = maxof(temp);
  51. byte a,b,c;
  52. R = new Random(System.nanoTime());
  53. for (int i=0;i<max;i++)
  54. {
  55. a=fgetc(f1);b=fgetc(f2);
  56. c = xor(a,b);
  57. ou.write(c);
  58. }
  59. }
  60. }
  61. /*Copyright (c) 2012 1pedosRUdeENBnhudrmdcrsW8SmGgxugE*/
  62. /*HM0CqX8uRJ1L7Y0NBHGTTBlpDHnZOt5uiV/dU5w8WQtJjfTRER34jogD+TdghNUuZfLsLoueP5FlI70W0vogq1w=*/

comments powered by Disqus