PowerBASIC Peer Support Forums
 

Go Back   PowerBASIC Peer Support Forums > User to user Discussions > PowerBASIC for Windows

Notices

PowerBASIC for Windows User to user discussions about the PB/Win (formerly PB/DLL) product line. Discussion topics include PowerBASIC Forms, PowerGEN and PowerTree for Windows.

Reply
 
Thread Tools Display Modes
  #1  
Old Jul 11th, 2006, 01:56 PM
Mike Trader Mike Trader is offline
Member
 
Join Date: Jan 2001
Location: LA, CA, USA
Posts: 1,689
Low overhead text encryption

After discovering that all my text strings and embedded text files
are visible by examining my .exe with notepad! (horrifying)

I have need for a simple text encrytion algo that I can implement
to obfuscate the ascii characters. It does not need to be super
secure, just enough to turn ASCII into binary.

I suppose I could go through the text Byte by Byte and just convert
the Bytes into their binary couterpart with a union, but is there
a nice little encyption algo that might be faster/better?

------------------
Kind Regards
Mike

[This message has been edited by Mike Trader (edited July 12, 2006).]
Reply With Quote
  #2  
Old Jul 11th, 2006, 02:05 PM
Paul Franks Paul Franks is offline
Member
 
Join Date: Mar 2006
Posts: 468
Mike,

Another, very simple, alternative is to package and encrypt your
executable (and DLLs and other files) into a single .exe with a
packager like Molebox Pro.

I have used it very successfully for a while. For $119, it's a
lot cheaper than the hours of development that would otherwise
be required to do something from scratch. You can set you own
encryption key, making your .exe very difficult to crack.



------------------

--pdf
__________________

--pdf
Reply With Quote
  #3  
Old Jul 11th, 2006, 02:13 PM
james klutho james klutho is offline
Member
 
Join Date: Apr 2001
Location: Littleton, CO, USA
Posts: 460
You might try using CHR$() as a simple encryption technique. Borje even wrote a TXTtoCHR program that does this.

MSGBOX CHR$(77,105,107,101) displays "Mike" and is confusing to look at with a hex editor.

------------------
Reply With Quote
  #4  
Old Jul 11th, 2006, 02:18 PM
Michael Mattias Michael Mattias is offline
Member
 
Join Date: Aug 1998
Location: Racine WI USA
Posts: 26,189
> MSGBOX CHR$(77,105,107,101) displays "Mike" and is confusing to look at with a hex editor.

I would think if all the arguments are numeric literals that would be evaluated at compile time.

__________________
Michael Mattias
Tal Systems Inc.
Racine WI USA
mailto:mmattias@talsystems.com
www.talsystems.com
Reply With Quote
  #5  
Old Jul 11th, 2006, 02:22 PM
Russ Srole Russ Srole is offline
Member
 
Join Date: Mar 2000
Location: Burbank, Ca.
Posts: 1,391
You might want run you exe through upx. It will compress it down and that's bound to obfuscate some of your text.

------------------
Reply With Quote
  #6  
Old Jul 11th, 2006, 02:22 PM
Michael Mattias Michael Mattias is offline
Member
 
Join Date: Aug 1998
Location: Racine WI USA
Posts: 26,189
Simple encryption?

XOR works real nice for that.
Something like..
Code:
FUNCTION CryptedString  (StrIn AS STRING, CryptKey AS STRING) AS STRING
   LOCAL StrPos AS LONG, KeyPos AS LONG, KeyLen AS LONG, StrOut AS STRING
   LOCAL CharIn AS BYTE, kCharIn AS BYTE, CharOut AS BYTE

   KeyLen = LEN(CryptKey)
   StrOut = STRING$ (LEN(StrIn), 0)  ' binary zeros as default
   FOR StrPos = 1 TO LEN (StrIn)
          KeyPos = (StrPos MOD(KeyLen -1)) + 1  ' add one to convert range (0:len-1)
                                                ' to range (1:LEN)
          CharIn                 = ASC(StrIn, StrPos)
          kCharIn                = ASC (CryptKey, KeyPos)
          CharOut                = CharIn XOR kCharIn
          MID$(StrOut, StrPos,1) = CHR$(CharOut)

   NEXT StrPos
   FUNCTION = StrOut
END FUNCTION
Call it once with the plain text string and a key, you get an encyrpted string out' call it with the encrypted string and the same key, get back the original.

