Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

PSIT & PSITCOE

Assignment# 1

Subject Code : NCS-651


##Question: WAP in c to perform bit stuffing?
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main(){
char data[500];
int a, b, c;
clrscr();
printf("Enter the data string: ");
gets(data);
int l = strlen(data);
printf("Data size before stuffing: %d\n\n", l);
int i = 0;
while(data[i] != NULL){
b = i;
i++;
for(a = 0; a < 5; a++){
if(data[b] != '1')
break;
b++;
}
if(a == 5){
for(c = l; c >= b; c--)
data[c + 1] = data[c];
data[b] = '0';
}
else{

Roll no.: 13164100


Section : PSIT-CS-III-A

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

PSIT & PSITCOE

Assignment# 2

Subject Code : NCS-651


--- byte stuffing --#include<stdio.h>
#include<conio.h>
void main()
{
char frame[100],str[50][50];
char flag='z';
char esc='x';
inti,j,k=0,n;
frame[k++]='z';
clrscr();
printf("Enter no.of String ::\t");
scanf("%d",&n);
printf("Enter String \n");
for(i=0;i<=n;i++)
{
gets(str[i]);
}
printf("You entered ::\n");
for(i=0;i<=n;i++)
{
puts(str[i]);
}
printf("\n");
for(i=1;i<=n;i++)
{
for(j=0;j<strlen(str[i]);j++)
{

Roll no.: 13164100


Section : PSIT-CS-III-A

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

PSIT & PSITCOE

Assignment# 3

Subject Code : NCS-651


Implementation of crc :
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
int i,j,keylen,msglen;
char input[100], key[30],temp[30],quot[100],rem[30],key1[30];
clrscr();
printf("Enter Data: ");
gets(input);
printf("Enter Key: ");
gets(key);
keylen=strlen(key);
msglen=strlen(input);
strcpy(key1,key);
for(i=0;i<keylen-1;i++)
{
input[msglen+i]='0';
}
for(i=0;i<keylen;i++)
temp[i]=input[i];
for(i=0;i<msglen;i++)
{
quot[i]=temp[0];
if(quot[i]=='0')
for(j=0;j<keylen;j++)
key[j]='0';

Roll no.: 13164100


Section : PSIT-CS-III-A

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

PSIT & PSITCOE

Assignment# 4

Subject Code : NCS-651

Roll no.: 13164100


Section : PSIT-CS-III-A

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

PSIT & PSITCOE

Assignment# 5

Subject Code : NCS-651


implementation of spanning tree using prim s algorithm ---#include<stdio.h>
#include<conio.h>
int a,b,u,v,n,i,j,ne=1;
int visited[10]={0},min,mincost=0,cost[10][10];
void main()
{
clrscr();
printf("\n Enter the number of nodes:");
scanf("%d",&n);
printf("\n Enter the adjacency matrix:\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
scanf("%d",&cost[i][j]);
if(cost[i][j]==0)
cost[i][j]=999;
}
visited[1]=1;
printf("\n");
while(ne<n)
{
for(i=1,min=999;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][j]<min)
if(visited[i]!=0)
{
min=cost[i][j];

Roll no.: 13164100


Section : PSIT-CS-III-A ----

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

PSIT & PSITCOE

Assignment# 6

Subject Code : NCS-651

Roll no.: 13164100


Section : PSIT-CS-III-A

#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

PSIT & PSITCOE

Assignment# 7

Subject Code : NCS-651

Roll no.: 13164100


Section : PSIT-CS-III-A

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

You might also like