Hiding Text In Text

Introduction

There are many ways to embed a message within some text. You can use the first letter of each word in your cipher text to represent characters from your message. That places constraints on the way you ocnstruct your cipher text. If the cipher text appears meaningless, you might guess that there is a secret message hidden there. With steganography, hiding the existence of the message is the name of the game.

Look at the following passage of text,

To be, or not to be,-that is the question:-
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune
Or to take arms against a sea of troubles,
And by opposing end them?-To die,-to sleep,-
No more; and by a sleep to say we end
The heartache, and the thousand natural shocks
That flesh is heir to,-'tis a consummation
Devoutly to be wish'd. To die,-to sleep;-
To sleep! perchance to dream:-ay, there's the rub;
For in that sleep of death what dreams may come,
When we have shuffled off this mortal coil,
Must give us pause: there's the respect
That makes calamity of so long life;
For who would bear the whips and scorns of time...

Pick out all of the letters written in bold and you have the following,

T H E S E C R E T I S O U T R U N A N D H I D E

Fine, so the message is easy to spot. How about now?

To be, or not to be,-that is the question:-
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune
Or to take arms against a sea of troubles,
And by opposing end them?-To die,-to sleep,-
No more; and by a sleep to say we end
The heartache, and the thousand natural shocks
That flesh is heir to,-'tis a consummation
Devoutly to be wish'd. To die,-to sleep;-
To sleep! perchance to dream:-ay, there's the rub;
For in that sleep of death what dreams may come,
When we have shuffled off this mortal coil,
Must give us pause: there's the respect
That makes calamity of so long life;
For who would bear the whips and scorns of time...

Not so easy the second time around. It's the same message. The font has been changed to a different typeface for the letters from the message. Assuming your computer has both Arial and Verdana, copy the text into a Word processor. Highlight the relevant characters and you will see that they are in Arial. The rest of the message, Verdana.

Programming

source_text ← "" // Set this to a fairly long string
embed ← "THESECRETISOUTRUNANDHIDE"
position ← 0
out ← ""
WHILE (embed.LENGTH > 0 AND position < source_text.LENGTH)
   WHILE (UPPERCASE(source_text(position))<> UPPERCASE(embed(0)))
      out ← out + source_text(position)
      position ← position + 1
   END WHILE
   CHANGE FORMAT
   out ← out + source_text(position)
   RESTORE FORMAT
   position ← position + 1
   embed ← embed.SUBSTRING(1)
END WHILE
out ← out + source_text.SUBSTRING(position)
OUTPUT out

The two lines in bold are open-ended. It depends entirely on the environment in which you are programming how you would do that. The 'hidden text' passages on this page are produced by PHP and write HTML/CSS instructions around the text. View the source HTML of this page and you can see what I mean. If you were using a control or widget in a different language, you'd probably need a different way of making the text change.

Challenges

This one is a good technique to implement as a VBA project and create something reusable. Javascript would also be highly suited to this technique.