01-14-2009, 07:33 PM
After Silva explained how the encryption of dat-files works (big thanks for that again), I tried to implement that into a programming language. As the only language I'm better at is Java, this code is written in Java (duh!).
Feel free to copy the code, or try to understand it. I seldomly write comments, and if I do, they're pretty useless :P
What it does: it reads the file template.dat (which has to be in the same folder as the class-object), decrypts it, and outputs the decrypted result into a txt-file.
On a side note: if you copy this code, I'd be pleased as punch if you leave the author notes in there. If you remove them, I'll stalk you until I chopped off your head after I cut out your heart, pulled out every single nail, sliced up your stomach and the usual stuff
Feel free to copy the code, or try to understand it. I seldomly write comments, and if I do, they're pretty useless :P
What it does: it reads the file template.dat (which has to be in the same folder as the class-object), decrypts it, and outputs the decrypted result into a txt-file.
On a side note: if you copy this code, I'd be pleased as punch if you leave the author notes in there. If you remove them, I'll stalk you until I chopped off your head after I cut out your heart, pulled out every single nail, sliced up your stomach and the usual stuff
Code:
/*
Programmed by Blue Phoenix
Explanations and help by Silva
Latest version: 14 Jan 2009
*/
import java.io.*;
import java.lang.*;
public class ReadIt {
public static void main(String args[]) throws IOException {
int mod;
char buffer;
String finalCode = "";
String plainEncryptionKey = "odBearBecauseHeIsVeryGoodSiuHungIsAGo";
FileInputStream data = new FileInputStream("template.dat");
int uselessCheck = 0;
byte[] encr = new byte[plainEncryptionKey.length()];
for (int i = 0; i < plainEncryptionKey.length(); i++)
encr[i] = (byte)plainEncryptionKey.charAt(i);
for (int i = data.read(); i != -1; i = data.read()) {
byte encrSingle;
if (uselessCheck >= 123) {
buffer = (char)i;
mod = (uselessCheck-123) % plainEncryptionKey.length();
encrSingle = encr[mod];
finalCode += decrypt(buffer,mod,(uselessCheck-123),encrSingle);
}
uselessCheck++;
}
// System.out.println(finalCode);
try {
FileOutputStream fout = new FileOutputStream ("Template.txt");
new PrintStream(fout).println (finalCode);
fout.close();
}
catch (IOException e) {
System.err.println ("Unable to write to file");
System.exit(-1);
}
}
public static char decrypt(char buffer, int mod, int i, byte encrSingle) {
byte datDecr;
char decrChar;
datDecr = (byte)buffer;
decrChar = PatchData(i,mod,datDecr,encrSingle);
return decrChar;
}
public static char PatchData (int i, int mod, byte datDecr, byte encrSingle){
char result;
datDecr -= encrSingle;
result = (char)datDecr;
return result;
}
}
Silverthorn / Blue Phoenix
~ Breaking LFE since 2008 ~
"Freeze, you're under vrest!" - Mark, probably.
» Gallery | » Sprites | » DeviantArt
~ Breaking LFE since 2008 ~
"Freeze, you're under vrest!" - Mark, probably.
» Gallery | » Sprites | » DeviantArt