Posted by Mejf on Mon 6 Apr 21:04
report abuse | download | new post
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.Random;
- public class CCrypt {
- if (args.length < 2) {
- System.err
- .println("Usage: java CCrypt <file1> <file2>\n"
- + "You will get one file called C, containing the cryptotext, "
- + "one file called K which decrypts C into M and "
- + "one file called K2 which decrypts C into M2.");
- }
- if (f1.length() > f2.length()) {
- File temp = f1;
- f1 = f2;
- f2 = temp;
- }
- doFirst(f1);
- doSecond(f2);
- }
- try {
- /**
- * From M2 and C we create K2 by K2 = M2 + C. Then M2 = C + K2 and M
- * = C + K
- */
- "K2"));
- key.writeInt(f2.getName().length());
- for (int l = 0; l < f2.getName().length(); l++)
- key.writeChar(f2.getName().charAt(l));
- int b;
- while ((b = in.read()) >= 0) {
- key.write(b ^ crypt.read());
- }
- crypt.close();
- in.close();
- key.close();
- e.printStackTrace();
- }
- }
- try {
- /**
- * From M and a random K we create C, by C = M ^ K.
- */
- "C"));
- "K"));
- key.writeInt(f1.getName().length());
- for (int l = 0; l < f1.getName().length(); l++)
- key.writeChar(f1.getName().charAt(l));
- int b;
- while ((b = in.read()) >= 0) {
- int k = rand.nextInt();
- key.write(k);
- crypt.write(b ^ k);
- }
- crypt.close();
- in.close();
- key.close();
- e.printStackTrace();
- }
- }
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.