On page 14 you learned how to encode messages by sorting a collection of arbitrary things. Music is made of melodies which are collections of notes. Why not compose a song to encode a text in the melody?
All you need to define is the set of notes you want to use in the song. As there are
Let's start with a simple example. There are 12 notes per scale, two scales have 24 note, that will be enough for "hello world". The message text is treated as a
I decided to allow 42 different characters: a-z 0-9 .:() and space. Using this alphabet, the numeric representation of "hello world" calculates like that:
h = 7 w = 22 e = 4 o = 14 l = 11 r = 17 l = 11 l = 11 o = 14 d = 3 ------------------------ 7 * (42^10) h + 4 * (42^9) e + 11 * (42^8) l + 11 * (42^7) l + 14 * (42^6) o + 36 * (42^5) [space] + 22 * (42^4) w + 14 * (42^3) o + 17 * (42^2) r + 11 * (42^1) l + 3 * (42^0) d ------------------------ = 121297199112622725
This number can be fed into the algorithm explained earlier, with a chromatic scale being the carrier list. (Reminder for non-musicians: C C# D D# E F F# G G# A H B c c# d d# e f f# g g# a h b.)
The result looks like that:
Less Letters, more Words
The maximum numeric message (and therefore the length of the text message) is limited by
7 * (27^10) h + 22 * (27^4) w + 4 * (27^9) e + 14 * (27^3) o + 11 * (27^8) l + 17 * (27^2) r + 11 * (27^7) l + 11 * (27^1) l + 14 * (27^6) o + 3 * (27^0) d + 36 * (27^5) [space] --------------------------------------------------- = 1474967912327400
Rhythm - Just for FunA melody of plain quarter notes may sound boring. But once the notes are sorted, you can insert duplicates wherever you like. All repetitions will be removed before decoding. As time is not important (yet, in this prototype), you can split quarters into quavers at random. Nothing of that will affect the encoded message. Here are a few versions of "coding in c sharp" (which is number 201255931456816565832252 with an alphabet of 27 characters).
The Demo Application
The demo lets you encode text as music in four steps:
Of course, you can also decode a melody back to text:
The application was written for a presentation, that's why there are a few hidden features that don't disturb the listeners with visible buttons or menus.
Some geeks asked me what is the textual meaning of
To save the content of a TextBox for later use, focus the box and press Ctrl+Y. The text will be appended to clipboard.txt in the executable's directory.
Save the Picture
The application displays the result as note names and drawn notes synchronously. But as only the note names can be enterd and decoded again, only those can be copied to the clipboard. Anyway, there's a way to grab the picture: Left click the PictureBox. The notes will be saved to a PNG file in the executable's directory.
Save the Sound
The melody beeped by the "Play"-Button can also be saved: Right click the PictureBox. The sound will be saved to a WAV file in the executable's directory.
Workaround for mono/Linux
With some combinations of mono versions and audio drivers
Instead of beeping, the application will then save the sound to a temporary file and have sox play it. There should be no visible/audible difference to the usual behaviour.
The demo application shows only the basic idea. Maybe I'll enhance it to split long messages into several melody parts, ensure a certain tonality, add harmonies to a given melody instead of generating a random one and so on. There are no limits for composers to add secret content to their songs.