MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Protect Your Source Code


Although MATLAB source code (.m) is executable by itself, the contents of MATLAB
source files are easily accessed, revealing design and implementation details. If you do
not want to distribute your proprietary application code in this format, you can use one of
these options instead:


  • Deploy as P-code on page 25-7 — Convert some or all of your source code files to a
    content-obscured form called a P-code file (from its .p file extension), and distribute
    your application code in this format. When MATLAB P-codes a file, the file is
    obfuscated not encrypted. While the content in a .p file is difficult to understand, it
    should not be considered secure. It is not recommended that you P-code files to
    protect your intellectual property.


MATLAB does not support converting live scripts or live functions to P-code files.


  • Compile into binary format on page 25-8 — Compile your source code files using the
    MATLAB Compiler to produce a standalone application. Distribute the latter to end
    users of your application.


Building a Content Obscured Format with P-Code


A P-code file behaves the same as the MATLAB source from which it was produced. The P-
code file also runs at the same speed as the source file. P-code files are purposely
obfuscated. They are not encrypted. While the content in a .p file is difficult to
understand, it should not be considered secure. It is not recommended that you P-code
files to protect your intellectual property.

NoteBecause users of P-code files cannot view the MATLAB code, consider providing
diagnostics to enable a user to proceed in the event of an error.

Building the P-Code File

To generate a P-code file, enter the following command in the MATLAB Command
Window:

pcode file1 file2, ...

The command produces the files, file1.p, file2.p, and so on. To convert all .m source
files residing in your current folder to P-code files, use the command:

Protect Your Source Code
Free download pdf