A method for protecting software is provided, where source code for the
software has a first directive marking an encryption beginning point and
a second directive marking an encryption end point. The method contains
the steps of: processing the source code to identify a block of code
between the first and second directives; compiling the source code to
produce a binary file; generating a valid key and a random string;
encrypting the random string with the key to obtain a first encrypted
value; encrypting a portion of the binary file corresponding to the block
of code with the valid key to obtain a second encrypted value; and
replacing the portion of the binary file corresponding to the block of
code with the second encrypted value and code that can decrypt the second
encrypted value during execution of the software.