// This finds the final sums of iR[i] private int findSumiRi() { int[] sum = new int[29]; int length = 28; // Find iRi int[] iR = new int[29]; for (int i = 0; i < 29; i++) iR[i] = M.myMod((i * R[i]), 29); // System.out.print("iRi: "); // for(int i = 0; i < 29; i++) // System.out.print(iR[i] + " "); // System.out.println(); for (int i = 0; i < 29; i++) sum[i] = iR[i]; for (int j = 0; j < 28; j++) { for (int i = 0; i < length; i++) { sum[i] = sum[i + 1] - sum[i]; sum[i] = M.myMod(sum[i], 29); // System.out.print(sum[i] + " "); } length = length - 1; // System.out.println(); } return sum[0]; }
// Main method just calls various functions and prints messages public static void main(String[] args) throws IOException { M.getFileInput(); M.processAllBlocks(); M.writeFile(); M.checkForError(); System.out.println("\nRecieved Message: " + message); System.out.println("Decoded Message: " + decodedMessage); }
// This finds the final sums of EiRi[] and stores it in RiEiLeading[] private void findSums(int[] myArray) // This is for RiEi { int[] sum = myArray; int length = 28; /* * System.out.print("Ri: "); // Delete Later for(int i = 0; i < 29; i++) * System.out.print(R[i] + ", "); System.out.println(); * * System.out.print("Ei: "); // Delete Later for(int i = 0; i < 29; i++) * System.out.print(Ei[i] + ", "); System.out.println("\n"); * * System.out.print("RiEi: "); for(int i = 0; i < 29; i++) * System.out.print(myArray[i] + ", "); System.out.println(); */ RiEiLeading[0] = myArray[0]; for (int j = 0; j < 28; j++) { for (int i = 0; i < length; i++) { sum[i] = sum[i + 1] - sum[i]; sum[i] = M.myMod(sum[i], 29); // System.out.print(sum[i] + " "); } RiEiLeading[j + 1] = sum[0]; length--; } }
private void findRiandEiandEiRi() { // FIND EI AND RIEI for (int j = 0; j < 29; j++) { Ei[j] = (j + (alpha + 29)) % 29; RiEi[j] = (Ei[j] * R[j]) % 29; } // FIND LEADING COEFFECIENTs FOR ALL SUMS OF RIEI M.findSums(RiEi); }
// For each block, this finds E(t), Q(t), P(t) private void processAllBlocks() { for (int i = 0; i < message.length() / 29; i++) { System.out.print("\nFor block #" + i); M.convert(); M.getRiAndiRi(i); M.findAlpha(i); M.findRiandEiandEiRi(); M.alterCArray(); M.buildQ(); M.buildP(); M.printP(); start = start + 29; // RESET EVERYTHING Q = new int[28]; P = new int[27]; R = new int[29]; } }
// This finds the final sums of R[i] private int findSumRi() { int[] sum = new int[29]; int length = 28; for (int i = 0; i < 29; i++) sum[i] = R[i]; // System.out.print("Ri: "); // for(int i = 0; i < 29; i++) // System.out.print(R[i] + " "); // WAS System.out.print(R[i + start] + // " "); System.out.println(); for (int j = 0; j < 28; j++) { for (int i = 0; i < length; i++) { sum[i] = sum[i + 1] - sum[i]; sum[i] = M.myMod(sum[i], 29); // System.out.print(sum[i] + " "); } length = length - 1; // System.out.println(); } return sum[0]; }
// This multiplies each leading sum of RiEi with each of the corresponding // C_K value and stores it in alteredCArrays private void alterCArray() { for (int k = 0; k < 28; k++) alteredCArrays[k] = M.multiplyArray(RiEiLeading[k], cArrays[k]); }
// This calls the other methods to get the finalSums of Ri and iRi private void getRiAndiRi(int i) { finalSumRi[i] = M.findSumRi(); finalSumiRi[i] = M.findSumiRi(); }