# How can I encrypt my CDF code?

GROUPS:
 Gregory Lypny 1 Vote Is there some way I can encrypt my CDFs (without too much pain) to keep the code from prying student eyes?
2 years ago
7 Replies
 David Reiss 1 Vote I think that the short answer (with the "not too much pain" condition) is "no." Hopefully Wolfram Research has a methodology in its development pipeline that will add this sort of functionality in a future release.
2 years ago
 Bianca Eifert 1 Vote Do your prying-eyed students have Mathematica? In that case you could take a look at encrypted packages (see Encode). That would also work if they have Player Pro, which I seriously doubt though... If the CDFs have to work with the Player, I second David's "no".
2 years ago
 Hi Bianca and David,Thanks for your responses. That's bad news for me because I'll have to go back to using static PDFs instead of Mathematica for teaching. All of my students have access to Mathematica because we have a site license, but it isn't reasonable to require first-year students in some courses to install Mathematica if all they will use it for is quizzes and assignments. CDFs make sense. I can obscure answers and code expiry dates in CDFs, but that's primitive. My intermediate undergrads and grad students use CDFs and Mathematica. It would be nice to be able to present interactive demos in class and then have advanced students do analytical work using Mathematica, but if they can rip off the code in my CDFs to do their assignments, it defeats the purpose. What a shame.
2 years ago
 Why does the code need to be in the (same) CDF as the assignments?
 David Reiss 2 Votes 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 > 0Collatz[n_Integer] := Prepend[Collatz[n/2], n] /; EvenQ[n] && n > 0End[ ] 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[<> "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 fileI 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: