0% found this document useful (0 votes)
9 views5 pages

Week7 and 8 Programs

Week 8

Uploaded by

shruthivatham33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Week7 and 8 Programs

Week 8

Uploaded by

shruthivatham33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ENCRYPTION

#include <stdio.h>

#include <string.h> // For strcspn()

int main() {

char message[100], ch;

int i, key;

// Input message

printf("Enter a message to encrypt: ");

fgets(message, sizeof(message), stdin); // Using fgets to prevent overflow

message[strcspn(message, "\n")] = '\0'; // Remove newline character

// Input key

printf("Enter key: ");

scanf("%d", &key);

// Encryption process

for (i = 0; message[i] != '\0'; ++i) {

ch = message[i];

// Encrypt lowercase letters

if (ch >= 'a' && ch <= 'z') {

ch = ch + key;

if (ch > 'z') {

ch = ch - 'z' + 'a' - 1;

message[i] = ch;
}

// Encrypt uppercase letters

else if (ch >= 'A' && ch <= 'Z') {

ch = ch + key;

if (ch > 'Z') {

ch = ch - 'Z' + 'A' - 1;

message[i] = ch;

// Output encrypted message

printf("Encrypted message: %s\n", message);

return 0;

DECRYPTION

#include <stdio.h>

#include <string.h> // For strcspn()


int main() {

char message[100], ch;

int i, key;

// Input encrypted message

printf("Enter the encrypted message: ");

fgets(message, sizeof(message), stdin); // Using fgets to prevent overflow

message[strcspn(message, "\n")] = '\0'; // Remove newline character

// Input decryption key

printf("Enter key: ");

scanf("%d", &key);

// Decryption process

for (i = 0; message[i] != '\0'; ++i) {

ch = message[i];

// Decrypt lowercase letters

if (ch >= 'a' && ch <= 'z') {

ch = ch - key;

if (ch < 'a') {

ch = ch + 'z' - 'a' + 1;

message[i] = ch;

// Decrypt uppercase letters

else if (ch >= 'A' && ch <= 'Z') {


ch = ch - key;

if (ch < 'A') {

ch = ch + 'Z' - 'A' + 1;

message[i] = ch;

// Output decrypted message

printf("Decrypted message: %s\n", message);

return 0;

LEAKY BUCKET ALGORITHM


#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--;
}
}

You might also like