Little Fighter Empire - Forums
What's wrong with my DCing algorithm? (C#) - Printable Version

+- Little Fighter Empire - Forums (https://lf-empire.de/forum)
+-- Forum: General Zone (https://lf-empire.de/forum/forumdisplay.php?fid=23)
+--- Forum: Programming (https://lf-empire.de/forum/forumdisplay.php?fid=50)
+--- Thread: What's wrong with my DCing algorithm? (C#) (/showthread.php?tid=8813)



What's wrong with my DCing algorithm? (C#) - NightmareX1337 - 07-05-2013

    CSHARP-Code:
public static class DataProc
{
	public static byte[] DatToPlain(string filepath)
	{
		byte[] buffer = File.ReadAllBytes(filepath);
		byte[] decryptedtext = new byte[buffer.Length];
		string password = Form1.Settings.dekey; // Decryption key
 
		if(string.IsNullOrEmpty(password)) return buffer;
 
		for(int i = 123, j = 0; i < buffer.Length; i++, j++)
			decryptedtext[j] = (byte)(buffer[i] - (byte)password[j % password.Length]);
 
		return decryptedtext;
	}
 
	public static void PlainToDat(string text, string filepath)
	{
		string password = Form1.Settings.enkey; // Encryption key
		string First123 = Program.Title;
		byte[] dat = new byte[123 + text.Length];
 
		for (int i = 0; i < First123.Length && i < 123; i++)
			dat[i] = (byte)First123[i];
		for (int i = First123.Length; i < 123; i++)
			dat[i] = 0;
		if(!string.IsNullOrEmpty(password))
			for (int i = 0; i < text.Length; i++)
				dat[i + 123] = (byte)((byte)text[i] + (byte)password[i % password.Length]);
		else
			for (int i = 0; i < text.Length; i++)
				dat[i + 123] = (byte)text[i];
 
		File.WriteAllBytes(filepath, dat);
	}
}

Hi,
Here is the DCing algorithm that i'm using it on my DCer (LF2.IDE)
The algorithm works fine and when i open saved files with -my DCer again or with- another DCer there is nothing weird but somehow LF2 crashes whenever i try to choose the saved character - there is no error while loading dat files
I saved my dat file -without changing it- with another DCer then everything was fine.
Please help :( so i can make my DCer much better :)

Thanks in Advance!..


RE: What's wrong with my DCing algorithm? (C#) - Azriel - 07-05-2013

There is nothing wrong here. The problem probably lies in your save algorithm.



Azriel~


RE: What's wrong with my DCing algorithm? (C#) - NightmareX1337 - 07-05-2013

(07-05-2013, 07:08 PM)Azriel Wrote:  There is nothing wrong here. The problem probably lies in your save algorithm.
Don't you see that there is no saving algorithm?!!
    CSHARP-Code:
File.WriteAllBytes(filepath, dat);



RE: What's wrong with my DCing algorithm? (C#) - Azriel - 07-05-2013

Is "dat" re-encrypted before writing out?
woops sorry didn't scroll down the source code, hold on, rereading.

yes there's somethign wrong, hold on i'll edit this post when i've analysed it properly.



Azriel~


RE: What's wrong with my DCing algorithm? (C#) - NightmareX1337 - 07-05-2013

    CSHARP-Code:
public bool Save(string filePath)
{
      	if(filePath.EndsWith(".dat"))
      	   	DataProc.PlainToDat(Scintilla.Text, filePath);
       	else
       		File.WriteAllText(filePath, Scintilla.Text);
 
        scintilla.Modified = false;
        return true;
}

That's what I'm using - I dont think 'dat' is re-encrypted...
Edit: waiting for it...


RE: What's wrong with my DCing algorithm? (C#) - Azriel - 07-05-2013

I think this should be it:
    CSHARP-Code:
dat[i + 123] = (byte)((byte)text[i] + (byte)password[i % password.Length]);
// should be
dat[i + 123] = (byte)((byte)text[i] + (byte)password[(i + 123) % password.Length]);


side note: you are also adding junk bytes to unencrypted data files. it's inconsistent with your decryption algorithm which just returns the file contents without removing junk.



Azriel~


RE: What's wrong with my DCing algorithm? (C#) - NightmareX1337 - 07-05-2013

I'll try...
Edit:
It's complete wrong, not working...


RE: What's wrong with my DCing algorithm? (C#) - Azriel - 07-05-2013

ah my mistake =/ (it was correct, i got the positions mixed up). Can't seem to see anything else that could be wrong.
maybe \r\n-s are changing? I can't tell, but in theory lf2 handles that alright



Azriel~


RE: What's wrong with my DCing algorithm? (C#) - zort - 07-05-2013

Well, what are the differences between a -virgin data file- and its later form -after having been touched by your vile algorithm-?


RE: What's wrong with my DCing algorithm? (C#) - NightmareX1337 - 07-05-2013

Actualy original LF2 data contains no '\r' characters they only contain '\n' characters - at least my files
Anyway, i solved it after removing first 123 junk bytes - i thought LF2 don't care those useless 123 byte :D
Thanks so much :D - it took my 2 days trying to solve :)
(07-05-2013, 07:49 PM)zort Wrote:  Well, what are the differences between a -virgin data file- and its later form -after having been touched by your vile algorithm-?
Then tell me what makes my algorithm vile?
nevermind...