#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char* CodificarCesar(char texto_nao_codificado[256], int chave)
{
char alf[]= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\n','\0'};
char mensagem_original[256];
char* mensagem_codificada
= malloc(256*sizeof(char));
memset(mensagem_codificada
,'\0',sizeof(mensagem_codificada
)); memset(mensagem_original
,'\0',sizeof(mensagem_original
)); strcpy(mensagem_original
,texto_nao_codificado
);
int i
,j
, tam
= strlen(mensagem_original
);
for(i=0; i<tam; i++){
{
if(mensagem_original[i]==alf[j])
{
mensagem_codificada[i]=alf[(j+chave)%26];
break;
}
else if(mensagem_original
[i
]==toupper(alf
[j
])) {
mensagem_codificada
[i
]=toupper(alf
[(j
+chave
)%26]); break;
}
else if(isspace(mensagem_original
[i
])) {
mensagem_codificada[i]=' ';
break;
}//else space
}//for j
}
mensagem_codificada[i] = '\0';
strcat(mensagem_codificada
,"\n"); memset(mensagem_original
,'\0',sizeof(mensagem_original
));
return mensagem_codificada;
}
int main(){
char msg_orig[] = "Zorro";
char *codificada = CodificarCesar(msg_orig, 1);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8Y3R5cGUuaD4KCgpjaGFyKiBDb2RpZmljYXJDZXNhcihjaGFyIHRleHRvX25hb19jb2RpZmljYWRvWzI1Nl0sIGludCBjaGF2ZSkKewoKICAgIGNoYXIgYWxmW109IHsnYScsJ2InLCdjJywnZCcsJ2UnLCdmJywnZycsJ2gnLCdpJywnaicsJ2snLCdsJywnbScsJ24nLCdvJywncCcsJ3EnLCdyJywncycsJ3QnLCd1JywndicsJ3cnLCd4JywneScsJ3onLCdcbicsJ1wwJ307CiAgICBjaGFyIG1lbnNhZ2VtX29yaWdpbmFsWzI1Nl07CiAgICBjaGFyKiBtZW5zYWdlbV9jb2RpZmljYWRhID0gbWFsbG9jKDI1NipzaXplb2YoY2hhcikpOwoKICAgIG1lbXNldChtZW5zYWdlbV9jb2RpZmljYWRhLCdcMCcsc2l6ZW9mKG1lbnNhZ2VtX2NvZGlmaWNhZGEpKTsKICAgIG1lbXNldChtZW5zYWdlbV9vcmlnaW5hbCwnXDAnLHNpemVvZihtZW5zYWdlbV9vcmlnaW5hbCkpOwogICAgc3RyY3B5KG1lbnNhZ2VtX29yaWdpbmFsLHRleHRvX25hb19jb2RpZmljYWRvKTsKCiAgICBpbnQgaSxqLCB0YW0gPSBzdHJsZW4obWVuc2FnZW1fb3JpZ2luYWwpOwoKICAgIGZvcihpPTA7IGk8dGFtOyBpKyspewogICAgICAgIGZvcihqPTA7IGo8c3RybGVuKGFsZik7IGorKykKICAgICAgICB7CiAgICAgICAgICAgIGlmKG1lbnNhZ2VtX29yaWdpbmFsW2ldPT1hbGZbal0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIG1lbnNhZ2VtX2NvZGlmaWNhZGFbaV09YWxmWyhqK2NoYXZlKSUyNl07CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGlmKG1lbnNhZ2VtX29yaWdpbmFsW2ldPT10b3VwcGVyKGFsZltqXSkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIG1lbnNhZ2VtX2NvZGlmaWNhZGFbaV09dG91cHBlcihhbGZbKGorY2hhdmUpJTI2XSk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGlmKGlzc3BhY2UobWVuc2FnZW1fb3JpZ2luYWxbaV0pKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBtZW5zYWdlbV9jb2RpZmljYWRhW2ldPScgJzsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9Ly9lbHNlIHNwYWNlCgogICAgICAgIH0vL2ZvciBqCiAgICB9CgoKICAgIG1lb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