You are on page 1of 5

OSI MODEL WITH STRING IMPLIMENTATION

CODE:

#include <bits/stdc++.h>

#include <windows.h>

using namespace std;

int main()

string s;
cout<<"OSI MODEL\n";

cout<<"RECIEVER SIDE\n";

Sleep(1000);
cout<<"Entering the application layer. \n";
cout<<"enter the message\n"; cin>>s;

string orig=s; s="ah"+s;

cout<<"after adding the header "<<s;

Sleep(1000);

cout<<"\n entering into presentation layer";

s="pt"+s;

cout<<"\nafter adding the header "<<s;


Sleep(1000);

cout<<"\n entering into session layer";

s="sh"+s;

cout<<"\nafter adding the header "<<s;

Sleep(1000);

cout<<"\nentering into transport layer";

s="th"+s;

cout<<"\nafter adding the header "<<s;

Sleep(1000);

cout<<"\nentering into network layer";

s="nh"+s;

cout<<"\nafter adding the header "<<s;

Sleep(1000);

cout<<"\n entering into datalink layer";

s="dh"+s;

cout<<"\nafter adding the header "<<s;

Sleep(1000);

cout<<"\n entering into physical layer";

s="ph"+s;

cout<<"\nafter adding the header "<<s;


string b;

s.replace(0,2,"0");//p
s.replace(1,2,"1");//da
s.replace(2,2,"0");//t s.replace(3,2,"1");

//session

s.replace(4,2,"0");//pre s.replace(5,2,"1");

//application s.replace(6,2,"0");//application int l=s.find(orig);

// cout<<"length is:"<<l<<"\n";

int val=stoi(orig);

// cout<<"value is"<<val; char res[1000];

itoa(val,res,2);

string vals(res); s.replace(7,orig.length(),vals);

Sleep(2000);

cout<<"\nafter converting into binary "<<s;

Sleep(2000);
cout<<"\n------------------------RECIEVER SIDE ";
cout<<"\nRecived message is"<<s;

Sleep(1000);
cout<<"\nafter Passing thorugh physical layer data
is:"<<setw(10)<<s.substr(1,s.length()-1);
Sleep(1000);
cout<<"\nafter Passing thorugh Datalink layer data
is:"<<setw(10)<<s.substr(2,s.length()-1);
Sleep(1000);

cout<<"\nafter Passing thorugh Network layer data


is:"<<setw(10)<<s.substr(3,s.length()-1);
Sleep(1000);
cout<<"\nafter Passing thorugh Transport layer data
is:"<<setw(10)<<s.substr(4,s.length()-1);
Sleep(1000);
cout<<"\nafter Passing thorugh Session layer data
is:"<<setw(10)<<s.substr(5,s.length()-1);
Sleep(1000);
cout<<"\nafter Passing thorugh Presentation layer data
is:"<<setw(10)<<s.substr(6,s.length()-1);
Sleep(1500);
string rec=s.substr(7,s.length()-1);
unsigned long long valuesss = std::stoull(rec, 0, 2);
cout<<"\nafter Passing thorugh Application layer data is"<<valuesss;
}

You might also like