Upstart logoUpstart
CodingFree preview

Substitution Cipher Decoding

Infer two substitution mappings from plaintext/ciphertext pairs and reverse the two encryption stages on a final message.

SWE
string
hashmap
Frequency
Medium
Last asked
2026-08-11
Stage
oa

Requirements

  • Input: clearMsgAb, cipheredMsgAb, clearMsgBc, cipheredMsgBc, and cipheredMsgCba.
  • Infer the Alice/Bob and Bob/Carol substitution mappings from the first four strings.
  • Decode the final string using the Bob/Carol mapping first and the Alice/Bob mapping second.
  • Return the original cleartext.
  • The senior-assessment variant says to ignore whitespace.

Notes

Character-set and whitespace treatment are not preserved in every version; clarify those rules rather than assuming the senior variant applies universally.

Build a decoding table from each ciphertext/plaintext pair, mapping cipher characters back to clear characters. Apply the Bob/Carol inverse first, then the Alice/Bob inverse. Check repeated observations for consistency and clarify what happens if a character has no known mapping; do not silently guess it. Apply the agreed whitespace rule before aligning training pairs. With total training length T and final message length M, table construction and decoding take expected O(T + M) time and O(A + M) space including the output, where A is the number of mapped characters. This uses the standard substitution-table pattern, but the two-stage composition and paired training strings are essential here.

Preparation

  • In 15 minutes, implement both inverse tables and verify that decoding reverses encryption on a small alphabet you choose for practice.
  • In 10 minutes, trace an inconsistent pair, an unmapped character, and both whitespace conventions; write down which require clarification instead of inventing output.
Was this article helpful?

Comments

Sign in to join the discussion
Loading...