Scripting Guide > Programming Methods > Encrypt and Decrypt Scripts > Working with Expressions in an Encrypted Script
发布日期: 11/15/2021

Working with Expressions in an Encrypted Script

An encrypted script might not run the same as the unencrypted script if the script attempts to convert parts of itself from expressions back to character strings. This is necessary to keep the script encrypted. You can avoid this problem by using the expression manipulation functions such as Arg(), Head(), Substitute(), and so on. You can also use Parse() to make expressions from character strings that are part of the encrypted script.

For example, here is a script that modifies an expression the wrong way for encryption:

ex = Expr(
	aaa = 20;
	Show( aaa );
);

// Wrong, don't do this.

temp = (Parse( Substitute( Char( Name Expr( ex ) ), "aaa", "bbb" ) ));
temp;

The script fails when encrypted because Char() is unable to break the encryption of the expression stored in ex. A second example follows:

ex = Expr(
	aaa = 20;
	Show( aaa );
);

// Best choice if it works for you.

temp = Substitute( Name Expr( ex ), Expr( aaa ), Expr( bbb ) );
temp;

A third example, though not optimal, follows:

ch = "aaa = 20; Show(aaa);";

/* Leaves the ch variable holding unencrypted text

and Temp holds an unencrypted expression.*/

temp = Parse( Substitute( ch, "aaa", "bbb" ) );
temp;

You might prefer the third choice over the second choice because it looks easier to understand; be aware that you might want to clear variables like ch and Temp when you are done with them. You probably encrypted the script to keep other folks from reading it, and they will definitely be able to see the content of variables when you are done.

需要更多信息?有问题?从 JMP 用户社区得到解答 (community.jmp.com).