machan, there are number of methods to unlock and jailbreak iphone ios4.
http://www.redmondpie.com/unlock-ios-4.0-iphone-3gs-with-ultrasn0w-0.92.1/
this is another tutorial to unlock using a tool called redsn0w, which is the method i followed.
http://www.youtube.com/watch?v=dLWLg-1T6dI