Hi,
Im attaching a file at the end of my exe so i can read it when running, the file is just plain text, but i want to encode it to avoid the possibilitie that someone could see my text file.
Then i try to encode it chr by char but when decoding its soooo slow (my text file could be 200 or more lines long > 5000 characters).
I don't care about encoding time, but decoding must be fast.
Can anybody could give me an idea?
I don't need it to be uncrackeable, its not too important that, just a regular encoding to keep it out of average users.
Fast way to Encode/decode some text file?
Fast way to Encode/decode some text file?
ARGENTINA WORLD CHAMPION
Ever think of binary encryption / Just scrambeling the binary code so the text file looks all screwy and upload launching ur app decrypt it. the cool thing is there is no loss of data, no additional spaces n sutch....
heres a sample in VB for now i'll try and port it to pb later.....
heres a sample in VB for now i'll try and port it to pb later.....
Code: Select all
Private Sub cmdDecrypt_Click()
Dim Data As Long, NumBytes As Long, Flag As Long, Q
Flag = Val(txtFlag.Text) 'Flag
NumBytes = FileLen(txtFile.Text) 'Find number of bytes in file
Open txtFile.Text For Binary As #1 'Open file
For Q = 1 To NumBytes - 3 'Loop through each binary entry (byte)
Get #1, Q, Data 'Load byte
Put #1, Q, Data - Flag 'Save byte plus the flag value
Me.Caption = Int(100 * Q / (NumBytes - 3)) & "% Complete"
Next
Close #1 'Close file
End Sub
Private Sub cmdEncrypt_Click()
Dim Data As Long, NumBytes As Long, Flag As Long, Q
Flag = Val(txtFlag.Text) 'Flag
NumBytes = FileLen(txtFile.Text) 'Find number of bytes in file
Open txtFile.Text For Binary As #1 'Open file
For Q = 1 To NumBytes 'Loop through each binary entry (byte)
Get #1, Q, Data 'Load byte
Put #1, Q, Data + Flag 'Save byte minus the flag value
Me.Caption = Int(100 * Q / NumBytes) & "% Complete"
Next
Close #1 'Close file
End Sub
Private Sub txtFlag_Change()
txtFlag.Text = Int(Val(txtFlag.Text)) 'Flag must be an integer
'Enforce interger lbound, ubound (-32768 to 32767)
If txtFlag.Text < -32768 Then txtFlag.Text = 0
If txtFlag.Text > 32767 Then txtFlag.Text = 0
End SubHi,freak wrote:just use PB's packer functions, unpacking is very fast there, and the file
will be unreadble for the users, too.
Timo
Can i unpack some data that i read from a file?
I want to read my own exe and get the attached file to memory and unpack it from there, no write operation done in this process. Its possible?
Code: Select all
If ReadFile(0,"myexe.exe")
FileSeek(MyOriginalExeSize)
*Mem = AllocateMemory(0,Lof()-MyOriginalExeSize)
ReadData(*Mem,Lof()-MyOriginalExeSize)
Closefile(0)
End If
ARGENTINA WORLD CHAMPION
Yes, it should work.
I always pack my data, and add the original size as a long before the data
for the unpack process. I've written a small toool for that, get it here:
http://freak.coolfreepages.com/tools/PackFile.zip
Pack your file like that, and add it to the exe. Now the code you allready
posted would look like this:
Now your original File is store in *Mem2, and *Mem isn't needed anymore.
(Don't forget to add checks, if the memory really got allocated)
Timo
I always pack my data, and add the original size as a long before the data
for the unpack process. I've written a small toool for that, get it here:
http://freak.coolfreepages.com/tools/PackFile.zip
Pack your file like that, and add it to the exe. Now the code you allready
posted would look like this:
Code: Select all
If ReadFile(0,"myexe.exe")
FileSeek(MyOriginalExeSize)
*Mem = AllocateMemory(0,Lof()-MyOriginalExeSize)
ReadData(*Mem,Lof()-MyOriginalExeSize)
Closefile(0)
unpackedsize.l = PeekL(*Mem) ; on the begining is the unpacked size
*Mem2 = AllocateMemory(1, unpackedsize)
UnpackMemory(*Mem + 4, *Mem2) ; *Mem+4 because we don't unpack the size
FreeMemory(0)
End If
(Don't forget to add checks, if the memory really got allocated)
Timo
quidquid Latine dictum sit altum videtur


