Hello!
I have been developing a plug-in for Rhino for the past 3 months or so in python script. After I finish it, I want to publish on a forum, but I don’t want other people to see my code. Is there any way to encrypt the code so that no one can see what I’ve coded?
Thank you
As far as I’m aware, Python cannot be obfuscated.
@piac, could your work on the GhPython add-on compiler be of use here? Otherwise, you could port your plugin to C# and distribute it as a RHP.
On the other hand, if you’ll allow me to get a little bit philosophical, I’d urge you to consider whether it really matters if other people see your code. It all depends on whether you’re focussed on selling yourself or your software, I guess. What are you most worried about?
Edit: Just saw that you were referring to a Rhino plugin, not a Grasshopper one!
One approach would be to compile your IronPython code to a .dll assembly and then import functions/classes from this assembly and use them in a script. See these links:
http://www.voidspace.org.uk/ironpython/dark-corners.shtml
That said, I would echo Will’s sentiments
/Anders
Thank you for your answer.
So I understand there is a way to do that by writing the scripts in C#?
Thank you,
Chirila Tudor.
Edit: i use rhinosyntax, so if there is any way to write all my scripts in c# using rhinosyntax, that would be awesome.
Thanks,
Tudor
Sent from Yahoo Mail on Android
From:“Anders Holden Deleuran” <steve@mcneel.com>
Date:Mon, Nov 17, 2014 at 17:48
Subject:[McNeel Forum] [Rhino Developer] How to encrypt my code?
November 17
One approach would be to compile your IronPython code to a .dll assembly and then import functions/classes from this assembly and use them in a script. See these links:
http://blogs.msdn.com/b/srivatsn/archive/2008/08/06/static-compilation-of-ironpython-scripts.aspx
http://www.voidspace.org.uk/ironpython/dark-corners.shtml
That said, I would echo Will's sentiments :wink:
/Anders
To respond, reply to this email or visit http://discourse.mcneel.com/t/how-to-encrypt-my-code/13939/3 in your browser.
To unsubscribe from these emails, visit your user preferences.
This compiler is probably what you are looking for
…I’ll cut my longer answer and just refer to the discussion about code encryption in the very old first beta thread for the Rhino Script compiler.
Is there any chance to make an exe with py2exe and inject it in rhino with, I don’t know, Olly dbg maybe? Will that work?
Thank you,
Tudor
Hi Tudor, some time ago Dale Fugier provided a cool tutorial along with some tools to encrypt RhinoScript files and make a .Net plug-in from it: http://wiki.mcneel.com/developer/scriptsamples/rhinoscriptplugin (also watch the video!)
You can hack into this to use it for Python. Some things to consider:
Rename your python file to .rvb so the RhinoScriptEncrypter can recognize and encrypt it.
You’ll have to modify the RhinoScriptCommand.cs in order to load and run python files:
- in lines 37 and 47 change _-RunScript to _-RunPythonScript
- further add a pair of brackets “()” in line 47 to make a valid python function call.
Edit: Of course your main function should just be named like the command.
Thank you so much, I will take a look at it.
Thanks for the tip @Jess, it helps a lot.
I forked the RhinoScriptEncrypter to enable .Py files encrypting to .Pyx:
https://github.com/MatthieuArnold/RhinoScriptEncrypter/blob/master/PythonScriptEncrypterCommand.cs
I’ve got a small issue with your modified RhinoScriptCommand.cs : the python script doesn’t stay loaded, and the second call fails:
string.format("_-RunPythonScript ({0}())",EnglishName);
It works when I just disable this part and the _bIsLoaded
test but I’m not sure this is the right way to solve this. @dale, what do you think?
This is correct. Unlike RhinoScript, which retains previously loaded scripts so they can be quickly run again at a later time, the Rhino.Python engine is reinitialized everytime a script is run. Thus the “is loaded” concept does not apply.
Does this help?
– Dale
Thanks @Dale for the details, it helps! Happy new year