Reference no: EM13366965
Write a program called "GF2.java" to implement the finite field GF(pn) where p is a prime number and n is a positive integer. You also need to write four methods to realize "+", "-", "´", and "/".
Specifically, your program will read parameters and polynomials from a file named "input.txt" (under the same directory). Then your program needs to create a file named "output.txt" (under the same directory) and prints the results to "output.txt". (Please check the attached sample "input.txt" and "output.txt".)
In "input.txt":
1. First line is the prime number p.
2. Second line is the degree n of the irreducible polynomial m(x) over Zp.
3. Third line is the coefficients of m(x), from leading coefficient to the constant, separated by one blank space.
4. Fourth Line is the degree of f(x) over Zp.
5. Fifth line is the coefficients of f(x), from leading coefficient to the constant, separated by one blank space.
6. Sixth line is the degree of g(x) over Zp.
7. Seventh line is the coefficients of g(x), from leading coefficient to the constant, separated by one blank space.
In "output.txt":
1. First line is the coefficients of f(x)+g(x) (mod m(x)), from leading coefficient to the constant, separated by one blank space.
2. Second line is the coefficients of f(x)-g(x) (mod m(x)), from leading coefficient to the constant, separated by one blank space.
3. Third line is the coefficients of f(x)*g(x) (mod m(x)), from leading coefficient to the constant, separated by one blank space.
4. Fourth line is the coefficients of f(x)/g(x) (mod m(x)), from leading coefficient to the constant, separated by one blank space (don't forget to handle the case of g(x) = 0).
Important: leading coefficient should not be 0 unless the polynomial is 0.
Example 1: if p = 3, m(x) = x2 + 1, f(x) = 2x, g(x) = x + 1, then f(x) + g(x) = 1 instead of 0x + 1. Thus in the first line of "output.txt" it should print 1 instead of 0 1.
Example 2: if p = 3, m(x) = x2 + 1, f(x) = 2x + 2, g(x) = x + 1, then f(x) + g(x) = 0 instead of 0x + 0. Thus in the first line of "output.txt" it should print 0 instead of 0 0.
You need to create a java file "GF2.java" to blackboard. The program will be tested using command line.
"javac GF2.java"
to compile it and type
"java GF2"
to run it.
The files "GF2.java" and "input.txt" will be placed in the same directory. Your program needs to output the file "output.txt" to the same directory.