What is the algorithm behind multisignature address? I know you can create a multisignature address with the command:

bitcoind createmultisig 2 ["pubkey1", "pubkey2", "pubkey3"]


As described here: https://gist.github.com/gavinandresen/3966071

This command returns the address (starting with character '3') and the redeem script.

My question: how to create that data without using bitcoind? What algorithms are used? I guess the address is just a hash of the redeem script, right? How could I generate the redeem script?

Could you point me to some sources?
OK, I found the answer I needed: https://bitcointalk.org/index.php?topic=317569