diff --git a/Others/CRCAlgorithm.java b/Others/CRCAlgorithm.java index f932a9b7..d53e3a02 100644 --- a/Others/CRCAlgorithm.java +++ b/Others/CRCAlgorithm.java @@ -1,53 +1,53 @@ -package crcalgorithm; +package Others; import java.util.ArrayList; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; /** - * * @author dimgrichr */ public class CRCAlgorithm { private int correctMess; - + private int wrongMess; - + private int wrongMessCaught; - + private int wrongMessNotCaught; - + private int messSize; - + private double ber; - + private boolean messageChanged; private ArrayList message; - + private ArrayList dividedMessage; - + private ArrayList p; - + private Random randomGenerator; - - + + /** * The algorithm's main constructor. * The most significant variables, used in the algorithm, * are set in their initial values. - * @param str The binary number P, in a string form, which is used by the CRC algorithm + * + * @param str The binary number P, in a string form, which is used by the CRC algorithm * @param size The size of every transmitted message - * @param ber The Bit Error Rate + * @param ber The Bit Error Rate */ - public CRCAlgorithm(String str, int size, double ber){ - messageChanged=false; + public CRCAlgorithm(String str, int size, double ber) { + messageChanged = false; message = new ArrayList<>(); messSize = size; dividedMessage = new ArrayList<>(); p = new ArrayList<>(); - for(int i=0;i(); dividedMessage = new ArrayList<>(); } - + /** * Random messages, consisted of 0's and 1's, * are generated, so that they can later be transmitted */ - public void generateRandomMess(){ - for(int i=0;i is created. * If check == true, the dividedMessaage is examined, in order to see if it contains any 1's. * If it does, the message is considered to be wrong by the receiver,so the variable wrongMessCaught changes. * If it does not, it is accepted, so one of the variables correctMess, wrongMessNotCaught, changes. - * If check == false, the diviided Message is added at the end of the ArrayList message. + * If check == false, the diviided Message is added at the end of the ArrayList message. + * * @param check the variable used to determine, if the message is going to be checked from the receiver - * if true, it is checked - * otherwise, it is not + * if true, it is checked + * otherwise, it is not */ - public void divideMessageWithP(boolean check){ + public void divideMessageWithP(boolean check) { ArrayList x = new ArrayList<>(); ArrayList k = (ArrayList) message.clone(); - if(!check){ - for(int i=0;i) x.clone(); - if(!check){ - for(int z:dividedMessage){ + if (!check) { + for (int z : dividedMessage) { message.add(z); } - } - else{ - if(dividedMessage.contains(1) && messageChanged){ + } else { + if (dividedMessage.contains(1) && messageChanged) { wrongMessCaught++; - } - else if(!dividedMessage.contains(1) && messageChanged){ + } else if (!dividedMessage.contains(1) && messageChanged) { wrongMessNotCaught++; - } - else if(!messageChanged){ + } else if (!messageChanged) { correctMess++; } } } - + /** * Once the message is transmitted, some of it's elements, * is possible to change from 1 to 0, or from 0 to 1, @@ -180,25 +181,23 @@ public class CRCAlgorithm { * Based on these changes. the boolean variable messageChanged, gets the value: * true, or false. */ - public void changeMess(){ - for(int y : message){ + public void changeMess() { + for (int y : message) { double x = randomGenerator.nextDouble(); - while(x<0.0000 || x>1.00000){ + while (x < 0.0000 || x > 1.00000) { x = randomGenerator.nextDouble(); } - if(x