Two-Way Cipher

September 20, 2016

A recent post at Reddit asked for a way to encrypt two plaintexts to the same ciphertext; the application was in geocaching, where a series of caches leads to two different locations depending on the decoded message. That’s an interesting question, and the responses there got it wrong. Fortunately, the poster also asked at the crypto reddit, and the people there were more helpful.

Your task is to write a program that decrypts two different plaintexts from the same ciphertext, given two different keys. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution in the comments below.

Advertisement

Pages: 1 2

2 Responses to “Two-Way Cipher”

  1. Graham said

    Just leaving a comment would be poor form; here’s my Haskell solution.

    module Main where
    import Data.Char (chr, ord)
    sub x y = chr $ 65 + (x' - y') `mod` 26
      where
        x' = ord x - 65
        y' = ord y - 65
    crypt = zipWith sub
    cipher = "ABCDEFGHIJK"
    key1 = crypt cipher "PROGRAMMING"
    key2 = crypt cipher "PRAXISXXXXX"
    main = do
      print cipher
      mapM_ (print . crypt cipher) [key1, key2]
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: