1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define STR 1000
void English_to_Morse();
void Morse_to_English();
int main()
{
char ch,ans;
printf("Would you like to decode or encode the text now? \n 'y' for yes and 'n' for no.\n");
scanf("%c",&ans);
while(ans =='y' || ans=='Y')
{
printf("\n\tSelect from the menu:\n"
"\tA. English to Morse\n"
"\tB. Morse to English\n");
fflush(stdin);
scanf("%c",&ch);
if(tolower(ch) == 'a')
{
English_to_Morse();
printf("\n\n");
printf("Do you want to continue to decode or encode another text?\n 'y' for yes and 'n' for no.\n");
fflush(stdin);
scanf("%c",&ans);
}
else if (tolower(ch) == 'b')
{
Morse_to_English();
printf("\n\n");
printf("Do you want to continue to decode or encode another text?\n 'y' for yes and 'n' for no.\n");
fflush(stdin);
scanf("%c",&ans);
}
else
{
printf("Invalid! Enter again: \n");
scanf("%c",&ch);
}
}
while(ans=='y' || ans=='N');
{
if(ans=='n' || ans=='N')
{
printf("\n\n");
printf("Thank you for using this system \2\n\n\n");
}
else
printf("Invalid! \n");
}
system("pause");
return 0;
}
void English_to_Morse()
{
int len, a, b,i=0;
char phr[STR],ans;
char alpha[]={"abcdefghijklmnopqrstuvwxyz1234567890"};
char *morse[37]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
"-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-",
"..-","...-",".--","-..-","-.--","--..",".----","..---",
"...--","....-",".....","-....","--...","---..","----.",
"-----"," "};
printf("\n\tEnter in a phrase in English for encrypting\n");
while (phr[i]!='\0')
{
scanf("%s", phr);
len=strlen(phr);
printf("\nConverting the phrase to Morse Code.... \n");
sleep(50);
for(a=0; a<len; a++)
{
for(b=0; b<37; b++)
{
if(tolower(phr[a])==alpha[b])
printf("%s ", morse[b]);
}
}
i++; printf(" ");
}
printf("\n\tDone!\n");
printf("\n");
return;
}
void Morse_to_English()
{
int len, a, b, i=0;
char phr[STR];
char alpha[]="abcdefghijklmnopqrstuvwxyz1234567890";
char *morse[36]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
"-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-",
"..-","...-",".--","-..-","-.--","--..",".----","..---",
"...--","....-",".....","-....","--...","---..","----.",
"-----"};
printf("\t\t\tMorse Code: \n");
for(i=0; i<36; i++)
{
printf("%s", morse[i]);
printf("\t");
}
printf("\n\n\tEnter a line of Morse Code for decrypting\n\n");
scanf("%s",&phr);
len=strlen(phr);
printf("\nConverting the Morse Code.... \n");
for(a=0; a<36; a++)
{
if(strcmp(phr, morse[a])==0 && *phr!='\0')
printf("%c", alpha[a]);
}
printf(" ");
printf("\n");
return;
}
|