Presumably if it's a Free CDF (non-enterprise) then all the code needs to be contained in the CDF itself.
If the code could be read in from an external Encoded .m file then it still would be reverse-engineerable (a word?) by using Information on the function and parameter names. Even if they were Protected and ReadProtected this would still be true if one first Unprotects them and then removes the ReadProtected attribute. However, if they are also Locked this is not true. Remember though (not you Daniel, I know you know all this!) if they are Locked then some things one might want to do with the functions may not be doable. For example then SetOptions will not work on them as well as some other things--worth keeping in mind, and probably not a show stopper for a CDF.
There is an approach using these ideas that may work.
So I have put the file from "ExampleData/Collatz.m" on my desktop at "/Users/dreiss/Desktop/Collatz.m" just so I can play around with it and make a modification. In this version of the file I have added ReadProtection and Locking as well as Protection for the code. Here is the code in that file with these changes:
BeginPackage["Collatz`"]
Collatz::usage =
"Collatz[n] gives a list of the iterates in the 3n+1 problem,
starting from n. The conjecture is that this sequence always
terminates."
Begin["Private
"]
Collatz[1] := {1}
Collatz[n_Integer] := Prepend[Collatz[3 n + 1], n] /; OddQ[n] && n >
0
Collatz[n_Integer] := Prepend[Collatz[n/2], n] /; EvenQ[n] && n > 0
End[ ] SetAttributes[Collatz,{Protected,ReadProtected,Locked}]
EndPackage[ ]
Name a file where an encoded version of Collatz.m will be temporarilly placed.
encoded = ToFileName["/Users/dreiss/Desktop/","encoded"]
And now Encode it
Encode["/Users/dreiss/Desktop/Collatz.m",encoded]
Now bring it back into the notebook using Import
Import[encoded,"String"]
(* The output goes here but the Wolfram Community has difficulty displaying it presumably because of all the odd character sequences *)
Of course, at this point there is no definition for the Coalitz function
?Collatz
gives
Information::notfound: Symbol Collatz not found.
Now copy the result of the above import into the argument of ImportString telling ImportString that this content is a Package.
When the following is executed the package is read in:
ImportString[<<output of the above Import>> "Package"]
Now ?Collatz has a definition
?Collatz
gives
Collatz[n] gives a list of the iterates in the 3n+1 problem,
starting from n. The conjecture is that this sequence always
terminates.
And Information[Collatz] does not tell you about its internals but it would have if it were not Locked and you had removed its Protection and ReadProtection
Information[Collatz]
gives
Collatz[n] gives a list of the iterates in the 3n+1 problem,
starting from n. The conjecture is that this sequence always
terminates.
Attributes[Collatz]={Locked,Protected,ReadProtected}
Finally one can use these ideas to create a Manipulate which has Encoded package material by using the Initialization Option.
I am attaching a notebook to this posting with the full material above along with a Manipulate contained in it illustrating the idea. I am also attaching the resulting CDF when that Manipulate is exported as a CDF as well as the modified Collatz.m file
I hope this helps... there are presumably other approaches that one may use to hide the internals of function and parameter definitions using Locked and so on, keeping in mind that Locked is a quite draconian thing to add to a parameter or functions attributes and may break other things that you may want to do.
Attachments: