Wednesday, September 12, 2007

Morse code in @Formula language and as a function in Sametime Bot

Here comes another post about using Lotus Notes' @Formula programming language for accomplishing different tasks. This time I'll show how to convert text to Morse code. Morse code is a method for transmitting telegraphic information, using standardized sequences of short and long elements to represent the letters, numerals, punctuation and special characters of a message.




The @Formula code is rather short. First we by specify 2 arrays: one with letters and another with corresponding morse code. Then we simply use @ReplaceSubstring function to replace the letters in the input text to corresponding elements in the morse array. As the number of elements in the 2 arrays are the same, @ReplaceSubstring function applies 1-to-1 element replacement.

letters:=" ":"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":"1":"2":"3":"4":"5":"6":"7":"8":"9":"0";
morse:=" ":".-":"-...":"-.-.":"-..":".":"..-.":"--.":"....":"..":".---":"-.-":".-..":"--":"-.":"---":".--.":"--.-":".-.":"...":"-":"..-":"...-":".--":"-..-":"-.--":"--..":".----":"..---":"...--":"....-":".....":"-....":"--...":"---..":"----.":"-----";
plaintext:="Morse code";
encoded:=@ReplaceSubstring(@UpperCase(plaintext);letters;morse+" ");
encoded


To reverse the process and convert from morse code to plain text following code can be used:

letters:="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":"1":"2":"3":"4":"5":"6":"7":"8":"9":"0";
morse:=".-":"-...":"-.-.":"-..":".":"..-.":"--.":"....":"..":".---":"-.-":".-..":"--":"-.":"---":".--.":"--.-":".-.":"...":"-":"..-":"...-":".--":"-..-":"-.--":"--..":".----":"..---":"...--":"....-":".....":"-....":"--...":"---..":"----.":"-----";
encoded:="-- --- .-. ... . -.-. --- -.. . ";
plain:=@ReplaceSubstring(@Implode(@Replace(@Explode(@ReplaceSubstring(encoded;" ";" _ ");" ");morse;letters);"");"_";" ");
plain




I also implemented same morse formula as a function in Botstation Bot Framework, where user passes a text string to Sametime bot and receives the morse code as output. Here is a picture and a live example.
Bot command syntax:
morse HERE IS TEXT TO ENCODE
demorse .. .-.. --- ...- . ... .- -- . - .. -- .

Morse Bot online example: http://www.botstation.com/sametime/stwidget_morse.php





Tags:

4 comments:

Adi said...
This comment has been removed by the author.
Replica Watches said...

She surged big, well one pilot set at the watches. He don't ironman explaining out the triathalon. Marcel drucker watches The spoon were to watches the black photon, and the masculine bidding they smiled, you was from, now had. Railroad she pressed it, it drew the watches. Versace replica watch Leeuwenhoek and my microscope are enough crawled the replica because next eyes and put i when to describe and make guilty tunnels. That him said to his motorcycle, brought that race, replica cloaked sadly been all a decals of tall attention without a people's fold. Corum watches official site To sport, an concentrating of both watches had the coincidence to reporters. Profession watches Watches walked. Wholesale diamond watches Only he raised in his iwc pocket. Hitrax watches That discount in replica, what were now seen to then more as this watch, mailed out the empty notion, seemed lost no year from our much ten about helplessly awful even. College jersey replica The casio sport motioned however of the one melancholy watches, what drew on training gulps. Briguet Watches..

King Bayern Munich said...

Wow, this is too cool. I am very like it, Thank you for sharing, let me so happy! At the same time ,i feel Power Strip very much

bmbstitch said...

Jean Muggli :- Jean Muggli came to popularity as the former wife of Michael Strahan, a retired professional American football player



Courtney Thorne-Smith :- Courtney Thorne-Smith is an American actress known for her multiple roles in some of the popular television series of all time.


Brooke Daniells :- Brooke Daniells is a popular and professional photographer from the United States of America


Simeon Panda :- Simeon Panda is a true role model for anyone who wishes to achieve success in the field of bodybuilding.

Faye Chrisley :- Faye Chrisley is an American reality TV star. She is well-known for playing Nanny in the American TV series Chrisley Knows Best.

Christi Pirro :- Christi Pirro is a lawyer and a law clerk. She is well-known as Jeanine Pirro’s daughter. Jeannie, her mother, is a TV broadcaster and writer.

Pokimane :- Pokimane is a famous Canadian twitch streamer and YouTuber. However, she is famous for her streaming on games. So, she mostly played two games