SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Downloaden Sie, um offline zu lesen
OOSP
PROJECT
Submitted To : Mr. Amol Vasudeva
Submitted By: Sandeep Kumar
101026
X-1(ECE)
JAVA Code: Cyclic Redundancy
Check for Error-Detection
Cyclic Redundancy Check Code for Error- Detection
The Cyclic Redundancy Check (CRC) is a technique for detecting errors in data
transmission, but not for correcting errors when they are detected.
Algorithm:
(A) For Computing CRC :
 The CRC Algorithm is based on polynomial arithmetic.
 Let the message that we have to send has k bits(denoted by M(x) in polynomial
form having degree (k-1) )The sender and the receiver are agreed upon a
generator polynomial having r bits (denoted by G(x) in polynomial form
having degree(r-1) ). The generator polynomial is also called “Divisor”.
 Now, append (r-1) zero bits to the LSB side of the message M(x) so it will now
contain (k+r-1) bits and corresponds to the polynomial x(r-1)
M(x).
 Divide the polynomial x(r-1)
M(x) by Divisor, using modulo-2 subtraction(bit by
bit XOR operation).Add the remainder R(x)(called frame check sequence) to
x(r-1)
M(x), using modulo-2 addition (bit by bit XOR operation). This is the
message that will be transmitted by the transmitter denoted by T(x).
(B) For Error Detection:
 Suppose that a transmission error occurs , so that the received message at the
receiver is T(x)+E(x), instead of T(x).Each 1 bit in E(x) corresponds to a bit that
has been inverted.
 The received message at the receiver end is divided by G(x), i. e. [T(x)+E(x)
/G(x)]. Since T(x) /G(x) is 0, so the result is simply E(x)/G(x).
 If E(x)/G(x)=0 than there is no error in the received message, otherwise there is
an error.
 The following type of errors can be detected using CRC:
 If G(x) has more than one bit and the coefficient of x0
is 1, then all single
bit errors are detected.
 If G(x) is not divisible by x (the coefficient of x0
is 1), and t is the least
positive integer(0<t<n-1) such that G(x) divides xt
+1, then all isolated
double errors are detected.
 If G(x) has a factor (x+1), then all odd numbered errors are detected.
Some standard Generator Polynomials are shown below:
Name Generator Polynomial
CRC-8 x8
+x2
+x+1
CRC-10 x10
+x9
+x5
+x4
+x2
+1
CRC-16 x16
+x12
+x5
+1
CRC-32 x32
+x26
+x23
+x22
+x16
+x12
+x11
+x10
+x8
+x7
+x5
+x4
+x2
+x+1
The following figure illustrates the computation of CRC
CODE:
import java.io.*;
class crc
{
public static void main(String a[]) throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int[] message;
int[] gen;
int[] app_message;
int[] rem;
int[] trans_message;
int message_bits,gen_bits, total_bits;
System.out.println("n Enter number of bits in message : ");
message_bits=Integer.parseInt(br.readLine());
message=new int[message_bits];
System.out.println("n Enter message bits : ");
for(int i=0; i<message_bits; i++)
message[i]=Integer.parseInt(br.readLine());
System.out.println("n Enter number of bits in gen : ");
gen_bits=Integer.parseInt(br.readLine());
gen=new int[gen_bits];
System.out.println("n Enter gen bits : ");
for(int i=0; i<gen_bits; i++)
{
gen[i]=Integer.parseInt(br.readLine());
}
total_bits=message_bits+gen_bits-1;
app_message=new int[total_bits];
rem=new int[total_bits];
trans_message=new int[total_bits];
for(int i=0;i<message.length;i++)
{
app_message[i]=message[i];
}
System.out.print("n Message bits are : ");
for(int i=0; i< message_bits; i++)
{
System.out.print(message[i]);
}
System.out.print("n Generators bits are : ");
for(int i=0; i< gen_bits; i++)
{
System.out.print(gen[i]);
}
System.out.print("n Appended message is : ");
for(int i=0; i< app_message.length; i++)
{
System.out.print(app_message[i]);
}
for(int j=0; j<app_message.length; j++)
{
rem[j] = app_message[j];
}
rem=computecrc(app_message, gen, rem);
for(int i=0;i<app_message.length;i++)
{
trans_message[i]=(app_message[i]^rem[i]);
}
System.out.println("n Transmitted message from the transmitter is : ");
for(int i=0;i<trans_message.length;i++)
{
System.out.print(trans_message[i]);
}
System.out.println("n Enter received message of "+total_bits+" bits at receiver end : ");
for(int i=0; i<trans_message.length; i++)
{
trans_message[i]=Integer.parseInt(br.readLine());
}
System.out.println("n Received message is :");
for(int i=0; i< trans_message.length; i++)
{
System.out.print(trans_message[i]);
}
for(int j=0; j<trans_message.length; j++)
{
rem[j] = trans_message[j];
}
rem=computecrc(trans_message, gen, rem);
for(int i=0; i< rem.length; i++)
{
if(rem[i]!=0)
{
System.out.println("n There is Error in the received message!!!");
break;
}
if(i==rem.length-1)
{
System.out.println("n There is No Error in the received message!!!");
}
}
static int[] computecrc(int app_message[],int gen[], int rem[])
{
int current=0;
while(true)
{
for(int i=0;i<gen.length;i++)
{
rem[current+i]=(rem[current+i]^gen[i]);
}
while(rem[current]==0 && current!=rem.length-1)
{
current++;
}
if((rem.length-current)<gen.length)
{
break;
}
}
return rem;
}
}
OUTPUT:
CRC JAVA CODE

