How is the Output script formed? I read about Input and output scripts on the wiki here:

https://en.bitcoin.it/wiki/Transactions

Let's say, I use my Bitcoin - QT Program, I go to "Send Coins" tab, enter a Bitcoin Address, BTC amount and then click Send.

Is the output script generated by my program?

For an output script, we need the Value, The destination Address and the scriptPubKey. My client program has all this data.

scriptPubKey refers to Public Key of? My public key or the person I intend to send the Bitcoins to?

So, now, once the output script is formed, is it broadcast over the Bitcoin Network?

Where does the Input Script come from?

the scriptSig in Input Script refers to the Public Key and Signature of whom?

When I am sending Bitcoins to a Bitcoin Address, the input Script is automatically generated by what?

Even though the wiki gives details about Input Script and output Script, I was unable to correlate it to a real time scenario where one person sends BTC to another.
Is the output script generated by my program?


Yes.


  scriptPubKey refers to Public Key of? 


Whoever you're sending the bitcoins to. 


  So, now, once the output script is formed, is it broadcast over the Bitcoin Network?


After it's signed, yes.


  Where does the Input Script come from?


It is composed of two pieces - your public key, and a valid signature corresponding to that public key. So, you make it.


  the scriptSig in Input Script refers to the Public Key and Signature of whom?


You.


  When I am sending Bitcoins to a Bitcoin Address, the input Script is automatically generated by what?


Your client, after looking at your wallet.


  Even though the wiki gives details about Input Script and output Script, I was unable to correlate it to a real time scenario where one person sends BTC to another.


There are two parts to a bitcoin transaction - the part where you prove that you own some bitcoins, and the part where you designate someone else to be able to prove they own some bitcoins.


  So, the Public Key in scriptPubKey differs from the Public Key in scriptSig?


scriptPubKey is very poorly named, because when you're sending bitcoins to an address, you only know the 160-bit hash of the public key. A scriptPubKey looks like this:

OP_DUP OP_HASH160 06f1b670791f9256bffc898f474271c22f4bb949 OP_EQUALVERIFY OP_CHECKSIG


The 06f1b6... is how your client specifies who it's sending to. The parts around it are scripts that tell the bitcoin client how to validate the transaction.


  Also, we only have the Bitcoin Address of the person we intend to send the Bitcoins to. How do we get the Public Key of the recipient?


We don't need to. We can tell the network the 160 bit hash, and the person you're sending to can show the public key to the network when they want to spend their bitcoins.