How can I use the function affinecrypt in Matlab

Hi I want to use the function affinecrypt and I have a code for it that I got from http://www.math.umd.edu/~lcw/MatlabCode/ But when I try to use it in Matlab it dosnt work and I get the answer Error: Function definitions are not permitted in this context. This is the code I am trying to use:
function y = affinecrypt(x,a,b); % This function performs the affine encryption function % y = a x + b mod 26 % where (a,26) = 1 % The result is kept in numerical representation
xnum=text2int(x); ynum = mod( a*xnum + b, 26); y=int2text(ynum);

1 Comment

Wow, this is the 5'th time in the last 30 minutes, where I ask a user to format the code such, that it is readable. Please read http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup.

Sign in to comment.

Answers (2)

You did not tell us, what you try to do with this code snippet. When do you get the error message? Do you try to insert this piece of code in the command window? This cannot work. Safe this file to a folder, which is included in your path (see: doc addpath) and call it from the command window or any other function with the input arguments:
y = affinecrypt(23, 4, 117) % Or what ever your parameters are
I am trying to solve the following problem: encrypt the plaintext message Cleopatra using the affine function 7x+8 and the solution should be affinecrypt('cleopatra',7,8) but when I type it in it dosnt work.

1 Comment

Jan
Jan on 21 Mar 2018
Edited: Jan on 21 Mar 2018
"It doesn't work" is not useful to explain a problem. Please do not let us guess the details. Which error message do you get?
Please post comments in the section for comments, and not as an answer. This message belongs to the original question, so better insert it there by editing it.
And, please, bo nilsson, format your code properly. I do not understand, why to ignore that I have asked for it. But it should be in your interest to offer a code which can be read as easy as possible.

Sign in to comment.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Asked:

on 21 Mar 2018

Edited:

Jan
on 21 Mar 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!