They can be sonar guided, or they can be wire guided. Before these technologies were developed, torpedoes were unguided.
Germany
They were not really codes. It was a communications system for torpedo guidance that was resistant to enemy jamming. Bits of signals were sent over different frequencies.
This depends on the type of torpedo, WWII torpedoes had An internal gyroscope which would be set before launch to a specific bearing. The rudder on the torpedo would turn until the desired heading was reached, then it would run straight until it either reached the end of its run or struck the target, these are commonly called straight run torpedoes because once they make the initial turn, the just go straight. Modern ADCAP torpedoes are much more complex and contain active and passive sonar sensors which will allow the torpedo to guide itself to a target.
Type 95 torpedo, aka Long Lance; best (and deadliest torpedo of WWII).
Torpedo - petroleum - was created in 1865.
Red Torpedo was created in 2009.
Threespot Torpedo was created in 1984.
Torpedo Service was created in 1870.
Torpedo Service ended in 1978.
Torpedo Sofia was created in 2006.
Silk Torpedo was created in 1974.
Spearfish torpedo was created in 1992.