Created
March 19, 2012 03:10
-
-
Save mthelander/2092473 to your computer and use it in GitHub Desktop.
Morse code decoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Expects characters to be separated by a single space, with words separated by three spaces. | |
def morse_to_eng(morse) | |
t,r,n = [32,69,84,73,65,78,77,83,85,82,87,68,75,71,79,72,86,70,95,76,95,80,74,66,88,67,89,90,81,95,95],[],0 | |
morse.bytes do |b| | |
n = case b | |
when 46, 45 then 2 * n + 1 + (46 - b) | |
else r << t[n] unless n == 0 && r[-1] == 32; 0 | |
end | |
end | |
r.pack('c*') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment