Advertisement
Guest User

Decrypt.jar

a guest
Apr 25th, 2012
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. package org.matthi.decrypt;
  2.  
  3. import java.io.*;
  4. import javax.swing.JFileChooser;
  5.  
  6. public class App
  7. {
  8.     public static void main(String[] args)
  9.         throws Exception
  10.     {
  11.         JFileChooser chooser = new JFileChooser();
  12.         chooser.setDialogTitle("Verschlüsselte Datei wählen...");
  13.         chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  14.         if(chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
  15.         {
  16.             System.exit(1);
  17.         }
  18.  
  19.         File file = chooser.getSelectedFile();
  20.         final byte[] key = new byte[4096];
  21.         App.class.getResourceAsStream("/decrypt.key").read(key);
  22.  
  23.         InputStream source = new BufferedInputStream(new FileInputStream(file));
  24.         OutputStream target = new BufferedOutputStream(new FileOutputStream(targetName(file)));
  25.  
  26.         int pos = 0;
  27.         while(source.available() > 0)
  28.         {
  29.             if(pos < 4096)
  30.             {
  31.                 target.write(source.read() ^ key[pos]);
  32.                 pos++;
  33.             }
  34.             else
  35.             {
  36.                 target.write(source.read());
  37.             }
  38.         }
  39.  
  40.         target.flush();
  41.         target.close();
  42.         source.close();
  43.     }
  44.  
  45.     private static String targetName(File file)
  46.     {
  47.         return file.getParent() + File.separator + file.getName().substring(7, file.getName().length() - 5);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement