Professional Documents
Culture Documents
Assigments CN
Assigments CN
Assignment# 1
continue;
}
}
l = strlen(data);
printf("Data size after stuffing: %d\nand the string is: ", l);
puts(data);
getch();
}
Dept :- CS Checked By :- Shubhi Gupta Date :12-05-2016
Assignment# 2
if(str[i][j]!=flag&&str[i][j]!=esc)
{
frame[k++]=str[i][j];
}
else{
frame[k++]='x';
frame[k++]=str[i][j];
}
}
}
frame[k++]='z';
frame[k++]='\0';
printf("------------------------------\n");
printf("Byte stuffing at sender side:\n\n");
printf("------------------------------\n");
for(i=0;i<k;i++)
{
printf("%c",frame[i]);
}
printf("\n------------------------------");
printf("\nByte stuffing at receiver side\n\n");
printf("------------------------------\n");
for(i=0;i<k;i++)
{
if(frame[i]=='x'|| frame[i]=='z')
{
i++;
}
printf("%c",frame[i]);}}}
Dept :- CS Checked By :- Shubhi Gupta Date :12-05-2016
Assignment# 3
else
for(j=0;j<keylen;j++)
key[j]=key1[j];
for(j=keylen-1;j>0;j--)
{
if(temp[j]==key[j])
rem[j-1]='0';
else
rem[j-1]='1';
}
rem[keylen-1]=input[i+keylen];
strcpy(temp,rem);
}
strcpy(rem,temp);
printf("\nQuotient is ");
for(i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for(i=0;i<keylen-1;i++)
printf("%c",rem[i]);
printf("\nFinal data is: ");
for(i=0;i<msglen;i++)
printf("%c",input[i]);
for(i=0;i<keylen-1;i++)
printf("%c",rem[i]);
}
----------------------------------------------------------------------------------------------------------------Dept :- CS Checked By :- Shubhi Gupta Date :12-05-2016
Assignment# 4
HAMMING CODE
#include<stdio.h>
#include<conio.h>
void main() {
int data[7],rec[7],i,c1,c2,c3,c;
printf("this works for message of 4bits in size \nenter message bit one by one: ");
scanf("%d%d%d%d",&data[0],&data[1],&data[2],&data[4]);
data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4];
data[3]=data[0]^data[1]^data[2];
printf("\nthe encoded bits are given below: \n");
for (i=0;i<7;i++) {
printf("%d ",data[i]);
}
printf("\nenter the received data bits one by one: ");
for (i=0;i<7;i++) {
scanf("%d",&rec[i]);
}
c1=rec[6]^rec[4]^rec[2]^rec[0];
c2=rec[5]^rec[4]^rec[1]^rec[0];
c3=rec[3]^rec[2]^rec[1]^rec[0];
c=c3*4+c2*2+c1 ;
if(c==0) {
printf("\ncongratulations there is no error: ");
} else {
printf("\nerron on the postion: %d\nthe correct message is \n",c);
if(rec[7-c]==0)
rec[7-c]=1; else
rec[7-c]=0;
for (i=0;i<7;i++) {
printf("%d ",rec[i]);
}
}
getch();
}
----------------------------------------------------------------------------------------------------------------Dept :- CS Checked By :- Shubhi Gupta Date :12-05-2016
Assignment# 5
a=u=i;
b=v=j;
}
if(visited[u]==0 || visited[v]==0)
{
printf("\n Edge %d:(%d %d) cost:%d",ne++,a,b,min);
mincost+=min;
visited[b]=1;
}
cost[a][b]=cost[b][a]=999;
}
printf("\n Minimun cost=%d",mincost);
getch();
}
----------------------------------------------------------------------------------------------------------------Dept :- CS Checked By :- Shubhi Gupta Date :12-05-2016
Assignment# 6
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main() {
int i, j,count=0,nl;
char str[100];
clrscr();
printf("enter the bit string: ");
gets(str);
for (i=0;i<strlen(str);i++) {
count=0;
//the following code search the six ones in given string
for (j=i;j<=(i+5);j++) {
if(str[j]=='1') {
count++;
}
}
//if there is six ones then folling code execute to bit stuffing after five ones
if(count==6) {
nl=strlen(str)+2;
for (;nl>=(i+5);nl--) {
str[nl]=str[nl-1];}
str[i+5]='0';
i=i+7;
}}
puts(str);
getch();}
Dept :- CS Checked By :- Shubhi Gupta Date :12-05-2016
Assignment# 7
MyServer.java
import java.io.*;
import java.net.*;
public class MyServer
{
public static void main(String[] args)
{
try
{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();//establishes connection
DataInputStream dis=new DataInputStream(s.getInputStream());
String str=(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
MyClient.java
import java.io.*;
import java.net.*;
public class MyClient {
public static void main(String[] args)
{
try
{
Socket s=new Socket("localhost",6666);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
----------------------------------------------------------------------------------------------------------------Dept :- CS Checked By :- Shubhi Gupta Date :12-05-2016