answersLogoWhite

0


Best Answer

//Monalphabetic Cipher

/**Created by:Mihir Vadalia*/

#include

#include

FILE *source,*dest,*kf;

void encrypt();

void decrypt();

void main()

{

int choice;

do

{

clrscr();

printf("\n\n\t\tMonoalphabetic Cipher\n\nEnter your chice:\n");

printf("1.Encryption\n2.Decryption\n3.Exit.\n\nYour Choice:");

scanf("%d",&choice);

switch(choice)

{

case 1:

encrypt();

break;

case 2:

decrypt();

break;

default:

exit(0);

}

getch();

}while(choice);

}

void encrypt()

{

char k[26]={'/0'},fname[15],ch;

int i,n;

printf("\n\nEnter the name of file to be encrypted:\n");

flushall();

gets(fname);

flushall();

source = fopen(fname,"r");

dest = fopen("Dest.txt","w");

kf = fopen("key.txt","r");

i=0;

while((ch=getc(kf))!=EOF)

{

k[i]=ch;

i++;

}

while ((ch=getc(source))!=EOF)

{

n=(int)ch-97;

for (i=0;i!=n;i++);

putc(k[i],dest);

}

fclose(dest);

fclose(source);

fclose(kf);

printf("\n\nThe file has been encrypted...\n\nThe contents are:\n");

dest=fopen("Dest.txt","r");

while((ch=getc(dest))!=EOF)

printf("%c",ch);

}

void decrypt()

{

char k[26]={'/0'},fname[15],ch;

int i,n;

printf("\n\nEnter the name of file to be decrypted:\n");

flushall();

gets(fname);

flushall();

dest = fopen(fname,"r");

kf = fopen("key.txt","r");

i=0;

while((ch=getc(kf))!=EOF)

{

k[i]=ch;

i++;

}

printf("\nDecrypted contents are : ");

while ((ch=getc(dest))!=EOF)

{

for (i=0;ch!=k[i];i++);

putchar(97+i);

}

fclose(source);

fclose(kf);

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C code to encrypt monoalphabetic cipher?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is difference between monoalphabetic and polyalphabetic cipher?

In a monoalphabetic cipher, our substitution characters are a random permutation of the 26 letters of the alphabet: plaintext letters: a b c d e f ..... substitution letters: t h i j a b ..... • The key now is the sequence of substitution letters. In other words, the key in this case is the actual random permutation of the alphabet used. For a particular alphabet, only one substitution can be used example: if the substitution letter for 'a' is 't' and for 'd' it is 'p' then if the keyword happens to be "tpp"..... then we can encrypt the message as "add"(note that the substitution letter for 'd' is only 'p'.. In a monoalphabetic cipher, the same substitution rule is used for every substitution. In a polyalphabetic cipher, the substitution rule changes continuously from letter to letter according to the elements of the encryption key. Example for polyalphabetic: key: abracadabraabracadabraabracadabraab plaintext: canyoumeetmeatmidnightihavethegoods ciphertext: CBEYQUPEFKMEBK..................... • The Vigenere cipher is an example of a polyalphabetic cipher.


Difference of polyalphabetic substitution cipher and polyalphabetic cipher?

In a monoalphabetic cipher, our substitution characters are arandom permutation of the 26 letters of the alphabet:plaintext letters: a b c d e f .....substitution letters: t h i j a b .....• The key now is the sequence of substitution letters. In otherwords, the key in this case is the actual random permutation ofthe alphabet used.For a particular alphabet, only one substitution can be usedexample: if the substitution letter for 'a' is 't' and for 'd' it is 'p'then if the keyword happens to be "tpp"..... then we can encrypt the message as "add"(note that the substitution letter for 'd' is only 'p'..In a monoalphabetic cipher, the same substitution rule is used forevery substitution. In a polyalphabetic cipher, the substitutionrule changes continuously from letter to letter according to theelements of the encryption key.Example for polyalphabetic:key: abracadabraabracadabraabracadabraabplaintext: canyoumeetmeatmidnightihavethegoodsciphertext: CBEYQUPEFKMEBK.....................• The Vigenere cipher is an example of a polyalphabetic cipher.


Algorithm for hill cipher?

Hill Cipher is a cryptographic algorithm to encrypt and decrypt an alphabetic text. In this cipher, each letter is represented by a number (eg. A = 0, B = 1, C = 2). To encrypt a message, each block of n letters (considered as an n -component vector) is multiplied by an invertible n × n matrix, against modulus 26.


Difference of polyalphabetic substitution cipher and monoalphabetic cipher?

mono meant one so substitution the replaced values as one character each value of alphabetic substitute A-Z . Plain text: a b c d e….. Substitution: d e f g h….. Polyalphabetic it's nothing but.. ploy meant more than one so its contain the more than one letters to substitution then also here using the key. Mono and ploy are using the same techniques of the substitution. Substitutions are having mono and ploy and then etc… In a monoalphabetic cipher, our substitution characters are a random permutation of the 26 letters of the alphabet: plaintext letters: a b c d e f ..... substitution letters: t h i j a b ..... • The key now is the sequence of substitution letters. In other words, the key in this case is the actual random permutation of the alphabet used. For a particular alphabet, only one substitution can be used example: if the substitution letter for 'a' is 't' and for 'd' it is 'p' then if the keyword happens to be "tpp"..... then we can encrypt the message as "add"(note that the substitution letter for 'd' is only 'p'.. In a monoalphabetic cipher, the same substitution rule is used for every substitution. In a polyalphabetic cipher, the substitution rule changes continuously from letter to letter according to the elements of the encryption key. Example for polyalphabetic: key: abracadabraabracadabraabracadabraab plaintext: canyoumeetmeatmidnightihavethegoods ciphertext: CBEYQUPEFKMEBK..................... • The Vigenere cipher is an example of a polyalphabetic cipher.


What is the program to write route cipher?

c#


What is the command to decrypt the myfiledoc?

cipher /d C:\filename.ext.


How do you write a program a bout rotor cipher using C?

Just fart!


How you complete level 54 on 100 Floors?

a=01 so code is c=03 o=15 d=04 e=05 The A=01 is the cipher and the level is asking you enter C-O-D-E where C=03, O=15, D=04, and E=05. See related links for screenshots.


How do you complete level 54 on 100 Floors?

a=01 so code is c=03 o=15 d=04 e=05 The A=01 is the cipher and the level is asking you enter C-O-D-E where C=03, O=15, D=04, and E=05. See related links for screenshots.


What is key of hill cipher if we have plain text and cipher text?

Assume Plaintext = P, Ciphertext = C, and the Key = K. C = P * K Therefore, multiply both sides by the inverse of P and you will get: C * P^(-1) = K Or, (ciphertext) * (inverse plaintext) = key If the size of the key is known as well, then use that same size when creating P and C matrices.


What is Caesar cipher?

secret language add 3 more e.g..................... a=d b=e c=f and so on.......


Is substitution a type of cipher?

Yes A=B B=C etc so CAT in cypher is DBU as one example