-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathDbaXor.java
More file actions
68 lines (62 loc) · 2.04 KB
/
DbaXor.java
File metadata and controls
68 lines (62 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Quick ugly code to decrypt files downloaded by Dba.jar
* Mimicks b.b.b.a.b
* Input: file to decrypt
* Output: a file with '.decrypted' appended to the name is created
*
* Example:
* $ java DbaXor bx
* Decrypting downloaded file bx
*
* A. Apvrille
*/
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Arrays;
public class DbaXor {
public static void copyAndXor(String input, String output) {
int i;
byte[] decrypted;
byte[] encrypted;
byte[] inputbuf;
try {
FileInputStream v2 = new FileInputStream(input);
int inputlen = v2.available();
if(inputlen < 30) {
System.out.println("Input file is too short");
v2.close();
}
inputbuf = new byte[inputlen];
v2.read(inputbuf);
v2.close();
byte[] v2_1 = new byte[5];
byte[] v4 = new byte[5];
encrypted = new byte[5];
decrypted = new byte[5];
System.arraycopy(inputbuf, 0, v2_1, 0, 5);
System.arraycopy(inputbuf, 5, v4, 0, 5);
System.arraycopy(inputbuf, inputbuf.length - 5, encrypted, 0, 5);
System.arraycopy(inputbuf, inputbuf.length - 10, decrypted, 0, 5);
FileOutputStream fos = new FileOutputStream(output);
encrypted = new byte[10];
System.arraycopy(inputbuf, 10, encrypted, 0, 10);
decrypted = new byte[inputbuf.length - 30];
System.arraycopy(inputbuf, 20, decrypted, 0, decrypted.length);
for(i = 0; i < decrypted.length; ++i) {
decrypted[i] = ((byte)(encrypted[i % 10] ^ decrypted[i]));
}
fos.write(decrypted);
fos.close();
}
catch(Exception v1) {
v1.printStackTrace();
}
}
public static void main(String args[]) {
// Supply filename to decrypt as argument
// Yes, this is quick and ugly - no input check
System.out.println("Decrypting downloaded file " +args[0]);
String output_name = args[0] + ".decrypted";
DbaXor.copyAndXor(args[0],output_name);
}
}