Letter comparison

Asked

Viewed 91 times

0

I managed to make a letter typed by the user, be shown another

Example: c returns A, because the letter A is the one that uses our alphabet the most. So I can unravel a message for example, because in the message the most outgoing letter is C, so C turned A.

Only it has letters that have the same amount of repetitions, for example j,g with 10 each. The question is how to make the letter j and then g, type a weight for one of them.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
main()
{
char chave[26],texto[30],frase[30];

int cont,i;

printf("Digite o texto: ");
scanf("%s",chave);

cont=strlen(chave);
strcpy(texto, chave);  

for(i=0;i<cont;i++)     
{
    if (texto[i]=='c')
        frase[i]='a';      

    else if (texto[i]=='z')
        frase[i]='e';
    else if (texto[i]=='s')
        frase[i]='o';
    else if (texto[i]=='m')
        frase[i]='r';
        else if (texto[i]=='n')
        frase[i]='n';
        else if (texto[i]=='e')
        frase[i]='z';
        else if (texto[i]=='j')
        frase[i]='d';
        else if (texto[i]=='a')
        frase[i]='w';           

    else frase[i]=texto[i];
} 
printf("\n %s\nTexto Descriptografada e :\n %s\n", chave, frase);  
}
  • Friend, your question is not clear. Exactly what you need?

  • What do you mean weight for the letters G and J? Do you want to assign integer value? (it can’t, it’s only possible to maybe represent them in string maybe)

  • it would be like decrypting a code, where the key would be the letters that leave most in Portuguese, hence each letter of the code receives the most accessed letter, example, if in the text to be decrypted is. xxxaattt, X receives A, because A is the first letter that appears most, but as I do for the letter A and T, for the two have the same number in that text to be converted

  • Possible duplicate of Substitution in c

  • It’s not clear yet. To compare letters, just see if they have the same code. Count occurrences in a text, you use a loop and a counter. But now, if your problem is how to implement a decoder, your question is too broad (and the logic you put in the comment is unreliable)

  • would have some PDF of how to do this, I’m beginner in C

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.