Espionage is a type of intelligence gathering that is employed by nations and corporations in order to gather information about the activities of their competitors and their enemies. Activities can range from inserting agents into the opponent's personnel structure to listening to their radio communications.
There is no nation that doesn't use espionage, but these activities are increased during times of war and conflict. The most important activity of an intelligence agency/operation is to determine the locations and targets of enemy military forces. Because of the uncertain nature of the intelligence gathering, it is not always a possibility to gain a full picture of the enemy's intentions and activities.
Countermeasures to enemy espionage include specialized couriers for delivering military orders (delivering them directly to the unit commanders) and computerized encryption of radio signals. Often, even with the use of encryption technology, code words are still used to further secure messages. These countermeasures are not fool proof, however. This is why changing codes and encryption keys is vital to maintaining security. Even the best mechanical/electronic methods can be cracked by a determined intelligence effort.
This was best displayed by the British and Americans cracking both the Nazi Enigma machine and the Japanese JN25 naval codes in WWII. Because of their belief that their systems were unbreakable, the Nazis never changed the main operating principles of their machines, making it easy for the British code crackers to recheck the system whenever a change was made in the operating procedures, as the Nazis almost never changed the basic mechanical design of the coding machines. With the creation of what can be called the first electronic computer -- the Colossus -- by Alan Turing, the Allies were often able to read German dispatches even before the German unit commanders. Operation Overlord owes much of its success to Operation Ultra encryption agents.
Encryption efforts also played a large part in the Battle of Midway with the breaking of the JN25 Naval code just before the battle. In this case, because of the heavy use of code words by the Japanese, the target was not initially certain to the decryption agents of the US Navy. By using a clever ruse, a blind request for fresh water, they were able to confirm the suspicion that the target was Midway Island.