441 private final int ALLONES = 2147483647;
448 private int[] nocoeff;
453 private int maskZrm1;
462 final static int MBL = 140;
465 private void init(
int w,
int r,
int modQ,
int step,
int nbcoeff,
int coeff[],
int nocoeff[]) {
466 normFactor = 1.0 / (1L << 31);
467 EpsilonHalf = 0.5 * normFactor;
474 maskw = (1 << w) - 1;
475 maskrw = ((1 << (r * w)) - 1) << S;
476 maskZrm1 = (ALLONES >> (r * w)) ^ (ALLONES >> ((r - 1) * w));
478 this.nbcoeff = nbcoeff;
479 this.nocoeff =
new int[nbcoeff];
480 this.coeff =
new int[nbcoeff];
481 for (
int j = 0; j < nbcoeff; j++) {
482 this.nocoeff[j] = nocoeff[j];
483 this.coeff[j] = coeff[j];
487 void initParamLFSR() {
488 t = (31 - r * w) / w;
489 masktrw = (~0) << (31 - (t + r) * w) & mask31;
491 for (
int j = 0; j < r; j++) {
492 maskv[j] = maskw << (S + ((r - 1 - j) * w));
500 F2wStructure(
int w,
int r,
int modQ,
int step,
int nbcoeff,
int coeff[],
int nocoeff[]) {
501 init(w, r, modQ, step, nbcoeff, coeff, nocoeff);
528 BufferedReader input;
530 if ((
new File(filename)).exists()) {
531 input =
new BufferedReader(
new FileReader(filename));
536 DataInputStream dataInput;
537 dataInput =
new DataInputStream(
F2wStructure.class.getClassLoader()
538 .getResourceAsStream(
"umontreal/ssj/hups/dataF2w/Panneton/" + filename));
539 input =
new BufferedReader(
new InputStreamReader(dataInput));
541 initFromReader(filename, input, no);
544 }
catch (Exception e) {
545 System.out.println(
"IO Error: problems finding file " + filename);
550 private int multiplyz(
int a,
int k) {
555 for (i = 0; i < k; i++) {
579 int res = 0, verif = 1;
580 for (i = 0; i < w; i++) {
581 if ((b & verif) == verif)
582 res ^= multiplyz(a, w - 1 - i);
593 tempState = state << S;
595 for (
int i = 1; i <= t; i++) {
597 for (
int j = 0; j < nbcoeff; j++) {
598 v = (tempState & maskv[nocoeff[j]]) >> (S + (r - 1 - nocoeff[j]) * w);
601 output |= d << (S - i * w);
602 tempState = (output << (i * w)) & maskrw;
610 for (
int i = 0; i < step; i++) {
611 tempState = (output << (t * w)) & maskrw;
613 for (
int j = 0; j < nbcoeff; j++) {
614 v = (tempState & maskv[nocoeff[j]]) >> (S + (r - 1 - nocoeff[j]) * w);
617 output = ((output << w) & masktrw) | (d << (31 - (r + t) * w));
619 state = (output & maskrw) >> S;
625 for (
int i = 0; i < step; i++) {
626 Zrm1 = (state & maskZrm1) >> S;
627 state = (state >> w) & maskrw;
628 for (
int j = 0; j < nbcoeff; j++)
629 state ^=
multiply(coeff[j], Zrm1) << (S + (r - 1 - nocoeff[j]) * w);
638 public static void print(String filename) {
639 BufferedReader input;
641 if ((
new File(filename)).exists()) {
642 input =
new BufferedReader(
new FileReader(filename));
644 DataInputStream dataInput;
645 dataInput =
new DataInputStream(
646 F2wStructure.class.getClassLoader().getResourceAsStream(
"umontreal/ssj/hups/dataF2w/" + filename));
647 input =
new BufferedReader(
new InputStreamReader(dataInput));
651 for (
int i = 0; i < 4; i++)
653 while ((s = input.readLine()) !=
null)
654 System.out.println(s);
657 }
catch (Exception e) {
658 System.out.println(
"IO Error: problems reading file " + filename);
668 StringBuffer sb =
new StringBuffer(
"z^");
670 for (
int j = nbcoeff - 1; j >= 0; j--)
671 sb.append(
" + (" + coeff[j] +
") z^" + nocoeff[j]);
672 sb.append(
" modQ = " + modQ +
" w = " + w +
" step = " + step);
673 return sb.toString();
676 private void initFromReader(String filename, BufferedReader input,
int no) {
677 int w, r, modQ, step, nbcoeff;
678 int coeff[], nocoeff[];
679 StringTokenizer line;
683 for (
int j = 1; j < nl; j++)
686 line =
new StringTokenizer(input.readLine());
687 w = Integer.parseInt(line.nextToken());
688 r = Integer.parseInt(line.nextToken());
689 modQ = Integer.parseInt(line.nextToken());
690 step = Integer.parseInt(line.nextToken());
691 nbcoeff = Integer.parseInt(line.nextToken());
692 nocoeff =
new int[nbcoeff];
693 coeff =
new int[nbcoeff];
694 for (
int i = 0; i < nbcoeff; i++) {
695 coeff[i] = Integer.parseInt(line.nextToken());
696 nocoeff[i] = Integer.parseInt(line.nextToken());
698 init(w, r, modQ, step, nbcoeff, coeff, nocoeff);
701 }
catch (Exception e) {
702 System.out.println(
"Input Error: problems reading file " + filename);
F2wStructure(int w, int r, int modQ, int step, int nbcoeff, int coeff[], int nocoeff[])
Constructs a F2wStructure object that contains the parameters of a polynomial in ,...