Podéis copiar el código directamente:
#include <stdio.h>
#define NUM_LETRAS 26
char cesar_char(char c,int desp){
char abc[NUM_LETRAS]={'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'};
int cod=0;
int i=0;
while(i<NUM_LETRAS && c!=abc[i])i++;
cod=i+desp;
if(cod>NUM_LETRAS){cod%=NUM_LETRAS;}
return abc[cod-1];
}
void cesar(char* text,int desp){
char res[256];
int postext=0;
int posres=0;
char charcod;
char local;
local=text[0];
while(local!='\0'){
charcod=cesar_char(local,desp);
res[posres]=charcod;
posres++;
postext++;
local=text[postext];
}
res[posres]='\0';
printf("Resultado: %s\n",res);
}
int main(){
char c[256];
int desp;
printf("Texto para codificar: ");
scanf("%s",&c);
printf("Desplazamiento: ");
scanf("%d",&desp);
cesar(c,desp);
return 0;
}
O descargar el código fuente de aquí:
Descargar
Thanks for your comment. I think you could find a lot of information in google ;).
ResponderEliminar