Encrypted Procedures - Maple Programming Help

 Encrypted Procedures

Maple 2018 lets you encrypt procedures. An encrypted procedure acts and behaves like any normal procedure in Maple, but it can not be viewed or debugged. This provides a way for professional users to share executable procedures while protecting their IP.

The following defines a procedure that implements a block game as described at "http://rosettacode.org/wiki/ABC_Problem#Maple". The procedure is then saved into a repository file called "abc.mla".

After executing the code above we can call the canSpell procedure to test what words can be spelled with the given blocks.

$\mathrm{canSpell}\left("box"\right);$

 ${\mathrm{true}}$ (1)

$\mathrm{canSpell}\left("xoxox"\right);$

 ${\mathrm{false}}$ (2)

Normally the statements of a procedure can be seen via commands such as showstat and eval in Maple. This is true for this procedure too because it was just defined. Note: option encrypted only takes full effect when the procedure is loaded from a library, not when it was just entered from source.

$\mathrm{eval}\left(\mathrm{canSpell}\right);$

 ${\mathbf{proc}}\left({w}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{option}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{encrypted}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{blocks}}{,}{i}{,}{j}{,}{\mathrm{word}}{,}{\mathrm{found}}{,}{N}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{blocks}}{≔}{\mathrm{Array}}{}\left(\left[\left\{{"B"}{,}{"O"}\right\}{,}\left\{{"K"}{,}{"X"}\right\}{,}\left\{{"D"}{,}{"Q"}\right\}{,}\left\{{"C"}{,}{"P"}\right\}{,}\left\{{"A"}{,}{"N"}\right\}{,}\left\{{"J"}{,}{"W"}\right\}{,}\left\{{"H"}{,}{"U"}\right\}{,}\left\{{"I"}{,}{"V"}\right\}{,}\left\{{"A"}{,}{"N"}\right\}{,}\left\{{"B"}{,}{"O"}\right\}{,}\left\{{"G"}{,}{"T"}\right\}{,}\left\{{"E"}{,}{"R"}\right\}{,}\left\{{"G"}{,}{"T"}\right\}{,}\left\{{"D"}{,}{"Q"}\right\}{,}\left\{{"F"}{,}{"S"}\right\}{,}\left\{{"E"}{,}{"R"}\right\}{,}\left\{{"F"}{,}{"S"}\right\}{,}\left\{{"L"}{,}{"Y"}\right\}{,}\left\{{"C"}{,}{"P"}\right\}{,}\left\{{"M"}{,}{"Z"}\right\}\right]\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{word}}{≔}{\mathrm{StringTools}}{:-}{\mathrm{UpperCase}}{}\left({\mathrm{convert}}{}\left({w}{,}{\mathrm{string}}\right)\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{N}{≔}{\mathrm{numelems}}{}\left({\mathrm{blocks}}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{for}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{i}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{to}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{length}}{}\left({\mathrm{word}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{do}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{found}}{≔}{\mathrm{false}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{for}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{j}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{to}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{N}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{do}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{word}}{[}{i}{]}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{in}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{blocks}}{[}{j}{]}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{then}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{blocks}}{[}{j}{]}{≔}{\mathrm{blocks}}{[}{N}{]}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{N}{≔}{N}{-}{1}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{found}}{≔}{\mathrm{true}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{break}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end do}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{not}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{found}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{then}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{false}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end do}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{true}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (3)



Let's restart and then reference the procedure from the "abc.mla" repository that we saved it in:

$\mathrm{restart};$

We can use the procedure:

$\mathrm{canSpell}\left("good"\right);$

 ${\mathrm{true}}$ (4)

But we can no longer see the implementation:

$\mathrm{eval}\left(\mathrm{canSpell}\right);$

 (5)