Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- public class CDeCrypt {
- public static void main(String[] args) {
- if (args.length < 2) {
- System.err
- .println("Usage: java CDeCrypt <keyfile> <cryptfile> [<outdirectory>]\n"
- + "The decrypted file will get its original name and weill be placed in the optional <outdirectory>.");
- System.exit(-1);
- }
- File key = new File(args[0]);
- File crypt = new File(args[1]);
- File outDir = new File(args.length > 2 ? args[2] : ".");
- decrypt(key, crypt, outDir);
- }
- private static void decrypt(File key, File crypt, File outDir) {
- try {
- DataInputStream k = new DataInputStream(new FileInputStream(key));
- DataInputStream c = new DataInputStream(new FileInputStream(crypt));
- int mNameLen = k.readInt();
- StringBuilder sb = new StringBuilder();
- while (mNameLen > 0) {
- sb.append(k.readChar());
- mNameLen--;
- }
- String mName = sb.toString();
- File mFile = new File(outDir, mName);
- DataOutputStream m = new DataOutputStream(new FileOutputStream(
- mFile));
- System.out.print("Decrypting " + crypt + " using key " + key
- + " to file " + mFile + " ... ");
- int b;
- while ((b = k.read()) >= 0) {
- m.write(b ^ c.read());
- }
- k.close();
- c.close();
- m.close();
- System.out.println("done!");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement