#include <stdio.h>int main(){ int i, x; char str[100]; printf("\nPlease enter a string:\t"); gets(str); printf("\nPlease choose following options:\n"); printf("1 = Encrypt the string.\n"); printf("2 = Decrypt the string.\n"); scanf("%d", &x); //using switch case statements switch(x) { case 1: for(i = 0; (i < 100 && str[i] != '\0'); i++) str[i] = str[i] + 3; //the key for encryption is 3 that is added to ASCII value printf("\nEncrypted string: %s\n", str); break; case 2: for(i = 0; (i < 100 && str[i] != '\0'); i++) str[i] = str[i] - 3; //the key for encryption is 3 that is subtracted to ASCII value printf("\nDecrypted string: %s\n", str); break; default: printf("\nError\n"); } return 0;}
#include<stdio.h>int main(){ int incoming, outgoing, buck_size, n, store = 0; printf("Enter bucket size, outgoing rate and no of inputs: "); scanf("%d %d %d", &buck_size, &outgoing, &n); while (n != 0) { printf("Enter the incoming packet size : "); scanf("%d", &incoming); printf("Incoming packet size %d\n", incoming); if (incoming <= (buck_size - store)){ store += incoming; printf("Bucket buffer size %d out of %d\n", store, buck_size); } else { printf("Dropped %d no of packets\n", incoming - (buck_size - store)); printf("Bucket buffer size %d out of %d\n", store, buck_size); store = buck_size; } store = store - outgoing; printf("After outgoing %d packets left out of %d in buffer\n", store, buck_size); n--; }}
Sliding Window
#include<stdio.h>int main(){ int w,i,f,frames[50]; printf("Enter window size: "); scanf("%d",&w); printf("\nEnter number of frames to transmit: "); scanf("%d",&f); printf("\nEnter %d frames: ",f); for(i=1;i<=f;i++) scanf("%d",&frames[i]); printf("\nWith sliding window protocol the frames will be sent in the following manner (assuming no corruption of frames)\n\n"); printf("After sending %d frames at each stage sender waits for acknowledgement sent by the receiver\n\n",w); for(i=1;i<=f;i++) { if(i%w==0) { printf("%d\n",frames[i]); printf("Acknowledgement of above frames sent is received by sender\n\n"); } else printf("%d ",frames[i]); } if(f%w!=0) printf("\nAcknowledgement of above frames sent is received by sender\n"); return 0;}