0% found this document useful (0 votes)
54 views9 pages

Program To Implement The Byte/Character Stiffing Message Encoding at The Sender End

The document describes C programs to implement byte/character stuffing and bit stuffing encoding and decoding algorithms. The encoding programs take a message as input, encode it by inserting bytes or bits according to the algorithm, and output the encoded message. The decoding programs take an encoded message, remove the inserted bytes or bits, and output the original message.

Uploaded by

Er Saurabh Nigam
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views9 pages

Program To Implement The Byte/Character Stiffing Message Encoding at The Sender End

The document describes C programs to implement byte/character stuffing and bit stuffing encoding and decoding algorithms. The encoding programs take a message as input, encode it by inserting bytes or bits according to the algorithm, and output the encoded message. The decoding programs take an encoded message, remove the inserted bytes or bits, and output the original message.

Uploaded by

Er Saurabh Nigam
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

Program to implement the Byte/Character stiffing message encoding at the sender end.

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

char a[20],final[20],msg[20];

int i,j=0,len,k=0;

printf("\nEnter the message.\n");

scanf("%s",&msg);

len=strlen(msg);

len=(len*2)+4;

for(i=0;i<=len;i++)

a[i]='0';

for(i=3;i<=len-2;i=i+2)

a[i]=msg[j];

j++;

printf("\nMessage before encoding\n");

for(i=0;i<=len;i++)

Pramod Kumar IT-1 6th sem B-2 2909113002


if(a[i]!='0')

printf("%c",a[i]);

a[1]='a';

a[len]='a';

for(i=3;i<=len-2;i++)

if((a[i]=='a')||(a[i]=='z'))

a[i-1]='z';

printf("\nMessage after encoding\n");

for(i=0;i<=len;i++)

if(a[i]!='0')

final[k]=arr[i];

k++;

for(i=0;i<=k-1;i++)

printf("%c",final[i]);

getch();

Pramod Kumar IT-1 6th sem B-2 2909113002


Output

Enter the message

deepak

Message before encoding

deepak

Message after encoding

adeepzaka

Enter the message

ankita

Message before encoding

ankita

Message after encoding

azankitzaa

Enter the message

zufail

Message before encoding

zufail

Message after encoding

azzufzaila

Pramod Kumar IT-1 6th sem B-2 2909113002


Program to implement the Byte/Character stiffing message decoding at receiver end.

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

char final[20],msg[20];

int i,j=0,len,k=0;

printf("\nEnter the message.\n");

scanf("%s",&msg);

len=strlen(msg);

msg[0]='0';

msg[len-1]='0';

for(i=0;i<len-1;i++)

if(msg[i]=='z')

msg[i]='0';

i++;

printf("\nMsg after decoding\n");

for(i=0;i<=len;i++)

Pramod Kumar IT-1 6th sem B-2 2909113002


if(msg[i]!='0')

final[k]=msg[i];

k++;

for(i=0;i<=k-1;i++)

printf("%c",final[i]);

getch();

Output

Enter the message

adeepzaka

Message after decoding

deepak

Enter the message

azankitzaa

Message after decoding

ankita

Enter the message

azzufzaila

Message after decoding

Zufail

Pramod Kumar IT-1 6th sem B-2 2909113002


Program to implement bit stuffing (message framing) encoding at sender end.

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

char msg[100],flag[100]={'0','1','1','1','1','1','1','0'};

int n,j;

int i,k=0,h=0;

clrscr();

printf("\nEnter the message:\n");

scanf("%s",&msg);

n=strlen(msg);

for(i=0;i<n+h;i++)

if(msg[i]=='1')

k++;

else

k=0;

if(k==5)

k=0;

h++;

for(j=n+h;j>=i;j--)

Pramod Kumar IT-1 6th sem B-2 2909113002


{

msg[j+1]=msg[j];

msg[i+1]='0';

strcat(msg,flag);

strcat(flag,msg);

printf("\nMessage After Encoding:");

printf("\n%s",flag);

getch();

Output

Enter the message:

01101011111100101010101

Message after encoding:

0111111001101011111010010101010101111110

Enter the message:

0111111111100101010101

Message after encoding:

0111111001111101111100010101010101111110

Pramod Kumar IT-1 6th sem B-2 2909113002


Program to implement the bit stuffing(message framing) decoding at receiver end.

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

char msg[50],final[18];

int n,i,k=0,j;

clrscr();

printf("\nEnter the message");

scanf("%s",&msg);

n=strlen(msg);

for(i=8;i<=n-9;i++)

final[i-8]=msg[i];

n=strlen(final);

printf("\nMessage after decoding\n");

for(i=0;i<n-1;i++)

if(final[i]=='1')

k++;

else

k=0;

Pramod Kumar IT-1 6th sem B-2 2909113002


if((k%5)==0)

for(j=i+1;j<n-1;j++)

final[j]=final[j+1];

printf("%c",final[i]);

getch();

Output

Enter the message:

0111111001101011111010010101010101111110

Message after decoding:

01101011111100101010101

Enter the message:

0111111001111101111100010101010101111110

Message after decoding:

0111111111100101010101

Pramod Kumar IT-1 6th sem B-2 2909113002

You might also like