successsri:
CYCLIC REDUNDANCY CHECK
AIM:
To write a java program to implement cyclic redundancy check.
ALGORITHM:
1. Start the program.
2. Import necessary packages.
3. Get an user input in the form of bit data ie string.
4. Get an generator data from the user.
5. Read the length of the string and convert the data into another format by deducing 48from it.
6. Now Add the generator data to the original data and send the string as transmitter string.
7. In the receiving end, enter the generator code.
8. Using the generator code, to the length of the received string, add 48 to the number format of the string by character.
9. If the generator string is wrong, display “message received with error”.
10. If the generator string is correct, perform step 8 and display “message received withno error”.
11. End the program
import java.io.*;
import java.lang.*;
public class crc{
public static void main(String args[]) throws IOException
{
int f[]=new int[25];
int gen[]=new int[10];
int rem[]=new int[10];
int flen,glen,rlen,i,j;
int p,sum,iframe,igen,irem;
String data;
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the frame:");
data=in.readLine();
flen=data.length()-1;
for(i=0;i
f[i]=(int)(data.charAt(i))-48;
System.out.println("Enter the generator:");
data=in.readLine();
glen=data.length()-1;
for(i=1;i<=glen;i++)
f[flen+i]=0;
flen=flen+glen;
for(i=0;i
gen[i]=((int)(data.charAt(i))-48);
p=0;sum=0;
for(i=flen;i>=0;i--)
{
sum=sum+(f[i]*(int)Math.pow(2,p));
p=p+1;
}
iframe=sum;
p=0;sum=0;
for(i=glen;i>=0;i--)
{
sum=sum+(gen[i]*(int)Math.pow(2,p));
p=p+1;
}
igen=sum;irem=iframe%igen;
irem=igen-irem;
i=0;
while(iframe>0)
{
f[i]=iframe%2;
iframe=iframe/2;i++;
}
if(iframe == 1)
f[i]=iframe;
System.out.print("Transmitted string:");
for(i=flen;i>=0;i--)
System.out.print(f[i]);
System.out.print("\n\nEnter the received string:");
data=in.readLine();
flen=data.length()-1;
for(i=0;i
f[i]=((int)(data.charAt(i)))-48;
p=0;sum=0;
for(i=flen;i>=0;i--)
{
p=p+1;
}
iframe=sum;
irem=iframe%igen;
if(irem==0)System.out.println("Message received with no error");
elseSystem.out.println("Message received with error");
}
}
OUTPUT:
C:\Program Files\Java\jdk1.6.0\bin>javac crc.java
C:\Program Files\Java\jdk1.6.0\bin>java crc
Enter the frame:10101011
Enter the generator:1011
Transmitted string:10101011000
Enter the received string:1011
Message received with no error
Comments
Post a Comment