Group Abstract Group Abstract

Message Boards Message Boards

How can I encrypt my CDF code?

GROUPS:

Is there some way I can encrypt my CDFs (without too much pain) to keep the code from prying student eyes?

POSTED BY: Gregory Lypny
Answer
2 months ago

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.

POSTED BY: David Reiss
Answer
2 months ago

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".

POSTED BY: Bianca Eifert
Answer
2 months 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.

POSTED BY: Gregory Lypny
Answer
2 months ago

Why does the code need to be in the (same) CDF as the assignments?

POSTED BY: Daniel Lichtblau
Answer
2 months ago

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.

POSTED BY: David Reiss
Answer
1 month ago

Is this above or below your definition of "not too much pain"? ;-)

POSTED BY: David Reiss
Answer
1 month ago

Nice one, David! I appreciate your thoroughness, and I will go over your steps because I have learned more about Mathematica from Mathematica discussion boards than anywhere else; and you've touched on interesting things that could be used in a consulting project. But as for incorporating these steps into the creation of encrypted university material, it is far too much pain in its complexity and the time it takes away from the real business of teaching and research. Hope Wolfram catches up to the game on this issue. Point-and-click encryption for PDFs is built right into Preview on Macs. I can do the same in RAD environments like LiveCode in a minute or two. As a matter of fact, I've been wondering whether it would be better, for some teaching applications, to export my Mathematica functions to C (that, I think I could learn to do) and then use them as externals in encrypted apps that I build with LiveCode.

Gregory

POSTED BY: Gregory Lypny
Answer
1 month ago