Explore the question of why the code was used in the first place.
If the purpose of the code was to facilitate communication between two people who knew the same things (i.e. knew the code), then it will be hard for anyone to discover the code and break it unless they're in on the secret. You can look at the WWII stories regarding Enigma and Purple to see what stories arise from trying to break these.
In many books, the purpose of the code is to get the attention of the right person after the information has been lost. In these cases, you'll put the message out there in plain sight, but you'll choose an encoding which only the right minded person would think of. This often appears in treasure maps that are designed to lead you to the right place after you had forgotten the secret in the first place.
In both cases, the worldbuilding key to making it believable is culture. Develop the main character in a culture which would support him or her eventually discovering the secret. If it's a person-to-person code, a mathematical background or a detective background would make the discovery more believable. If it's an in-plain-sight code, a person who has been brought up to resonate with the culture that left the code is the key for believability.