/*
Name: Funcion Morse
Author: Strup
Date: 09/12/13 14:14
Description: Cifrar un texto a morse y descifrarlo.
*/
#include <stdio.h>
#include <stdlib.h>
void cifrar(char *string,long *cifrado);
char *descifrar(long *cadena);
int i;char *texto;
int main()
{
texto=(char*)malloc(1000*sizeof(char));
gets(texto);long str[strlen(texto)];
cifrar(texto,str);
for(i=0;i<strlen(texto);i++)
{
printf("%s",str[i]);
}
puts("");
printf("%s\n",descifrar(str));
system("PAUSE");
return 0;
}
void cifrar(char *string,long *cifrado)
{
int x,y;
char *puntero_texto="abcdefghijklmnopqrstuvwxyz0123456789.,?-!:;()=$@_+~# '",*puntero_texto_uper="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,?-!:;()=$@_+~# '";
char *morse[]={".- ", "-... ", "-.-. ", "-.. ", ". ","..-. ", "--. ", ".... ", ".. ", ".--- ", "-.- ", ".-.. ", "-- ", "-. ", "--- ", ".--. ", "--.- ", ".-. ", "... ", "- ", "..- ", "...- ",".-- ", "-..- ", "-.-- ", "--.. ", "----- ",".---- ", "..--- ", "...-- ", "....- ", "..... ", "-.... ", "--... ","---.. ", "----. ", ".-.-.- ", "--..-- ", "..--.. ", "-....- ", "-.-.-- ", "---... ", "-.-.-. ", "-.--. ", "-.--.- ", "-...- ", "...-..- ", ".--.-. ","..--.- ", ".-.-. ", ".-... ", "...-.- ", "/ ", ".----. "};
for(x=0;x<=strlen(string);x++)
{
for(y=0;y<=54;y++)
{
if(string[x] == puntero_texto[y] || string[x] == puntero_texto_uper[y])
{
cifrado[x]=morse[y];
}
}
}
}
char *descifrar(long *cadena)
{
char *morse[]={".- ", "-... ", "-.-. ", "-.. ", ". ","..-. ", "--. ", ".... ", ".. ", ".--- ", "-.- ", ".-.. ", "-- ", "-. ", "--- ", ".--. ", "--.- ", ".-. ", "... ", "- ", "..- ", "...- ",".-- ", "-..- ", "-.-- ", "--.. ", "----- ",".---- ", "..--- ", "...-- ", "....- ", "..... ", "-.... ", "--... ","---.. ", "----. ", ".-.-.- ", "--..-- ", "..--.. ", "-....- ", "-.-.-- ", "---... ", "-.-.-. ", "-.--. ", "-.--.- ", "-...- ", "...-..- ", ".--.-. ","..--.- ", ".-.-. ", ".-... ", "...-.- ", "/ ", ".----. "};
char *matriz[]={"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","0","1","2","3","4","5","6","7","8","9",".",",","?","-","!",":",";","(",")","=","$","@","_","+","~","#"," ","'"};
int x,y;
char descifrado[500]="";
for (x=0;x<=sizeof(cadena)*500;x++)
{
for(y=0;y<=54;y++)
{
if(cadena[x] == morse[y])
{
strcat(descifrado,matriz[y]);
}
}
}
return descifrado;
}
una toma de su funcionamiento
espero os guste el code, cualquier cosa avisan un saludo Bueno me aburria y despues de hacerla en php codee esta funcion de cifrado y descifrado morse en C, para ir atinando mas las practicas que llevo a cavo con este lenguaje, bueno aqui e lcode.
Abolición para el torneo del toro de la vega. Death to the murderers of bulls.