CRC

import java.io.BufferedReader;import java.

io.IOException;import java.io.

InputStreamReader;public class crc { public static void main(String args[]) throws IOException { InputStreamReader crc = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(crc); int[] data_maessage, crc_gen, message, random, transmitter; int data_bits, gen_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_maessage = new int[data_bits]; /* * ———————- here we enter the massage in bits * ———————– */ System.out.println(” Enter the message bits : “); for (int i = 0; i < data_bits; i++) data_maessage[i] = Integer.parseInt(br.

readLine()); /* * ——————— here we enter how number of the generator Polynomial Division * means divided ———————- */ System.out.println(” Enter the number of bits in Generetor Polynomial Division : “); gen_bits = Integer.

parseInt(br.readLine()); crc_gen = new int[gen_bits]; /* * ————————-here we enter the Generator Polynomial Division bits * ———————— */ System.out.println(” Enter the Generator Polynomial Division bits : “); for (int i = 0; i < gen_bits; i++) { crc_gen[i] = Integer.parseInt(br.

readLine()); } total_bits = data_bits + gen_bits – 1; message = new int[total_bits]; random = new int[total_bits]; transmitter = new int[total_bits]; /*—————— CRC GENERATION———————–*/ for (int i = 0; i < data_maessage.length; i++) { message[i] = data_maessage[i]; } System.out.print(" The Massage bits are  : "); for (int i = 0; i < data_bits; i++) { // here its print the massage System.out.

println(data_maessage[i]); } System.out.print(” The Geberators bits are : “); for (int i = 0; i < gen_bits; i++) { // here its print the generator polynomial System.

out.println(crc_gen[i]); } /* * ——————— append dividend and remainder ————————- */ System.out.print(” The Appended message is : “); for (int i = 0; i < message.length; i++) { System.out.

print(message[i]); } for (int j = 0; j < message.length; j++) { random[j] = message[j]; } random = CRC(message, crc_gen, random); for (int i = 0; i < message.length; i++) { transmitter[i] = (message[i] ^ random[i]); } System.out.println(" The Message is Transmitted from the transmitter : "); for (int i = 0; i < transmitter.length; i++) { System.out.

print(transmitter[i]); } System.out.println(” Enter message of ” + total_bits + ” bits at receiver end : “); for (int i = 0; i < transmitter.length; i++) { transmitter[i] = Integer.parseInt(br.

readLine()); } System.out.println(” The Received message is : “); for (int i = 0; i < transmitter.length; i++) { System.out.print(transmitter[i]); } for (int j = 0; j < transmitter.

length; j++) { random[j] = transmitter[j]; } /* ———————– ERROR DETECTION ———————— */ random = CRC(transmitter, crc_gen, random); for (int i = 0; i < random.length; i++) { if (random[i] != 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 🙂 …

..  “); } } System.out.println(“Thank you 🙂 and My References are in this projecr which i used for study in References in below the Package name….”); } public static int[] CRC(int message[], int crc_generator[], int random[]) { int crc = 0; while (true) { for (int i = 0; i < crc_generator.length; i++) { random[crc + i] = (random[crc + i] ^ crc_generator[i]); } while (random[crc] == 0 && crc != random.length - 1) { crc++; } if ((random.length - crc) < crc_generator.length) { break; } } return random; }}

x

Hi!
I'm Tamara!

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

Check it out