__________________
Michael Mattias
Tal Systems Inc.
Racine WI USA
mailto:mmattias@talsystems.com
www.talsystems.com
Reply With Quote
  #7  
Old Jul 11th, 2006, 04:08 PM
Mike Trader Mike Trader is offline
Member
 
Join Date: Jan 2001
Location: LA, CA, USA
Posts: 1,689
paul,

molebox pro will help you to:
- create one or multiple packages for an application.
- protect your media files, data files and dlls from unauthorized access.
- manage level packs, add-ons, updates, patches minimizing their file size (pro version only).
- compress and encrypt your application and all the files it requires.
- embed dlls into exe files (pro version only).
- secure application integrity and avoid dll conflict.
- make program cracking extremely difficult.

molebox supports applications created with intel c++,
microsoft visual c++, borland c++, borland delphi,
microsoft visual basic, blitz basic.
molebox pro utility requires windows 95 osr2/nt 4 or later,
windows 2000/xp is recommended. packed application will
work under windows 95/nt 4 or better systems.

i can do all that with my own pre-compile app and execryptor, the
only piece missing is the encryption of the embedded files like
text files.

the exe is compressed and protected with execryptor, but the text
is still visible.

michael,
i like that, but its char by char... both directions.
perhaps i could use a union and do it in 32 or 64 byte chunks...

also came across huffman
http://www.powerbasic.com/support/pb...ad.php?t=23400
anyone had experience with this?

james,
thx. found it.. the link is:
http://www.powerbasic.com/support/pb...ad.php?t=23152

essentially:
Code:
              if len(txt) then
                 txt2 = "chr$("
                 for i = 1 to len(txt)
                    txt2 = txt2 & format$(asc(txt, i)) & ", "
                 next i
                 txt2 = left$(txt2, len(txt2) - 2) & ")"
              end if
char by char again...

im thinking something like:

Code:
union encrypttexttype ' 
  varenc  as extended  ' 10 bytes
  stext   as string*10 ' 10 bytes
end union
that will do 10 bytes ata time... but i want need speed captain!

what variable type has 32 bytes to it?


[this message has been edited by mike trader (edited july 11, 2006).]
Reply With Quote
  #8  
Old Jul 11th, 2006, 05:03 PM
Chris Holbrook Chris Holbrook is offline
Member
 
Join Date: Aug 2005
Location: UK
Posts: 2,978
There's some serious-looking string encryption in the source code forum somewhere, look under GOST, if a job's worth doing etc

------------------
Reply With Quote
  #9  
Old Jul 11th, 2006, 05:12 PM
Paul Franks Paul Franks is offline
Member
 
Join Date: Mar 2006
Posts: 468
Quote:
Originally posted by Mike Trader:

- Compress and encrypt your application and all the files it requires.
Quote:
I can do all that with my own pre-compile app and EXEcryptor, the
only piece missing is the encryption of the embedded files like
text files.
Molebox Pro will include your text files in the encrypted .exe,
and your application can access them as though they were ordinary
files on the local disk drive, without any changes to your existing
code.


------------------

--pdf
__________________

--pdf
Reply With Quote
  #10  
Old Jul 11th, 2006, 06:44 PM
Mike Trader Mike Trader is offline
Member
 
Join Date: Jan 2001
Location: LA, CA, USA
Posts: 1,689
gost:
http://www.powerbasic.com/support/pb...ad.php?t=23531


pbtwofish, blowfish, des, skipjack, gost, tea, rc4, cryptoapi,
http://www.powerbasic.com/support/pb...ad.php?t=17891

probably too much for this job. just need something light and fast
to obfuscate the text. rememberits burried in the middle of an
exe so unless you knew where it started, you would have to go through
the entire exe trying decoding techniques.

perhaps this is what i need... (unicode)
http://www.awes.com/obfuscator/


[this message has been edited by mike trader (edited july 11, 2006).]
Reply With Quote
  #11  
Old Jul 11th, 2006, 09:46 PM
Mike Trader Mike Trader is offline
Member
 
Join Date: Jan 2001
Location: LA, CA, USA
Posts: 1,689
From an idea on a VB forum GASP!!!

Pretty slick in PB of course....

Code:
#COMPILE EXE "BitCrypt.exe"
#DIM ALL 

'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤'
FUNCTION BitEncrypt( sPtr AS DWORD, sLen AS LONG ) AS LONG
 
  LOCAL i AS LONG 
  LOCAL Bite() AS BYTE 
 
    REDIM Bite(1:sLen) AT sPtr ' one byte for each char

    FOR i = 1 TO sLen ' MSGBOX CHR$(Bite(i))
      BIT TOGGLE Bite(i), 7 ' Toggle MSB - zero based 
    NEXT

  FUNCTION = 1 ' String Encoded
        
END FUNCTION  
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤'
FUNCTION PBMAIN AS LONG 
                      
  LOCAL sTemp AS STRING

    sTemp = "C is not a programming language, it's punishment for evil deeds in a former life."         
                
    MSGBOX sTemp,64,"Starting String" 
    CALL BitEncrypt( STRPTR(sTemp), LEN(sTemp) )
    MSGBOX sTemp,64,"Encrypted" 
    CALL BitEncrypt( STRPTR(sTemp), LEN(sTemp) )
    MSGBOX sTemp,64,"Decrypted" 

END FUNCTION  

'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤'
Coupled with Michaels Key ideas I think I got a winnner!

------------------
Kind Regards
Mike

[This message has been edited by Mike Trader (edited July 11, 2006).]
Reply With Quote
  #12  
Old Jul 12th, 2006, 05:33 AM
Mike Trader Mike Trader is offline
Member
 
Join Date: Jan 2001
Location: LA, CA, USA
Posts: 1,689
When I use the above function on a larger text file in my pre-compile app,
I get a Windows error message:
"The instruction at 0x7C911e58 referenced memory at 0x00000001. Memory could not be read"

Sometimes it just crashes, but allways at the very last instruction.

This occurs at the VERY LAST instruction of my large app. The
END FUNCTION statement of PBMAIN.

If I put a MSGBOX just before it, the program halts at that point
and eveything is fine. When I dismiss the MSGBOX the next instruction
is the END FUNCTION which produces the above error window.

This ony happens when I use the code above to encrypt the text.
I have checked it and recheked it and I am not going out of
scope of the arrays.

Can anyone see what might be the problem?


------------------
Kind Regards
Mike



[This message has been edited by Mike Trader (edited July 12, 2006).]
Reply With Quote
  #13  
Old Jul 12th, 2006, 09:07 AM
Michael Mattias Michael Mattias is offline
Member
 
Join Date: Aug 1998
Location: Racine WI USA
Posts: 26,189
>I like that, but its Char by Char... both directions.

It looks like you have found a solution but....

.. <U>all</U> encryption is done character by character.

__________________
Michael Mattias
Tal Systems Inc.
Racine WI USA
mailto:mmattias@talsystems.com
www.talsystems.com
Reply With Quote
  #14  
Old Jul 12th, 2006, 09:09 AM
Michael Mattias Michael Mattias is offline
Member
 
Join Date: Aug 1998
Location: Racine WI USA
Posts: 26,189
>The instruction at 0x7C911e58 referenced memory at 0x00000001. Memory could not be read"
>Sometimes it just crashes, but allways at the very last instruction.
>This occurs at the VERY LAST instruction of my large app.

No, it does not occur on the very last instruction. The error may have occurred earlier but just doesn't show up until later

That the memory pointer is 0x000000001 sure looks like a fencepost ("off by one") error somewhere.... somewhere in the application code (not shown).



[This message has been edited by Michael Mattias (edited July 12, 2006).]
__________________
Michael Mattias
Tal Systems Inc.
Racine WI USA
mailto:mmattias@talsystems.com
www.talsystems.com
Reply With Quote
  #15  
Old Jul 12th, 2006, 09:13 AM
Eddy Van Esch Eddy Van Esch is offline
Member
 
Join Date: Jan 2001
Location: Belgium
Posts: 2,015
Quote:
Originally posted by Michael Mattias:
.. <U>all</U> encryption is done character by character.
Not all. Block ciphers (like AES, MARS, RC6, Serpent, Twofish,...) all process a block of bytes in one operation.
If your plaintext is not exactly one block long, you must add bytes to make its length a multiple of the block size. Then chop it up to encrypt the plaintext, one block at the time.

Stream ciphers in general, process one byte at the time.

Kind regards

------------------
Eddy
email: raimundo4u at yahoo dot com
www.devotechs.com -- HIME Huge Integer Math and Encryption library--

[This message has been edited by Eddy Van Esch (edited July 12, 2006).]
__________________
Eddy
www.devotechs.com -- HIME Huge Integer Math and Encryption library--
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:53 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright © 1999-2010 PowerBASIC, Inc. All Rights Reserved.
Error in my_thread_global_end(): 2 threads didn't exit