A method and system for emulating a secret code between a first hardware
module to a second hardware module. First, the secret code that is
initially stored in the first hardware module is transformed into a
transformed secret code according to a transformation pattern randomly
selected from a set of possible transformation patterns. Then the
transformed secret code is transferred to the second hardware module.
Next, the second hardware module can repeatedly guess a hypothetical
secret code from the transformed secret code by using a transformation
pattern selected from the possible transformation patterns and reversing
the effect of the selected transformation pattern on the transformed
secret code. In addition, the hypothetical secret code is used to encode a
test sample, and the encoded test sample is sent back to the first
hardware module. Accordingly, the first hardware module can verify the
validity of the current hypothetical secret code by checking the encoded
test sample. After proving that a current hypothetical secret code is the
same as the true secret code, the first hardware module informs the second
hardware module of such a match result and stops the process.