I'd like to make a function that has many parts. Doing this in something such as Java, which I am familiar with, would be simple. In Mathematica I have these "pieces", which I want to put into a single function:
(* These are just example values for testing. *)
m = 2;
portionOfPT = "friday";
portionOfCT = "pqcfku";
(* I want all of this to happen within the function. *)
ptBlocks = Partition[stringToNumbers[portionOfPT], m]
ctBlocks = Partition[stringToNumbers[portionOfCT], m]
ctMatrix = {ctBlocks[[1]], ctBlocks[[2]]}
ptMatrix = {ptBlocks[[1]], ptBlocks[[2]]}
inversePTMatrix = Inverse[ptMatrix, Modulus -> 26]
(* This is what I want to return.*)
key = Mod[inversePTMatrix.ctMatrix, 26]
The function would be something like this with two parameters:
autoPTAtkHill[portionOfPT_, portionOfCT_, m_] :=
How do I go about making a function containing multiple parts like this that depend on what is returned from the previous.
EDIT:
Does this look correct, and by correct I mean proper. It gives the correct results.
autoPTAtkHill[portionOfPT_, portionOfCT_, m_] :=
Module[{key},
ptBlocks = Partition[stringToNumbers[portionOfPT], m];
ctBlocks = Partition[stringToNumbers[portionOfCT], m];
ctMatrix = {ctBlocks[[1]], ctBlocks[[2]]};
ptMatrix = {ptBlocks[[1]], ptBlocks[[2]]};
inversePTMatrix = Inverse[ptMatrix, Modulus -> 26];
key = Mod[inversePTMatrix.ctMatrix, 26]
];
(*...*)
,not//
reference.wolfram.com/language/guide/Syntax.html $\endgroup$Module
. $\endgroup$key
. YourMod
expression will be returned by the function without it. alsoptBlocks,ctBlocks
etc probably ought to be put in the Module scope unless of course you want them available later as a side effect. $\endgroup$