Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define vi vector<int>
- #define vll vector<long long int>
- void BellmanFord(int network[3][3], int routers, int connections, int source, int arr[3][3])
- {
- int dist[routers];
- for (int i = 0; i < routers; i++)
- {
- dist[i] = INT_MAX;
- }
- dist[source] = 0;
- for (int i = 0; i < routers - 1; i++)
- {
- for (int j = 0; j < connections; j++)
- {
- if (dist[network[j][0]] != INT_MAX && dist[network[j][0]] + network[j][2] < dist[network[j][1]])
- dist[network[j][1]] = dist[network[j][0]] + network[j][2];
- }
- }
- // cout << "Router Distance from Source-router " << source + 1 << endl;
- for (int i = 0; i < routers; i++)
- {
- arr[source][i] = min(arr[source][i], dist[i]);
- arr[i][source] = min(arr[source][i], dist[i]);
- }
- }
- int main()
- {
- std::ios::sync_with_stdio(false);
- int routers;
- cout << "Enter the number of routers :: ";
- cin >> routers;
- int connections;
- cout << "Enter the number of connections :: ";
- cin >> connections;
- int s, d, hc;
- int network[3][3];
- int arr[3][3];
- for (int i = 0; i < routers; i++)
- {
- for (int j = 0; j < routers; j++)
- {
- network[i][j] = INT_MAX;
- }
- }
- cout << "Enter " << connections << " details in (source_router,destination_router,hop_cost) format " << endl;
- for (int i = 0; i < connections; i++)
- {
- cin >> s >> d >> hc;
- network[s - 1][d - 1] = hc;
- network[d - 1][s - 1] = hc;
- }
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- arr[i][j] = INT_MAX;
- }
- }
- int choice;
- while (1)
- {
- cout << "Do you want to compute the shortest hops ? press 1 to compute ,any other character to exit :: ";
- cin >> choice;
- if (choice == 1)
- {
- int src;
- cout << "Enter the source router to compute the shortest hops to other routers :: ";
- cin>>src;
- BellmanFord(network, routers, connections, src-1, arr);
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- }
- else
- {
- break;
- }
- }
- return 0;
- }
- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define vi vector<int>
- #define vll vector<long long int>
- char t[128], cs[128], g[] = "10001000000100001";
- int a, e, c;
- int N = strlen(g);
- void xor_fun()
- {
- for (c = 1; c < N; c++)
- {
- cs[c] = ((cs[c] == g[c]) ? '0' : '1');
- }
- }
- void crc()
- {
- for (e = 0; e < N; e++)
- {
- cs[c] = cs[c + 1];
- }
- do
- {
- if (cs[0] == '1')
- {
- xor_fun();
- }
- for (c = 0; c < N; c++)
- {
- cs[c] = cs[c + 1];
- cs[c] == t[e++];
- }
- } while (e <= a + N - 1);
- }
- int main()
- {
- std::ios::sync_with_stdio(false);
- cout<<"Enter the Polynomial :: ";
- cin>>t;
- cout<<"\nGenerating Polynomial is :: "<<g;
- a = strlen(t);
- for(e = a;e<a+N-1;e++){
- t[e] = '0';
- }
- cout<<"\nModified t[u] is :: "<<t;
- crc();
- getchar;
- cout<<"\nChecksum is :: "<<cs;
- for(e=a;e<a+N-1;e++){
- t[e] = cs[e-a];
- }
- cout<<"\nFinal Codeword is :: "<<t;
- cout<<"\nTest Error detection 0(yes) 1(no) ? :: ";
- cin>>e;
- if(e==0){
- cout<<"\nEnter the position where error is to be inserted :: ";
- cin>>e;
- t[e] = (t[e] == '0')?'1':'0';
- cout<<"\nErrorneous data :: "<<t;
- }
- crc();
- for(e=0;(e<N-1) && (cs[e]!='1');e++);
- if(e<N-1){
- cout<<"\nError Detected";
- }
- else{
- cout<<"\nNo Error Detected";
- }
- }
- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int gcd(int a, int b)
- {
- int c;
- while(a != b)
- {
- if(a < b)
- {
- c = a;
- a = b;
- b = c;
- }
- a -= b;
- }
- return a;
- }
- int mod(int x,int y, int p)
- {
- int res = 1;
- x = x % p;
- if (x == 0) return 0;
- while (y > 0)
- {
- // If y is odd, multiply x with result
- if (y & 1)
- res = (res*x) % p;
- y = y>>1; // y = y/2
- x = (x*x) % p;
- }
- return res;
- }
- int main()
- {
- int p,q,n,e,m,c,d,x,z;
- int en[100],de[100], j = 0,fact_z[100];
- printf("\nEnter the value of p and q: ");
- scanf("%d%d", &p, &q);
- n = p*q;
- int cnt;
- cnt = 0;
- z = (p-1)*(q-1);
- for(int i = 1;i<z;i++){
- if(z%i == 0){
- printf("%d ",i);
- fact_z[cnt] = i;
- cnt++;
- }
- }
- printf("Choose a value for e from a number which is not in list :: ");
- scanf("%d",&e);
- for(int i=0;i<cnt;i++){
- if(fact_z[i] == e|| gcd(e,z) != 1){
- printf("e belongs to the factors list get lost!!");
- return 0;
- }
- }
- printf("Enter the message(int) to be encrypted: ");
- scanf("%d", &m);
- printf("Before encryption: %d\n", m);
- c = mod(m, e, n);
- printf("After encryption: %d\n", c);
- d = z;
- cnt = 2;
- while (1){
- if(d%e == 0){
- break;
- }else{
- d = (cnt*z)+1;
- cnt++;
- }
- }
- d = d/e;
- printf("\n%d\n",d);
- x = mod(c, d, n);
- printf("After decryption: %d\n", x);
- return 0;
- }
- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- #include <iostream>
- #include <dos.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include<windows.h>
- using namespace std;
- #define bucketSize 512
- int random(int min, int max){
- return min + rand() / (RAND_MAX / (max - min + 1) + 1);
- }
- void bktInput(int a, int b)
- {
- if (a > bucketSize)
- cout << "\n\t\tBucket overflow";
- else
- {
- Sleep(500);
- while (a > b)
- {
- cout << "\n\t\t" << b << " bytes outputted."<<"\t Remaining bytes "<<a;
- a -= b;
- Sleep(500);
- }
- if (a > 0)
- cout << "\n\t\tLast " << a << " bytes sent\t";
- cout << "\n\t\tBucket output successful";
- }
- }
- int main()
- {
- int op, pktSize;
- // randomize();
- cout << "Enter output rate : ";
- cin >> op;
- for (int i = 1; i <= 5; i++)
- {
- Sleep(random(100,1000));
- pktSize = random(100,700);
- cout << "\nPacket no " << i << "\tPacket size = " << pktSize;
- bktInput(pktSize, op);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement