Question: Help programming is not my strong point....One to One and onto

 

Let NULL = {0,1,2,. . ., 255} denote the set of integers from 0 to 255. Consider for each element a in NULL  the function f(a) : NULL  ->NULL defined by the rule  f(a)(x) = a*x mod 256  for all x in NULL . Note that since n mod 256  (or modp(n,256) is the remainder when n is divided by 256 each such f(a) is a well defined function from NULL  to itself. Note that there is one such function for each a  in NULL .  Note that since f (a) depends on a we should write it as NULL :NULL  ->NULL and we could try to define using the Maple code: f[a]:=x->modp(a*x,256); Unfortunately this doesn't work. However the following method does work.  This procedure if given input a will output a function (really a procedure)  f (a) such that f(a)(x)= a*x mod 256.  

>f:=proc(a) x->modp(a*x,256); end proc:

Here are examples of how it can be used: Note that f(a) : NULL  ->NULL. So f(a)(x) =a*x mod 256; For example if we take a = 13, we have:

>f(13);

 

>f(13)(1), f(13)(2), f(13)(200);

Note that we can use map to obtain the image of the set {1,2,200} under the mapping f(13).

>map(f(13),{1,2,200});

f:=proc(a) x->modp(a*x,256); end proc:

f(13);

proc (x) options operator, arrow; modp(13*x, 256) end proc

(1)

f(13)(1), f(13)(2), f(13)(200);

13, 26, 40

(2)

map(f(13),{1,2,200});

{13, 26, 40}

(3)

 

 

 

(a) Determine for which values of a in NULL the functions f(a) are onto. Use Maple to determine this even if you might be able to figure it out using some theory. The answer should be a list containing 128 integers.

 

(b) Determine for which values of a in NULL the function f(a) is 1-1. You may use the fact that a linear mapping from a finite set with n elements to a finite set with n elements is 1-1 if and only if it is onto.

 

(c) It is a fact that if  the function f(a) has an inverse then its inverse has the form f(b) for some b in NULL . Note for example, that f(13) and f(197) are inverses since their composition applied to x is x for all x from 0 to 255 as verified in the following computation:

inverse:=true:
for x from 0 to 255 do
if (f(13)@f(197))(x)<> x or (f(197)@f(13))(x) <> x then inverse:=false; break;
end if;
end do:
inverse;

true

(4)

 

 

Find the set of all pairs {a,b} such that f(a) and f(b) are inverses of each other. So your answer to (c) should be a set of "pairs" including the pair {13,197}. Note that this way we don't count {13,197} as different from {197,13}. You should have 66  "pairs". A few are inverses of themselves so these pairs will be "degenerate", that is, in some cases we have f(a) is its own inverse. It might help to write a procedure InverseCheck with input a and b and output true if f(a) and f(b) are inverses of each other and false if not. Then you can go through all possible a and b and find the pairs for which InverseCheck(a,b) returns true.

 

(d) Use select to pick out the "degenerate pairs" in the output to (c). Note that you can use x->evalb(nops(x) = 1) to pick out the "pairs" with only one element.

 

 

 

 

 

``

 

Download 2.mw

Please Wait...