Uploaded by gpw2564

IS Pract3

advertisement
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void substitution_encrypt(char *plaintext, char *key)
{
int i;
for(i=0; i<strlen(plaintext); i++)
{
if(isalpha(plaintext[i]))
{
int j = tolower(plaintext[i])- 'a';
plaintext[i] = key[j];
}
}
}
void transposition_encrypt(char *plaintext)
{
strrev(plaintext);
}
void encrypt(char *plaintext, char *key)
{
substitution_encrypt(plaintext, key);
transposition_encrypt(plaintext);
}
void main()
{
char plaintext[100], key[27];
clrscr();
printf("c );
gets(plaintext);
printf("Enter Key : ");
gets(key);
encrypt(plaintext, key);
printf("Encrypted text : %s \n", plaintext);
getch();
}
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void substitution_decrypt(char *ciphertext, char *key)
{
int i;
for (i=0; i<strlen(ciphertext); i++)
{
if (isalpha(ciphertext[i]))
{
int j = 0;
while(key[j] != ciphertext[i])
j++;
ciphertext[i] = 'a' + j;
}
}
}
void transposition_decrypt(char *ciphertext)
{
strrev(ciphertext);
}
void decrypt(char *ciphertext, char *key)
{
transposition_decrypt(ciphertext);
substitution_decrypt(ciphertext, key);
}
void main()
{
char ciphertext[100], key[27];
printf("Enter Ciphertext : ");
gets(ciphertext);
printf("Enter Key : ");
gets(key);
decrypt(ciphertext, key);
printf("Decrypted Text : %s \n", ciphertext);
getch();
}
Download