0

I have a simple equations to solve and I want to do it in matlab,however, there are some years, that I didn't use and kinda forgot it. So this

linsolve({(387=mod(324*a+b,601)), (491=mod(381*a+b,601))},{a,b}),

doesn't give me a result, due to an a mistake I am not able to find. the original set of equations is:

(324a+b)mod601=387 (381a+b)mod601=491,

affine cipher apparently. Thank you!

July
  • 15
  • 1
  • 1
  • 7

2 Answers2

0

Try this First make you function describing equations in a separate file with the name myfunc.m:

function y=myfunc(x)
    y(1)=mod(324*x(1)+x(2),601)-387;
    y(2)=mod(381*x(1)+x(2),601)-491;

than apply fsolve like

x0=[1; 1];
[ans,err]=fsolve(@myfunc,x0)

x0 is a guess to the solution. This method gives an approximate numerical solution around your guess.

fsolve solves a system of nonlinear equations. It has many parameters, you can read about them in MATLAB help.

Let me know if it works

freude
  • 3,632
  • 3
  • 32
  • 51
  • sorry i have made a mistake, y1 and y2 should be replaced by y(1) and y(2). I have corrected the function – freude Nov 30 '14 at 21:25
  • thank you again! the equation solved, however, I got strange numbers, but it is an another story! – July Nov 30 '14 at 21:37
  • check equations one more time and play with the guess x0. At the beginning I have messed up with signs in the equations. I have got these numbers for your example: 1.8246, -204.1579 with maximal absolute error 0.0147 – freude Nov 30 '14 at 21:41
  • yes, I've got the same numbers. I suspect there can be a mistake in formulation but with every change I will use your base, so it is ok! – July Nov 30 '14 at 21:46
0

Starting with these equations,

(324*a + b) mod 601 = 387,
(381*a + b) mod 601 = 491,

we can conclude that

((381*a + b) - (324*a + b)) mod 601 = (491 - 387) mod 601

and therefore (performing the obvious simplifications inside the parentheses on the left-hand side and fully evaluating the right-hand side),

(57*a) mod 601 = 104.

That looks a lot easier to solve than the system of two equations in two variables. Once you know a, you can return to one of the original equations and solve for b.

David K
  • 3,147
  • 2
  • 13
  • 19