import InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr);

import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class crc { public static void main(String args) throws IOException { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); int data, crc_generator, message, random, transmitter; int data_bits, generator_bits, total_bits; /* * ——————— Here we enter the Number of bit for massage length * ——————– */ System.out.println(”
Enter the Number of bits in message: “); data_bits = Integer.parseInt(br.readLine()); data = new intdata_bits; /* * ———————- here we enter the massage in bits * ———————– */ System.out.println(”
Enter the message bits : “); for (int i = 0; i < data_bits; i++) datai = Integer.parseInt(br.readLine()); /* * --------------------- here we enter how number of the generator polynomial * means divided ---------------------- */ System.out.println(" Enter the number of bits in Generetor Polynomial: "); generator_bits = Integer.parseInt(br.readLine()); crc_generator = new intgenerator_bits; /* * -------------------------here we enter the Generator polynomial bits * ------------------------ */ System.out.println(" Enter the Generator bits : "); for (int i = 0; i < generator_bits; i++) { crc_generatori = Integer.parseInt(br.readLine()); } /* * System.out.print("Data bits are : "); for(int i=0; i< data_bits; i++) * System.out.print(datai); System.out.println(); *  * System.out.print("divisor bits are : "); for(int i=0; i< divisor_bits; i++) * System.out.print(divisori); System.out.println(); */ total_bits = data_bits + generator_bits - 1; message = new inttotal_bits; random = new inttotal_bits; transmitter = new inttotal_bits; /*------------------ CRC GENERATION-----------------------*/ for (int i = 0; i < data.length; i++) { messagei = datai; } System.out.print(" The Massage bits are  : "); for (int i = 0; i < data_bits; i++) { // here its print the massage System.out.println(datai); } System.out.print(" The Geberators bits are : "); for (int i = 0; i < generator_bits; i++) { // here its print the generator polynomial System.out.println(crc_generatori); } /* * --------------------- append dividend and remainder ------------------------- */ System.out.print(" The Appended message is : "); for (int i = 0; i < message.length; i++) { System.out.print(messagei); } for (int j = 0; j < message.length; j++) { randomj = messagej; } random = CRC(message, crc_generator, random); for (int i = 0; i < message.length; i++) { transmitteri = (messagei ^ randomi); } System.out.println(" The Message is Transmitted from the transmitter : "); for (int i = 0; i < transmitter.length; i++) { System.out.print(transmitteri); } System.out.println(" Enter message of " + total_bits + " bits at receiver end : "); for (int i = 0; i < transmitter.length; i++) { transmitteri = Integer.parseInt(br.readLine()); } System.out.println(" The Received message is :"); for (int i = 0; i < transmitter.length; i++) { System.out.print(transmitteri); } for (int j = 0; j < transmitter.length; j++) { randomj = transmitterj; } /* ----------------------- ERROR DETECTION ------------------------ */ random = CRC(transmitter, crc_generator, random); for (int i = 0; i < random.length; i++) { if (randomi != 0) { System.out.println(" There is an error in received data..... "); break; } if (i == random.length - 1) { System.out.println(" Data was received without any error..... "); } } } public static int CRC(int message, int crc_generator, int random) { int cur = 0; while (true) { for (int i = 0; i < crc_generator.length; i++) { randomcur + i = (randomcur + i ^ crc_generatori); } while (randomcur == 0 && cur != random.length - 1) { cur++; } if ((random.length - cur) < crc_generator.length) { break; } } return random; }}

Go Top
x

Hi!
I'm Rita!

Would you like to get a custom essay? How about receiving a customized one?

Check it out