client
import java.io.*;
import java.net.*;
import java.util.*;
class crccli
{
public static void main(String args[])
{
try
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",139);
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
int s[]=new int[11];
int i,j=0;
int temp[]=new int[4];
int divisor[]=new int[4];
divisor[3]=1;
divisor[2]=1;
divisor[1]=0;
divisor[0]=1;
String dividend[]=new String[11];
System.out.println("Enter the data: ");
for(i=10;i>=3;i--)
{
dividend[i]=buf.readLine();
if(dividend[i].equals("0"))
{s[i]=0;}
else
{s[i]=1;}
}
for(j=0;j<3;j++)
s[j]=0;
System.out.print("The divisor is ");
for(i=3;i>=0;i--)
System.out.print(divisor[i]);
System.out.println("\n");
temp[3]=s[10];
temp[2]=s[9];
temp[1]=s[8];
for(i=10;(i-3)>=0;i--)
{
temp[0]=s[i-3];
if(temp[3]==0)
{
for(j=3;j>=0;j--)
temp[j]=temp[j]^0;
}
else
{
for(j=3;j>=0;j--)
temp[j]=temp[j]^divisor[j];
}
for(j=3;j>0;j--)
temp[j]=temp[j-1];
}
System.out.println("The remainder is "+temp[3]+temp[2]+temp[1]);
s[2]=temp[3];
s[1]=temp[2];
s[0]=temp[1];
for(i=0;i<3;i++)
{
if(s[i]==1)
dividend[i]="1";
else
dividend[i]="0";
}
for(i=10;i>=0;i--)
{
System.out.println(dividend[i]);
dout.writeBytes(dividend[i]+'\n');
}
String s1=din.readLine();
System.out.println(s1);
clsct.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
server
import java.io.*;
import java.net.*;
import java.util.*;
class crcser
{
public static void main(String args[])
{
try
{
ServerSocket obj=new ServerSocket(139);
Socket obj1=obj.accept();
while(true)
{
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
int i,j=0;
int s[]=new int[11];
int temp[]=new int[4];
int divisor[]=new int[4];
divisor[3]=1;
divisor[2]=1;
divisor[1]=0;
divisor[0]=1;
String dividend[]=new String[11];
String s1=new String();
for(i=10;i>=0;i--)
{
dividend[i]=din.readLine();
if(dividend[i].equals("1"))
{s[i]=1;}
else
{s[i]=0;}
}
System.out.print("The dividend is\n");
for(i=10;i>=0;i--)
{System.out.println(s[i]);}
System.out.print("The divisor is ");
for(i=3;i>=0;i--)
System.out.print(divisor[i]);
System.out.println("\n");
temp[3]=s[10];
temp[2]=s[9];
temp[1]=s[8];
for(i=10;(i-3)>=0;i--)
{
temp[0]=s[i-3];
if(temp[3]==0)
{
for(j=3;j>=0;j--)
temp[j]=temp[j]^0;
}
else
{
for(j=3;j>=0;j--)
temp[j]=temp[j]^divisor[j];
}
for(j=3;j>0;j--)
temp[j]=temp[j-1];
}
System.out.println("The remainder is "+temp[3]+temp[2]+temp[1]);
if(temp[3]==0&&temp[2]==0&&temp[1]==0)
{
System.out.println("No errror in packet");
s1="Packet received at server without error";
}
else
{
System.out.println("Errror in packet");
s1="Packet received at server with error";
}
dout.writeBytes(s1+'\n');
obj.close();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
output
client
Enter the data:
1
0
1
0
1
0
1
0
The divisor is 1101
The remainder is 110
server
The dividend is
1
0
1
0
1
0
1
0
1
1
0
The divisor is 1101
The remainder is 000
No errror in packet
client
Packet received at server without error
import java.io.*;
import java.net.*;
import java.util.*;
class crccli
{
public static void main(String args[])
{
try
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",139);
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
int s[]=new int[11];
int i,j=0;
int temp[]=new int[4];
int divisor[]=new int[4];
divisor[3]=1;
divisor[2]=1;
divisor[1]=0;
divisor[0]=1;
String dividend[]=new String[11];
System.out.println("Enter the data: ");
for(i=10;i>=3;i--)
{
dividend[i]=buf.readLine();
if(dividend[i].equals("0"))
{s[i]=0;}
else
{s[i]=1;}
}
for(j=0;j<3;j++)
s[j]=0;
System.out.print("The divisor is ");
for(i=3;i>=0;i--)
System.out.print(divisor[i]);
System.out.println("\n");
temp[3]=s[10];
temp[2]=s[9];
temp[1]=s[8];
for(i=10;(i-3)>=0;i--)
{
temp[0]=s[i-3];
if(temp[3]==0)
{
for(j=3;j>=0;j--)
temp[j]=temp[j]^0;
}
else
{
for(j=3;j>=0;j--)
temp[j]=temp[j]^divisor[j];
}
for(j=3;j>0;j--)
temp[j]=temp[j-1];
}
System.out.println("The remainder is "+temp[3]+temp[2]+temp[1]);
s[2]=temp[3];
s[1]=temp[2];
s[0]=temp[1];
for(i=0;i<3;i++)
{
if(s[i]==1)
dividend[i]="1";
else
dividend[i]="0";
}
for(i=10;i>=0;i--)
{
System.out.println(dividend[i]);
dout.writeBytes(dividend[i]+'\n');
}
String s1=din.readLine();
System.out.println(s1);
clsct.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
server
import java.io.*;
import java.net.*;
import java.util.*;
class crcser
{
public static void main(String args[])
{
try
{
ServerSocket obj=new ServerSocket(139);
Socket obj1=obj.accept();
while(true)
{
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
int i,j=0;
int s[]=new int[11];
int temp[]=new int[4];
int divisor[]=new int[4];
divisor[3]=1;
divisor[2]=1;
divisor[1]=0;
divisor[0]=1;
String dividend[]=new String[11];
String s1=new String();
for(i=10;i>=0;i--)
{
dividend[i]=din.readLine();
if(dividend[i].equals("1"))
{s[i]=1;}
else
{s[i]=0;}
}
System.out.print("The dividend is\n");
for(i=10;i>=0;i--)
{System.out.println(s[i]);}
System.out.print("The divisor is ");
for(i=3;i>=0;i--)
System.out.print(divisor[i]);
System.out.println("\n");
temp[3]=s[10];
temp[2]=s[9];
temp[1]=s[8];
for(i=10;(i-3)>=0;i--)
{
temp[0]=s[i-3];
if(temp[3]==0)
{
for(j=3;j>=0;j--)
temp[j]=temp[j]^0;
}
else
{
for(j=3;j>=0;j--)
temp[j]=temp[j]^divisor[j];
}
for(j=3;j>0;j--)
temp[j]=temp[j-1];
}
System.out.println("The remainder is "+temp[3]+temp[2]+temp[1]);
if(temp[3]==0&&temp[2]==0&&temp[1]==0)
{
System.out.println("No errror in packet");
s1="Packet received at server without error";
}
else
{
System.out.println("Errror in packet");
s1="Packet received at server with error";
}
dout.writeBytes(s1+'\n');
obj.close();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
output
client
Enter the data:
1
0
1
0
1
0
1
0
The divisor is 1101
The remainder is 110
server
The dividend is
1
0
1
0
1
0
1
0
1
1
0
The divisor is 1101
The remainder is 000
No errror in packet
client
Packet received at server without error
nice blog....
ReplyDelete