Message Boards Message Boards

5 Replies
0 Total Likes
View groups...
Share this post:

Creating a function or class

Posted 9 years ago

I have some code that in mathematica that decrypts a RSA cryptation. I would like to make a function RSACrack[n,e, crypto] so that I sort of just bake in the code into that function and get a return value from it. How do I do this with mathematica? I attached the code I would like to "abstract(?)" into a simple function line.

Please let me know if it's unclear what I seek! Thanks in advance.

POSTED BY: Anton Holgersson
5 Replies

Great! The main thing to watch out for is being sure that all parameters that should be localized in the Module are included in the list of the first argument so that nothing leaks out.

POSTED BY: David Reiss

I solved my problem! It was pretty simple in the end, what I was seeking was something like RSACrack[n, e, crypto_] :=Module[{} <code here>] And then I basically just threw my old code in there with some minor adjustments to make the code all dynamic/automatic.

POSTED BY: Anton Holgersson

Give it a try and then post any questions and code attempts that you have and I or others will take a crack at advising your next steps.

POSTED BY: David Reiss

Perhaps the best way to help you along your way with this is to point you to this tutorial:

And here is a tutorial on defining functions:

as well as two links that talk about how to localize variables:


Once you have this under your belt you will be in a position to take the set of computations that are in your notebook, place them in a module to localize those variables that should not be exposed, and then create a function definition for those parameters that you want to supply as arguments to your function.

POSTED BY: David Reiss

Thank you David! I will look into these links.

POSTED BY: Anton Holgersson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract