This question evaluates the ability to reconstruct and compose bijective character-substitution mappings, testing competency in string manipulation, mapping inference, and basic cipher reasoning.
Three people pass notes A → B → C → A. Notes are encrypted using a character-substitution cipher (a one-to-one mapping per character).
You are given two known plaintext/ciphertext pairs that allow you to reconstruct the substitution keys:
clearMsgAb
and
cipheredMsgAb
clearMsgBc
and
cipheredMsgBc
A third message (intended to be decrypted by A) has been encrypted twice in this order:
cipheredMsgCba
To decrypt cipheredMsgCba, you must:
Implement a function that returns the final decrypted plaintext.
Inputs:
string clearMsgAb
string cipheredMsgAb
string clearMsgBc
string cipheredMsgBc
string cipheredMsgCba
Assumptions (for a well-formed input):
clearMsgAb.length == cipheredMsgAb.length
and
clearMsgBc.length == cipheredMsgBc.length
.
x
maps to
y
once, it always maps to
y
).
cipheredMsgCba
(so decryption is always possible).