// Lit une ligne du fichier en ignorant les lignes blanches // et les commentaires. private String readOneLine(BufferedReader input) { String line; try { while (true) { line = input.readLine(); if (line == null) return null; line = line.trim(); // On saute les lignes blanches. if (line.length() == 0) { line = input.readLine(); continue; } // On saute les lignes de commentaires if (line.charAt(0) == '#') { line = input.readLine(); continue; } // On elimine les commentaires a la fin de la ligne int index = line.indexOf('#'); if (index >= 0) { line = line.substring(0, index).trim(); } return line; } } catch (IOException e) { System.err.println(e); System.exit(1); } return null; }
// Initialise les variables, et appelle fillCyclesLFSR() private void init() { k1 = nocoeff1[0]; posa1 = new int[nbcoeff1]; shifta1 = new int[nbcoeff1]; for (int i = 0; i < nbcoeff1; ++i) { posa1[i] = k1 - nocoeff1[i + 1] - 1; shifta1[i] = 1 << posa1[i]; } if (J == 2) { k2 = nocoeff2[0]; posa2 = new int[nbcoeff2]; shifta2 = new int[nbcoeff2]; for (int i = 0; i < nbcoeff2; ++i) { posa2[i] = k2 - nocoeff2[i + 1] - 1; shifta2[i] = 1 << posa2[i]; } } if (k1 + k2 > 31) { System.err.println("The degree of the combined polynomials must be < 31"); System.err.println("k1 = " + k1 + " k2 = " + k2); System.exit(1); } maskX1 = (1 << k1) - 1; maskX2 = (1 << k2) - 1; maskX1Shift = maskX1 << k2; maskX = (1 << (k1 + k2)) - 1; numBits = k1 + k2; normFactor = 1.0 / (1L << numBits); fillCyclesLFSR(); }
// Lit le fichier contenant les polynomes pour plusieurs generateurs. // no indique le choix du generateur dans le fichier. private void readFile(String fileName, int no) { BufferedReader input = null; try { if ((new File(fileName)).exists()) { input = new BufferedReader(new FileReader(fileName)); } else { DataInputStream dataInput; dataInput = new DataInputStream( F2wStructure.class .getClassLoader() .getResourceAsStream("umontreal/ssj/hups/dataLFSR/" + fileName)); input = new BufferedReader(new InputStreamReader(dataInput)); } } catch (FileNotFoundException e) { System.err.println("File " + fileName + " not found" + PrintfFormat.NEWLINE); System.exit(1); } // La numerotation des generateurs debute a 1 if (no < 1) no = 1; int[] numbers; // La premiere ligne valide est le nombre de polynomes String line = readOneLine(input); numbers = lineToNumbers(line); J = numbers[0]; if (J != 1 && J != 2) { System.err.println( "Error: J = " + J + PrintfFormat.NEWLINE + "CycleBasedLFSR works only for the cases of one or two polynomials"); System.exit(1); } // Nombre ne lignes qu'il faut sauter avant de lire les polynomes. int nbLines = (J + 1) * (no - 1); // On saute nbLines valides for (int i = 0; i < nbLines; i++) { line = readOneLine(input); if (line == null) { // Il n'y a aucune ligne qui correspond a no. System.err.println( "Error CycleBasedLFSR:" + PrintfFormat.NEWLINE + " no data in file " + fileName + " for " + no + "-th LFSR"); System.exit(1); } } // Lecture des valeurs des J steps. line = readOneLine(input); if (line == null) { // Il n'y a aucune ligne qui correspond a no. System.err.println( "Error CycleBasedLFSR:" + PrintfFormat.NEWLINE + " no data in file " + fileName + " for " + no + "-th LFSR"); System.exit(1); } numbers = lineToNumbers(line); // Lecture des J polynomes. if (J == 1) { step1 = numbers[0]; line = readOneLine(input); nocoeff1 = lineToNumbers(line); nbcoeff1 = nocoeff1.length - 1; } else if (J == 2) { step1 = numbers[0]; step2 = numbers[1]; line = readOneLine(input); nocoeff1 = lineToNumbers(line); nbcoeff1 = nocoeff1.length - 1; line = readOneLine(input); nocoeff2 = lineToNumbers(line); nbcoeff2 = nocoeff2.length - 1; } }