Contact Learn C
Copy

Program 247: Decryption of Morse Code Cipher in C

Program 247: Visit Morse Code encryption
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
    int i=0,j=0,k=0,flag=0;
    char *alphamorse[]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
                    "-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-",
     "...-",".--","-..-","-.--","--.."};
 char *nummorse[]={"-----",".----","..---","...--","....-",".....","-....","--...","---..","----."};
 
    char morseCode[1000]={0},substr[1000][100]={0},c;
    printf("Enter a Morse Code with spaces\n");
    gets(morseCode);    
    while(morseCode[k]!='\0')//for splitting sentence
    {
        j=0;
        while(morseCode[k]!=' '&&morseCode[k]!='\0')
        {
            substr[i][j]=morseCode[k];
            k++;
            j++;
        }
        substr[i][j]='\0';
        i++;
        if(morseCode[k]!='\0')
        {
            k++;
        }        
    }
    int len=i;
 for(i=0;i<len;i++)
 {
  for(j=0;j<25;j++)
  {
   if(!strcmp(alphamorse[j],substr[i]))//strcmp returns 0 if they are same
   {
    printf("%c",(j+65));
    break;
   }
  }
  for(j=0;j<9;j++)
  {
   if(!strcmp(nummorse[j],substr[i]))
   {
    printf("%d",j);
    break;
   }
  }  
 }
 printf("\n");
}
Explanation:
The above can also be done using switch case but you need to write a total of 35 cases which is not a good practice.

//Coming Soon
Output:
Decryption of Morse Code Cipher in C


4 comments:

  1. How do I
    Encryption and decryption between users in morse using a flashlight

    ReplyDelete
  2. Bitcoin money is a cryptocurrency fork of Bitcoin exemplary. It was made in august 2017. It is significant that Bitcoin money builds the size of squares, which permits more exchanges to be prepared. bitcoin mixer

    ReplyDelete
  3. Hi, I'm trying this code, but it's not translating letter "Z" and I cannot figure out why...

    ReplyDelete
  4. Can you explain me this code?

    ReplyDelete

Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide