Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DCing algorithm
#1
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 Twisted
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
Reply
Thanks given by: MH-Razen , zort , MangaD
#2
Code:
/*Programmed by Silva
Stolen stuff from Blue Phoenix
Latest version: 14 Jan 2009
*/

   import java.io.*;

    public class ReadFile{
       public static void main(String[] args) throws IOException{
         File f;
         f=new File("template.dat");// file rawr
          
         if(!f.exists()&& f.length()<0)
            System.out.println("The specified file is not exist");
        
         else{
            FileInputStream finp=new FileInputStream(f);
            int counta = 0;
            int countTo123 = 0;
            byte b;
            byte d;
            do{
               countTo123++;
               b=(byte)finp.read();
               if (countTo123 > 123)
               {
              
                  d = DecryptByte(counta,b);
                  counta++;
                  if (counta > 36){
                     counta = 0;
                  }
                  System.out.print((char)d);
               }
            }
            while(b!=-1);
            finp.close();
         }
      }
      
       public static byte DecryptByte(int counta,byte b){
         String plainEncryptionKey = "odBearBecauseHeIsVeryGoodSiuHungIsAGo";
         b -= (byte)plainEncryptionKey.charAt(counta);
         return b;
      }
   }

My version :) (works faster because it uses streams ;) ).
[Image: doty7Xn.gif]

10 ʏᴇᴀʀs sɪɴᴄᴇ ɪʀᴄ ɢᴏᴏᴅ.ɪ ᴡᴀʟᴋ ᴛʜʀᴏᴜɢʜ ᴛʜᴇ ᴇᴍᴘᴛʏ sᴛʀᴇᴇᴛs ᴛʀʏɪɴɢ ᴛᴏ ᴛʜɪɴᴋ ᴏғ sᴏᴍᴇᴛʜɪɴɢ ᴇʟsᴇ ʙᴜᴛ ᴍʏ ᴘᴀᴛʜ ᴀʟᴡᴀʏs ʟᴇᴀᴅs ᴛᴏ ᴛʜᴇ ɪʀᴄ. ɪ sᴛᴀʀᴇ ᴀᴛ ᴛʜᴇ sᴄʀᴇᴇɴ ғᴏʀ ʜᴏᴜʀs ᴀɴᴅ ᴛʀʏ ᴛᴏ sᴜᴍᴍᴏɴ ᴛʜᴇ ɢᴏᴏᴅ ɪʀᴄ. ɪ ᴡᴀᴛᴄʜ ᴏᴛʜᴇʀ ɪʀᴄ ᴄʜᴀɴɴᴇʟs ʙᴜᴛ ɪᴛ ɪs ɴᴏ ɢᴏᴏᴅ. ɪ ᴘᴇsᴛᴇʀ ᴢᴏʀᴛ ᴀɴᴅ ᴛʀʏ ᴛᴏ ʀᴇsɪsᴛ ʜɪs sᴇxɪɴᴇss ʙᴜᴛ ɪᴛ ɪs ᴀʟʟ ᴍᴇᴀɴɪɴɢʟᴇss. ᴛʜᴇ ᴇɴᴅ ɪs ɴᴇᴀʀ.ɪ ᴛʜᴇɴ ᴜsᴜᴀʟʟʏ ʀᴇᴀᴅ sᴏᴍᴇ ᴏʟᴅ ɪʀᴄ ʟᴏɢs ᴀɴᴅ ᴄʀʏ ᴍʏsᴇʟғ ᴛᴏ sʟᴇᴇᴘ.


Reply
Thanks given by: Silverthorn
#3
k, take Silva's version, it's working faster. For a reason that I don't know =P
Silverthorn / Blue Phoenix
~ Breaking LFE since 2008 ~

"Freeze, you're under vrest!" - Mark, probably.

» Gallery | » Sprites | » DeviantArt
Reply
Thanks given by:
#4
mine's better coz it reads and writes. not released yet coz I haven't finished it (doesn't update UI and what not). (no - colour coding is not as simple as it looks)

[Image: 2qmmc0p.png]



Azriel~
Reply
Thanks given by:
#5
We are talking about the algorithm >.<" . Not about the application, lol.
[Image: doty7Xn.gif]

10 ʏᴇᴀʀs sɪɴᴄᴇ ɪʀᴄ ɢᴏᴏᴅ.ɪ ᴡᴀʟᴋ ᴛʜʀᴏᴜɢʜ ᴛʜᴇ ᴇᴍᴘᴛʏ sᴛʀᴇᴇᴛs ᴛʀʏɪɴɢ ᴛᴏ ᴛʜɪɴᴋ ᴏғ sᴏᴍᴇᴛʜɪɴɢ ᴇʟsᴇ ʙᴜᴛ ᴍʏ ᴘᴀᴛʜ ᴀʟᴡᴀʏs ʟᴇᴀᴅs ᴛᴏ ᴛʜᴇ ɪʀᴄ. ɪ sᴛᴀʀᴇ ᴀᴛ ᴛʜᴇ sᴄʀᴇᴇɴ ғᴏʀ ʜᴏᴜʀs ᴀɴᴅ ᴛʀʏ ᴛᴏ sᴜᴍᴍᴏɴ ᴛʜᴇ ɢᴏᴏᴅ ɪʀᴄ. ɪ ᴡᴀᴛᴄʜ ᴏᴛʜᴇʀ ɪʀᴄ ᴄʜᴀɴɴᴇʟs ʙᴜᴛ ɪᴛ ɪs ɴᴏ ɢᴏᴏᴅ. ɪ ᴘᴇsᴛᴇʀ ᴢᴏʀᴛ ᴀɴᴅ ᴛʀʏ ᴛᴏ ʀᴇsɪsᴛ ʜɪs sᴇxɪɴᴇss ʙᴜᴛ ɪᴛ ɪs ᴀʟʟ ᴍᴇᴀɴɪɴɢʟᴇss. ᴛʜᴇ ᴇɴᴅ ɪs ɴᴇᴀʀ.ɪ ᴛʜᴇɴ ᴜsᴜᴀʟʟʏ ʀᴇᴀᴅ sᴏᴍᴇ ᴏʟᴅ ɪʀᴄ ʟᴏɢs ᴀɴᴅ ᴄʀʏ ᴍʏsᴇʟғ ᴛᴏ sʟᴇᴇᴘ.


Reply
Thanks given by:
#6
Ok, I don't know if I should be posting here (because the only people who have posted are elite members :D) but do the decoding algorithms work on R-LF2 data files? Jiquera's DC doesn't work, and Rammichael's DC works, but the only difference between regular and RLF2's data files are the special chinese characters in the name (I think everyone knows this already). My question is, why does Rammichael's DC works and Jiquera's doesn't (after all, they're just characters in the name), and does BP and Silva's algorithm work for R-LF2 data files ?
<div style="background-image:url('http://f.imagehost.org/0086/Fill.png'); filter:alpha(opacity=70); border-top:1px solid #000000; border-right:1px solid #000000; border-left: 1px solid #000000; border-bottom: 1px solid #000000"> <table border="0" width="100%"><tr><td width="500"><img src=http://g.imagehost.org/0170/FORUM_SIGNATURE.png opacity="1" alt="Little Fighter Code Lyoko"></td><td width="30"><img src="http://www.antoninasdesigns.com/images/real-gray-square.gif" width="1" height="100"></td><td><font face=monotype corsiva><font color=#0A298F><font size="4"><b><i>~Solomon Leung</size><br><font size="2">P.S. I Just Lost <a href="http://www.losethegame.org" target="_blank" style="text-decoration: none"><font color=#0A298F>The Game</font></a></b></i></font></font></size></td></tr></table></div>
Reply
Thanks given by:
#7
Jiquera's data changer is just uses poorly coded libraries to read in data(my theory), it stops when it reaches a certain byte value. This doesn't happen with our implementations I believe.
[Image: doty7Xn.gif]

10 ʏᴇᴀʀs sɪɴᴄᴇ ɪʀᴄ ɢᴏᴏᴅ.ɪ ᴡᴀʟᴋ ᴛʜʀᴏᴜɢʜ ᴛʜᴇ ᴇᴍᴘᴛʏ sᴛʀᴇᴇᴛs ᴛʀʏɪɴɢ ᴛᴏ ᴛʜɪɴᴋ ᴏғ sᴏᴍᴇᴛʜɪɴɢ ᴇʟsᴇ ʙᴜᴛ ᴍʏ ᴘᴀᴛʜ ᴀʟᴡᴀʏs ʟᴇᴀᴅs ᴛᴏ ᴛʜᴇ ɪʀᴄ. ɪ sᴛᴀʀᴇ ᴀᴛ ᴛʜᴇ sᴄʀᴇᴇɴ ғᴏʀ ʜᴏᴜʀs ᴀɴᴅ ᴛʀʏ ᴛᴏ sᴜᴍᴍᴏɴ ᴛʜᴇ ɢᴏᴏᴅ ɪʀᴄ. ɪ ᴡᴀᴛᴄʜ ᴏᴛʜᴇʀ ɪʀᴄ ᴄʜᴀɴɴᴇʟs ʙᴜᴛ ɪᴛ ɪs ɴᴏ ɢᴏᴏᴅ. ɪ ᴘᴇsᴛᴇʀ ᴢᴏʀᴛ ᴀɴᴅ ᴛʀʏ ᴛᴏ ʀᴇsɪsᴛ ʜɪs sᴇxɪɴᴇss ʙᴜᴛ ɪᴛ ɪs ᴀʟʟ ᴍᴇᴀɴɪɴɢʟᴇss. ᴛʜᴇ ᴇɴᴅ ɪs ɴᴇᴀʀ.ɪ ᴛʜᴇɴ ᴜsᴜᴀʟʟʏ ʀᴇᴀᴅ sᴏᴍᴇ ᴏʟᴅ ɪʀᴄ ʟᴏɢs ᴀɴᴅ ᴄʀʏ ᴍʏsᴇʟғ ᴛᴏ sʟᴇᴇᴘ.


Reply
Thanks given by:
#8
I don't have any r-lf2-files on my comp right now, so I cannot test the decrypter with them. However, I just tried the "stupid" unreadable-making-method, where you just replace the first few bits. It works fine, and I think this is the encryption method of r-lf2. (Of course it works, I know how me and Silva coded :P)

But just to prevent any questions, CE-LF2 dat-files are encrypted in a different way, and with this code you cannot decrypt them either.
Silverthorn / Blue Phoenix
~ Breaking LFE since 2008 ~

"Freeze, you're under vrest!" - Mark, probably.

» Gallery | » Sprites | » DeviantArt
Reply
Thanks given by:
#9
(01-16-2009, 03:06 PM)Blue Phoenix Wrote:  I don't have any r-lf2-files on my comp right now, so I cannot test the decrypter with them. However, I just tried the "stupid" unreadable-making-method, where you just replace the first few bits. It works fine, and I think this is the encryption method of r-lf2. (Of course it works, I know how me and Silva coded :P)

I love bringing this up, but if you press A + B + C in LF2 mid-game you get to a sort of debug mode.

F2 crashes the game, but F3 calls up an encrypter/decrypter for .dat files. I don't have an R-LF2 data file at hand, but there's a chance it was done using that or celebix' encrypter/decrypter, which does exactly the same.

Kinda what I suspect CL of having done, really, however I'm not sure how relevant this is.
Reply
Thanks given by:
#10
DAMN YOU ALL genius people
or more like DAMN YOU java (for me it's a 'language from planet')

I've been trying many things but none of them works :(

Please try to make this noob understand how to encode/decode dat files. I'd like to start from how to convert the encoded version into a readable version. I'm learning from Silva's code, but also read BP's to help me understand. but....

1. Count to 123 first - does that mean the first 123 characters are unused? Or... I don't have any idea, probably this is what makes me fail coz I don't even have any idea what else to try about this
2. b=(byte)finp.read(); --> I can't find this on my dictionary. What does this mean in this planet's language?
3. d = DecryptByte(counta,b); ---> does DecryptByte give you the KeyAscii (keycode or sth) from the character? But if so, I don't understand why there must be the variable 'b' behind it.
4. System.out.print((char)d); ---> does this prints the character stored in variable 'd' ? which is the result of DecryptByte(counta,b) ? But that's strange, I can't see where you modify / encode the byte :0 .

And damn you gravedigging warning :( . And damn me :( .
and thanks for replying and helping :D !!




EDIT:
Finally :D . Chiko explained all to me.
So the first 123 chars are useless.
We subtract the 'KeyAscii' of the 124th character with the 'KeyAscii' of the 1st char of the encryption key.
then the 125th character with the 2nd char from the key, so on.
When we get to the end of the encryption key, go back to the first character.

Oooooooo....... not it works, I have to open another thread
TEMPE
Reply
Thanks given by: A-Man




Users browsing this thread: 1 Guest(s)