Weitere ähnliche Inhalte

Was ist angesagt?

0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and boundAbhishek Singh
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in CompilerAkhil Kaushik
 
Minmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slidesMinmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slidesSamiaAziz4
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardAnimesh Chaturvedi
 
Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)k33a
 
Classical relations and fuzzy relations
Classical relations and fuzzy relationsClassical relations and fuzzy relations
Classical relations and fuzzy relationsBaran Kaynak
 
Tic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmTic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmUjjawal Poudel
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statisticsRajendran
 
Webinar : P, NP, NP-Hard , NP - Complete problems
Webinar : P, NP, NP-Hard , NP - Complete problems Webinar : P, NP, NP-Hard , NP - Complete problems
Webinar : P, NP, NP-Hard , NP - Complete problems Ziyauddin Shaik
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)swapnac12
 
Block coding, error detection (Parity checking, Cyclic redundancy checking (C...
Block coding, error detection (Parity checking, Cyclic redundancy checking (C...Block coding, error detection (Parity checking, Cyclic redundancy checking (C...
Block coding, error detection (Parity checking, Cyclic redundancy checking (C...Paulo_Vangui
 

Was ist angesagt? (20)

0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
 
Daa notes 3
Daa notes 3Daa notes 3
Daa notes 3
 
Defuzzification
DefuzzificationDefuzzification
Defuzzification
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Minmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slidesMinmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slides
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)
 
Classical relations and fuzzy relations
Classical relations and fuzzy relationsClassical relations and fuzzy relations
Classical relations and fuzzy relations
 
A* Algorithm
A* AlgorithmA* Algorithm
A* Algorithm
 
Tic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmTic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max Algorithm
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
 
Hamming codes
Hamming codesHamming codes
Hamming codes
 
Webinar : P, NP, NP-Hard , NP - Complete problems
Webinar : P, NP, NP-Hard , NP - Complete problems Webinar : P, NP, NP-Hard , NP - Complete problems
Webinar : P, NP, NP-Hard , NP - Complete problems
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 
Tsp branch and-bound
Tsp branch and-boundTsp branch and-bound
Tsp branch and-bound
 
Block coding, error detection (Parity checking, Cyclic redundancy checking (C...
Block coding, error detection (Parity checking, Cyclic redundancy checking (C...Block coding, error detection (Parity checking, Cyclic redundancy checking (C...
Block coding, error detection (Parity checking, Cyclic redundancy checking (C...
 
Theta notation
Theta notationTheta notation
Theta notation
 

Andere mochten auch

Andere mochten auch (6)

CRC Error coding technique
CRC Error coding techniqueCRC Error coding technique
CRC Error coding technique
 
05 directnets errors
05 directnets errors05 directnets errors
05 directnets errors
 
Synthesis
SynthesisSynthesis
Synthesis
 
verilog code
verilog codeverilog code
verilog code
 
CDMA
CDMACDMA
CDMA
 
Cdma ppt for ECE
Cdma ppt for ECECdma ppt for ECE
Cdma ppt for ECE
 

Ähnlich wie CRC JAVA CODE

13-DataLink_02.ppt
13-DataLink_02.ppt13-DataLink_02.ppt
13-DataLink_02.pptWinterSnow16
 
第四次课程 Chap8
第四次课程 Chap8第四次课程 Chap8
第四次课程 Chap8Emma2013
 
CRC implementation
CRC implementation CRC implementation
CRC implementation ajay singh
 
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPTGROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPTKrishbathija
 
Reed solomon Encoder and Decoder
Reed solomon Encoder and DecoderReed solomon Encoder and Decoder
Reed solomon Encoder and DecoderAmeer H Ali
 
Cyclic Redundancy Check
Cyclic Redundancy CheckCyclic Redundancy Check
Cyclic Redundancy CheckRajan Shah
 
Convolutional Error Control Coding
Convolutional Error Control CodingConvolutional Error Control Coding
Convolutional Error Control CodingMohammed Abuibaid
 
The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)theijes
 
Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...
Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...
Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...IRJET Journal
 
Oth1
Oth1Oth1
Oth1b137
 

Ähnlich wie CRC JAVA CODE (20)

13-DataLink_02.ppt
13-DataLink_02.ppt13-DataLink_02.ppt
13-DataLink_02.ppt
 
Data links
Data links Data links
Data links
 
第四次课程 Chap8
第四次课程 Chap8第四次课程 Chap8
第四次课程 Chap8
 
CRC implementation
CRC implementation CRC implementation
CRC implementation
 
IntrRSCode
IntrRSCodeIntrRSCode
IntrRSCode
 
IntrRSCode
IntrRSCodeIntrRSCode
IntrRSCode
 
IntrRSCode
IntrRSCodeIntrRSCode
IntrRSCode
 
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPTGROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
 
Reed solomon Encoder and Decoder
Reed solomon Encoder and DecoderReed solomon Encoder and Decoder
Reed solomon Encoder and Decoder
 
cyclic_code.pdf
cyclic_code.pdfcyclic_code.pdf
cyclic_code.pdf
 
Cyclic Redundancy Check
Cyclic Redundancy CheckCyclic Redundancy Check
Cyclic Redundancy Check
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
Convolutional Error Control Coding
Convolutional Error Control CodingConvolutional Error Control Coding
Convolutional Error Control Coding
 
The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)
 
3320 cyclic codes.ppt
3320 cyclic codes.ppt3320 cyclic codes.ppt
3320 cyclic codes.ppt
 
Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...
Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...
Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...
 
03raster 1
03raster 103raster 1
03raster 1
 
Oth1
Oth1Oth1
Oth1
 
BCH Codes
BCH CodesBCH Codes
BCH Codes
 
Error Control coding
Error Control codingError Control coding
Error Control coding
 

Kürzlich hochgeladen

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Kürzlich hochgeladen (20)

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

CRC JAVA CODE

  • 1. OOSP PROJECT Submitted To : Mr. Amol Vasudeva Submitted By: Sandeep Kumar 101026 X-1(ECE) JAVA Code: Cyclic Redundancy Check for Error-Detection
  • 2. Cyclic Redundancy Check Code for Error- Detection The Cyclic Redundancy Check (CRC) is a technique for detecting errors in data transmission, but not for correcting errors when they are detected. Algorithm: (A) For Computing CRC :  The CRC Algorithm is based on polynomial arithmetic.  Let the message that we have to send has k bits(denoted by M(x) in polynomial form having degree (k-1) )The sender and the receiver are agreed upon a generator polynomial having r bits (denoted by G(x) in polynomial form having degree(r-1) ). The generator polynomial is also called “Divisor”.  Now, append (r-1) zero bits to the LSB side of the message M(x) so it will now contain (k+r-1) bits and corresponds to the polynomial x(r-1) M(x).  Divide the polynomial x(r-1) M(x) by Divisor, using modulo-2 subtraction(bit by bit XOR operation).Add the remainder R(x)(called frame check sequence) to x(r-1) M(x), using modulo-2 addition (bit by bit XOR operation). This is the message that will be transmitted by the transmitter denoted by T(x). (B) For Error Detection:  Suppose that a transmission error occurs , so that the received message at the receiver is T(x)+E(x), instead of T(x).Each 1 bit in E(x) corresponds to a bit that has been inverted.  The received message at the receiver end is divided by G(x), i. e. [T(x)+E(x) /G(x)]. Since T(x) /G(x) is 0, so the result is simply E(x)/G(x).  If E(x)/G(x)=0 than there is no error in the received message, otherwise there is an error.  The following type of errors can be detected using CRC:  If G(x) has more than one bit and the coefficient of x0 is 1, then all single bit errors are detected.  If G(x) is not divisible by x (the coefficient of x0 is 1), and t is the least positive integer(0<t<n-1) such that G(x) divides xt +1, then all isolated double errors are detected.  If G(x) has a factor (x+1), then all odd numbered errors are detected.
  • 3. Some standard Generator Polynomials are shown below: Name Generator Polynomial CRC-8 x8 +x2 +x+1 CRC-10 x10 +x9 +x5 +x4 +x2 +1 CRC-16 x16 +x12 +x5 +1 CRC-32 x32 +x26 +x23 +x22 +x16 +x12 +x11 +x10 +x8 +x7 +x5 +x4 +x2 +x+1 The following figure illustrates the computation of CRC
  • 4. CODE: import java.io.*; class crc { public static void main(String a[]) throws IOException { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); int[] message; int[] gen; int[] app_message; int[] rem; int[] trans_message; int message_bits,gen_bits, total_bits; System.out.println("n Enter number of bits in message : "); message_bits=Integer.parseInt(br.readLine()); message=new int[message_bits]; System.out.println("n Enter message bits : "); for(int i=0; i<message_bits; i++) message[i]=Integer.parseInt(br.readLine()); System.out.println("n Enter number of bits in gen : "); gen_bits=Integer.parseInt(br.readLine()); gen=new int[gen_bits]; System.out.println("n Enter gen bits : "); for(int i=0; i<gen_bits; i++) { gen[i]=Integer.parseInt(br.readLine()); } total_bits=message_bits+gen_bits-1; app_message=new int[total_bits]; rem=new int[total_bits]; trans_message=new int[total_bits]; for(int i=0;i<message.length;i++) { app_message[i]=message[i]; } System.out.print("n Message bits are : "); for(int i=0; i< message_bits; i++) { System.out.print(message[i]); }
  • 5. System.out.print("n Generators bits are : "); for(int i=0; i< gen_bits; i++) { System.out.print(gen[i]); } System.out.print("n Appended message is : "); for(int i=0; i< app_message.length; i++) { System.out.print(app_message[i]); } for(int j=0; j<app_message.length; j++) { rem[j] = app_message[j]; } rem=computecrc(app_message, gen, rem); for(int i=0;i<app_message.length;i++) { trans_message[i]=(app_message[i]^rem[i]); } System.out.println("n Transmitted message from the transmitter is : "); for(int i=0;i<trans_message.length;i++) { System.out.print(trans_message[i]); } System.out.println("n Enter received message of "+total_bits+" bits at receiver end : "); for(int i=0; i<trans_message.length; i++) { trans_message[i]=Integer.parseInt(br.readLine()); } System.out.println("n Received message is :"); for(int i=0; i< trans_message.length; i++) { System.out.print(trans_message[i]); } for(int j=0; j<trans_message.length; j++) { rem[j] = trans_message[j]; } rem=computecrc(trans_message, gen, rem); for(int i=0; i< rem.length; i++) { if(rem[i]!=0)
  • 6. { System.out.println("n There is Error in the received message!!!"); break; } if(i==rem.length-1) { System.out.println("n There is No Error in the received message!!!"); } } static int[] computecrc(int app_message[],int gen[], int rem[]) { int current=0; while(true) { for(int i=0;i<gen.length;i++) { rem[current+i]=(rem[current+i]^gen[i]); } while(rem[current]==0 && current!=rem.length-1) { current++; } if((rem.length-current)<gen.length) { break; } } return rem; } } OUTPUT: