-
Notifications
You must be signed in to change notification settings - Fork 4
/
galoisfield.cpp
executable file
·67 lines (50 loc) · 1.56 KB
/
galoisfield.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**********************************************************************
Project: C++ Library for General Galois Field Arithmetic
Language: C++ 2007
Author: Saied H. Khayat
Date: Feb 2013
URL: https://github.com/saiedhk
Copyright Notice: Free use of this library is permitted under the
guidelines and in accordance with the MIT License (MIT).
http://opensource.org/licenses/MIT
**********************************************************************/
#include <iostream>
using namespace std;
#include <cassert>
#include "galoisfield.h"
namespace shk_galoiscpp
{
//------------------------------------------------------
GaloisField::GaloisField(Fint mod, Int dim, Fint poly[])
{
assert (mod>1);
assert (dim>0);
modulus = mod;
dimension = dim;
reductpoly = new Fint[dimension+1];
for (Int i=0; i < dimension+1; i++)
{
reductpoly[i] = poly[i];
}
}
//------------------------------------------------------
GaloisField::~GaloisField()
{
delete [] reductpoly;
}
//------------------------------------------------------
ostream& operator<<(ostream& output, const GaloisField& gf)
{
output << "\nPrime Modulus: " << gf.modulus;
output << "\nDimension: " << gf.dimension;
output << "\nReduction Polynomial Coefficients: (";
for (Int i=0; i<=gf.dimension; i++)
{
if (i < gf.dimension)
output << gf.reductpoly[i] << " ";
else
output << gf.reductpoly[i] << ")\n";
}
return output;
}
} // namespace shk_galoiscpp