[AutoIt]ASCII to Morse Code
#1
Code:
MorseCode("greysec is awesome")

Func MorseCode($Input, $Freq = 525, $Dur = 100)
    If Not StringIsAlNum(StringStripWS($Input, 8)) Then Exit
    Local $Array = StringSplit(StringLower($Input), "")
    Local $Morse = ""
    For $i = 1 to UBound($Array) - 1
        $Morse &= CharConvert($Array[$i])
    Next
    $Array = StringSplit($Morse, "")
    For $i = 1 to UBound($Array) - 1
        If $Array[$i] = "." Then
            Beep($Freq, $Dur)
        ElseIf $Array[$i] = "-" Then
            Beep($Freq, ($Dur * 3))
        Else
            Sleep($Dur)
        EndIf
        Sleep(25)
    Next
EndFunc

Func CharConvert($Char)
    Switch $Char
        Case " "
            Return "     "
        Case "a"
            Return ".- "
        Case "b"
            Return "... "
        Case "c"
            Return  "-.-. "
        Case "d"
            Return "-.. "
        Case "e"
            Return ". "
        Case "f"
            Return "..-. "
        Case "g"
            Return "--. "
        Case "h"
            Return ".... "
        Case "i"
            Return ".. "
        Case "j"
            Return ".--- "
        Case "k"
            Return "-.- "
        Case "l"
            Return ".-.. "
        Case "m"
            Return "-- "
        Case "n"
            Return "-. "
        Case "o"
            Return "--- "
        Case "p"
            Return ".--. "
        Case "q"
            Return "--.- "
        Case "r"
            Return ".-. "
        Case "s"
            Return "... "
        Case "t"
            Return "- "
        Case "u"
            Return "..- "
        Case "v"
            Return "...- "
        Case "w"
            Return ".-- "
        Case "x"
            Return "-..- "
        Case "y"
            Return "-.-- "
        Case "z"
            Return "--.. "
        Case "0"
            Return "----- "
        Case "1"
            Return ".---- "
        Case "2"
            Return "..--- "
        Case "3"
            Return "...-- "
        Case "4"
            Return "....- "
        Case "5"
            Return "..... "
        Case "6"
            Return "-.... "
        Case "7"
            Return "--... "
        Case "8"
            Return "---.. "
        Case "9"
            Return "----. "
    EndSwitch
EndFunc

A fun script today, nothing really useful obviously but great to kill a little time Smile
Reply
#2
I would suggest not including the space in your morse definitions and adding the space in your output you re also missing the conversions for certain special characters which now have definitions but any who nice work!
Reply
#3
(01-13-2016, 09:39 AM)NO-OP Wrote: I would suggest not including the space in your morse definitions and adding the space in your output you re also missing the conversions for certain special characters which now have definitions but any who nice work!

the spaces in the definitions is basically a "sleep" between characters and/or words but didn't realize that I missed some characters (the special ones you mentioned, assume they are punctuation?) have to look into it and map them as well! Thanks for the feedback though Smile
Reply
#4
(01-13-2016, 09:58 AM)b1nary Wrote:
(01-13-2016, 09:39 AM)NO-OP Wrote: I would suggest not including the space in your morse definitions and adding the space in your output you re also missing the conversions for certain special characters which now have definitions but any who nice work!

the spaces in the definitions is basically a "sleep" between characters and/or words but didn't realize that I missed some characters (the special ones you mentioned, assume they are punctuation?) have to look into it and map them as well! Thanks for the feedback though Smile

They're these characters:
~ ! @ # $ % ^ & * ( ) - _ + = . ,
But I don't believe most of those have a Morse code translation.
Reply
#5
(01-25-2016, 08:31 PM)Cryptography Wrote: They're these characters:
~ ! @ # $ % ^ & * ( ) - _ + = . ,
But I don't believe most of those have a Morse code translation.

They do actually, after NO-OP made his post I looked into it, for example a question mark (?) is:

Code:
..--..

Wiki page you can check them, gotta scroll down just a bit but they are there Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why isn't the ASCII art behaving properly in this hangman game I invented? QMark 2 5,681 01-12-2022, 11:30 PM
Last Post: QMark
  how to code TCP in python? QMark 10 53,207 09-24-2018, 03:40 PM
Last Post: ekultek
  How to code in Python 3 [Ebook] Insider 0 12,290 02-03-2018, 04:58 PM
Last Post: Insider
  [AutoIt]Pseudorandom String Generator b1nary 1 12,204 03-13-2016, 01:54 PM
Last Post: Vector