Skip to content

Instantly share code, notes, and snippets.

@mthelander
Created March 19, 2012 03:10
Show Gist options
  • Save mthelander/2092473 to your computer and use it in GitHub Desktop.
Save mthelander/2092473 to your computer and use it in GitHub Desktop.
Morse code decoder
# 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