How to store a string/variable in a smart contract that is encoded and only the owner of that contract can call a function to decode it?

Let’s say we wanted to protect a string. Would it be possible to encode this and have a function in the smart contract that only the owner can use to decode it?

Depending on what you are trying to accomplish, you can just store a hash of the string on-chain, and then the owner can bring the full string to the blockchain later and the contract will check that the hash matches. Beware of front runners though! How To Get Front-Run on Ethereum mainnet - YouTube