0
$\begingroup$

I am trying to create a proprietary function as discussed in this link:

How to distribute proprietary Mathematica code

So I create a function and dump it into a file

f[x_Real] := x^2 + 1;
SetAttributes[f, {ReadProtected, Locked}]

SetDirectory[$TemporaryDirectory];
DumpSave["notEncodedFunction.mx", f]

After I quit and load the file it works

Quit[]

SetDirectory[$TemporaryDirectory];
Get["notEncodedFunction.mx"]
f[5.1]

27.01

I now try to repeat the above but with an encoded version and it fails

Quit[]

SetDirectory[$TemporaryDirectory];
Encode["notEncodedFunction.mx", "encodedFunction.mx"];

Get["encodedFunction.mx"];
f[5.1]

f[5.1]

I feel I am overlooking something obvious here but what?

PS: If copying the code to the notebook please split put the Quit[] line in its own cell

$\endgroup$
2
  • 2
    $\begingroup$ The only examples I see for Encode use plain text files, not binary formats like MX. I can't say whether what you are seeing is a bug or not. But I am curious what the intent is for encoding an MX file - the file format is not readable except by the kernel. $\endgroup$
    – Jason B.
    May 1, 2023 at 16:38
  • $\begingroup$ Following the answer in the link: "...to use a combination of encryption, DumpSave..." I took "encryption" to refer to Encode $\endgroup$ May 1, 2023 at 16:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.