CRC (Java)

Problem Definition: Write a program in Java to find CRC of a given number. import java.util.Scanner; class CRC{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); //Input Data Stream System.out.print(“Enter data stream: “); String datastream = sc.nextLine(); System.out.print(“Enter generator: “); String generator = sc.nextLine(); int data[] = new int[datastream.length() + generator.length() – 1]; int divisor[] = new int[generator.length()]; for(int i=0;i<datastream.length();i++) data[i] = Integer.parseInt(datastream.charAt(i)+””); for(int … Continue reading CRC (Java)

Internet Checksum (Java)

Problem Definition: Write a program in Java to calculate the Internet Checksum and verify it at the Sender’s & Receiver’s side. import java.util.Scanner; class Checksum{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println(“**********SENDER**********”); System.out.print(“Enter the word: “); String input = sc.nextLine(); //Calculation of hex string String hex[]; if(input.length()%2 == 0){ //Even length input hex = new String[input.length()/2]; for(int i=0;i<hex.length;i++) hex[i] = Integer.toHexString(input.charAt(2*i))+Integer.toHexString(input.charAt(2*i+1)); }else{//odd … Continue reading Internet Checksum (Java)