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);

回答(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 个评论

"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.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

标签

提问:

2018-3-21

编辑:

Jan
2018-3-21

Community Treasure Hunt

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

Start Hunting!

Translated by