Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's wrong with my DCing algorithm? (C#)
#1
    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!..
Ultimately, my constant dissatisfaction with the way things are becomes the driving force behind everything I do.
[Image: sigline.png]
LF2 IDE - Advanced visual data changer featuring instant data loader
LF2 Sprite Sheet Generator - Template based sprite sheet generator based on Gad's method
[Image: sigline.png]
There is no perfect language, but C++ is the worst.
Reply
Thanks given by:
#2
There is nothing wrong here. The problem probably lies in your save algorithm.



Azriel~
Reply
Thanks given by:
#3
(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);
Ultimately, my constant dissatisfaction with the way things are becomes the driving force behind everything I do.
[Image: sigline.png]
LF2 IDE - Advanced visual data changer featuring instant data loader
LF2 Sprite Sheet Generator - Template based sprite sheet generator based on Gad's method
[Image: sigline.png]
There is no perfect language, but C++ is the worst.
Reply
Thanks given by:
#4
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~
Reply
Thanks given by:
#5
    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...
Ultimately, my constant dissatisfaction with the way things are becomes the driving force behind everything I do.
[Image: sigline.png]
LF2 IDE - Advanced visual data changer featuring instant data loader
LF2 Sprite Sheet Generator - Template based sprite sheet generator based on Gad's method
[Image: sigline.png]
There is no perfect language, but C++ is the worst.
Reply
Thanks given by:
#6
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~
Reply
Thanks given by: Nightmarex1337
#7
I'll try...
Edit:
It's complete wrong, not working...
Ultimately, my constant dissatisfaction with the way things are becomes the driving force behind everything I do.
[Image: sigline.png]
LF2 IDE - Advanced visual data changer featuring instant data loader
LF2 Sprite Sheet Generator - Template based sprite sheet generator based on Gad's method
[Image: sigline.png]
There is no perfect language, but C++ is the worst.
Reply
Thanks given by:
#8
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~
Reply
Thanks given by:
#9
Well, what are the differences between a -virgin data file- and its later form -after having been touched by your vile algorithm-?
Reply
Thanks given by:
#10
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...
Ultimately, my constant dissatisfaction with the way things are becomes the driving force behind everything I do.
[Image: sigline.png]
LF2 IDE - Advanced visual data changer featuring instant data loader
LF2 Sprite Sheet Generator - Template based sprite sheet generator based on Gad's method
[Image: sigline.png]
There is no perfect language, but C++ is the worst.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)