Mathematica and Number Theory

advertisement
Mathematica as a Cryptographic Tool
Section 4.1, T. Barr, Invitation to Cryptology
Mathematicar is a general purpose computer algebra system (CAS)
that has a vast array of symbolic and graphical manipulation capabilities.
In particular, it has the ability to perform integer division and remainder
extraction, factorization, and greatest common divisor determination for
large integers that are well out of the scope of floating point representation
currently used in most hand-held calculators.
A Mathematica notebook is structured in cells, demarcated by vertical marks at the right-hand side of the screen. You type instructions into
a cell and then evaluate it by pressing shift-return on the keyboard. All
functions in Mathematica require square brackets [ ] surrounding the arguments. Built-in functions all begin with capital letters. The Help menu
provides help on syntax and other matters.
Wolfram Alpha is a much stripped-down online version of Mathematica that functions a bit like a mathematical Google—just type in a mathematical question and it will attempt to interpret and solve it. You might
find it useful for some of the purposes shown here.
A Few Mathematica Functions
Value is integer quotient when
the first argument is divided
by the second
Value is the remainder when
the first argument is divided
by the second
Value is its factorization into
powers of primes
Value is the greatest common
divisor of the two
Value is the first argument
raised to the power of the
second argument modulo the
third argument
Quotient[ , ]
Arguments are an integer and
a positive integer
Mod[ , ]
Arguments are an integer and
a positive integer
FactorInteger[ ]
Argument is an integer
GCD[ , ]
Arguments are positive integers
PowerMod[ , , ]
Arguments are integers; the
third must be positive
Prime[ ]
Argument is a positive integer
n
Value is the nth prime
PrimeQ[ ]
Argument is a positive integer
n
Value is True if n is prime and
False otherwise
1
Arguments are the type of random number (Integer, Real,
e.g.) and the range from which
the value is selected
Random[ , ]
Value is a pseudorandom number from the specified range
Below are some examples of how these functions can be used.
In[51]:=
Out[51]=
In[52]:=
Out[52]=
Quotient@23, 5D
4
Mod@23, 5D
3
In[58]:=
FactorInteger@2 214 576D
Out[58]=
In[64]:=
Out[64]=
In[65]:=
Out[65]=
In[66]:=
Out[66]=
In[67]:=
Out[67]=
In[71]:=
Out[71]=
882, 4<, 83, 2<, 87, 1<, 813, 3<<
GCD@393 040, 5270D
170
PowerMod@7, - 1, 26D
15
Prime@97D
509
PrimeQ@97D
True
Random@Integer, 81, 100<D
72
Practice Exercises using Mathematica
1. Determine the quotient and remainder when 9876543210123456789 is
divided by 2111111211111111 and explain how you used the CAS to
2
do this.
2. Determine whether 103273184 has an inverse modulo 1259294809743
and explain both your reasoning and at what point the CAS is useful.
3. Find the prime factorization of 37575241065115333933 and indicate
how you used the CAS to do this.
4. Find 159103554−1 mod 477310661.
5. Compute 5432034598789658431 mod 6654334561.
6. Mathematica can be used as a programming environment. In particular, you can define and use your own functions, as illustrated here
In[14]:=
affinecipher@x_, a_, b_D := Block@8X = Mod@ToCharacterCode@xD - 65, 26D, Y<,
Y = Mod@ b * X + a, 26D + 65;
FromCharacterCode@YD
D
In[12]:=
affinecipher@"GREAT", 3, 7D
Out[12]=
In[13]:=
Out[13]=
TSFDG
affinecipher@"TSFDG", 7, 15D
GREAT
A function called affinecipher is defined in input line 14. It has three
arguments, a string x, an integer constant a, and an integer multiplier
b. The function calculates (a + bX) mod 26, where X is the list of
numerical equivalents of the letters in x. This list is then shifted by
65 to compute the list Y of ASCII values for the cipher test, which is
then converted to a string with the function FromCharacterCode.
(a) Without actually writing the program in Mathematica, trace
through the code to see what the function will produce from the
input affinecipher["TRUTH",13,1].
(b) Explain why affinecipher["TRUTH",13,4] would not produce
uniquely decipherable ciphertext.
3
(c) In Mathematica, test this version of affincipher. Then use it
to decipher GCUPCX, which was enciphered using the affine cipher
y = (12 + 17x) mod 26.
4
Download