0% found this document useful (0 votes)
10 views2 pages

Polyalphabetic Algorithm

The document contains two C programs implementing a polyalphabetic encryption and decryption algorithm using a key. The encryption program generates a new key based on the input message and encrypts it, while the decryption program reverses the process to retrieve the original message. Both programs display the original message, key, generated key, and the resulting encrypted or decrypted message.

Uploaded by

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

Polyalphabetic Algorithm

The document contains two C programs implementing a polyalphabetic encryption and decryption algorithm using a key. The encryption program generates a new key based on the input message and encrypts it, while the decryption program reverses the process to retrieve the original message. Both programs display the original message, key, generated key, and the resulting encrypted or decrypted message.

Uploaded by

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

ENS EN NO.

:206400316171

Polyalphabetic Encryption Algorithm


#include<stdio.h>

#include<string.h>

int main(){

char msg[] = "THERE IS A SECRET PASSAGE BEHIND THE PICTURE";

char key[] = "PASSWORD";

int msgLen = strlen(msg), keyLen = strlen(key), i, j;

char newKey[msgLen], encryptedMsg[msgLen];

//generating new key

for(i = 0, j = 0; i < msgLen; ++i, ++j){

if(j == keyLen)

j = 0;

newKey[i] = key[j];

newKey[i] = '\0';

//encryption

for(i = 0; i < msgLen; ++i){

encryptedMsg[i] = ((msg[i] + newKey[i]) % 26) + 'A';

encryptedMsg[i] = '\0';

printf("Original Message: %s", msg);

printf("\nKey: %s", key);

printf("\nNew Generated Key: %s", newKey);

printf("\nEncrypted Message: %s", encryptedMsg);

return 0;

}
ENS EN NO.:206400316171

Polyalphabetic Decryption Algorithm


#include<stdio.h>

#include<string.h>

int main()

char msg[] = "IHWJAHZVIALKAQIHITHSOGRJTTTWDWEGITZWPDZFIUJW";

char key[] = "PASSWORD";

int msgLen = strlen(msg), keyLen = strlen(key), i, j;

char newKey[msgLen], decryptedMsg[msgLen];

//generating new key

for(i = 0, j = 0; i < msgLen; ++i, ++j){

if(j == keyLen)

j = 0;

newKey[i] = key[j];

newKey[i] = '\0';

// decryption

for(i = 0; i < msgLen; ++i){

decryptedMsg[i] = (((msg[i] - newKey[i]) + 26) % 26) + 'A';

decryptedMsg[i] = '\0';

printf("Original Message: %s", msg);

printf("\nKey: %s", key);

printf("\nNew Generated Key: %s", newKey);

printf("\nDecrypted Message: %s", decryptedMsg);

You might also like