Unfortunately, the floor is swarming with spies. Assume that Alice and Bob can't enter each other's rooms in this example, so they can only interact in the hallway. What they might do is agree on a common paint in the hallway – say, yellow. They get a tin of this yellow paint, divide it between themselves, and return to their respective rooms.
In their rooms, they'll mix in a secret paint – one that no one knows about. Alice uses a shade of blue, and Bob uses a shade of red. Crucially, the spies can't see these secret colors they're using. They will see the resulting mixtures, though, because Alice and Bob now exit their rooms with their blue-yellow and red-yellow concoctions.
They swap these mixtures out in the open. It doesn't matter if the spies see them now, because they won't be able to determine the precise shade of the colors added in. Remember that this is only an analogy – the real mathematics underpinning this system makes it even harder to guess the secret “color.”
Alice takes Bob's mix, Bob takes Alice's, and they return to their rooms again. Now, they blend their secret colors back in.
- Alice combines her secret shade of blue with Bob's red-yellow mix, giving a red-yellow-blue mix
- Bob combines his secret shades of red with Alice's blue-yellow mix, giving a blue-yellow-red mix
Both combinations have the same colors in them, so they should look identical. Alice and Bob have successfully created a unique color that adversaries are unaware of.
So, this is the principle we can use to create a shared secret in the open. The difference is that we're not dealing with hallways and paint, but insecure channels, public keys, and private keys.