Problem of the Day
A new programming or logic puzzle every Mon-Fri

Et tu, Brute?

WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU

Permalink: http://problemotd.com/problem/et-tu-brute/

Comments:

  • pegleg - 10 years, 8 months ago

    TODAYSPROBLEMOFTHEDAYISTOCREATEACAESARCIPHERENCRYPTERANDDECRYPTER

    reply permalink

  • pegleg - 10 years, 8 months ago

    You should really let me delete my comments :-X Don't mean to ruin it

    reply permalink

  • Max Burstein - 10 years, 8 months ago

    No worries at all. Once someone posts a comment the comments become hidden by default so as not to ruin it for anyone else. Nice job on solving it and creating a decoder!

    reply permalink

  • Pegleg - 10 years, 8 months ago

    Python 3.4

    def decode(msg, number):
        temp = []
        for i in msg:
            finalnum = ord(i) + number
            if finalnum > ord('Z'):
                finalnum -=26
            elif finalnum < ord('A'):
                finalnum +=26
            temp.append(chr(finalnum))
        return ''.join(temp)
    message = input('Type message to encrypt/Decrypt')
    while True:
        number = input('Type number to shift by, n to close')
        if(number.lower() != 'n'):
            print(decode(message,int(number)))
        else:
            print('Laterz')
            break;
    

    reply permalink

  • Kevin Benton - 10 years, 8 months ago

    import string
    cipher = 'WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU'
    
    for shift in range(0,25):
       attempt = cipher
       for idx, letter in enumerate(string.uppercase):
           pointer = (idx+shift) % (len(string.uppercase))
           attempt = attempt.replace(letter, string.uppercase[pointer].lower())
       print attempt
    

    reply permalink

  • Daniel - 10 years, 8 months ago

    My C# solution

    Outputs all permutations for this Caesar cipher.

    Today's answer is: TODAYSPROBLEMOFTHEDAYISTOCREATEACAESARCIPHERENCRYPTERANDDECRYPTER

       static void Main(string[] args)
        {
            string strString = "WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU";
            string[] aryLetters = new string[26] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
            int i = 0;
            int offset;
            string strOutput;
            while (i <= 25)
            {
                strOutput = "";
                foreach (char c in strString)
                {
                    offset = i + Array.IndexOf(aryLetters, c.ToString());
                    offset = (offset <= 25 ? offset : (offset % 25) - 1);
                    strOutput += aryLetters[offset];
                }
                Console.WriteLine(strOutput);
                Console.WriteLine();
                i++;
            }
            Console.ReadKey();
        }
    

    reply permalink

  • Anonymous - 10 years, 8 months ago

    Another one in J.

    alphabet=: 26 {. (a. i. 'A') }. a.
    
    encrypt=: (alphabet i. ]) {"1 alphabet |."0 1~ [
    decrypt=: alphabet {~ ] i."1~ alphabet |."0 1~ [
    
    NB. Encrypt and decrypt:
    3 encrypt 'TODAYSPROBLEMOFTHEDAYISTOCREATEACAESARCIPHERENCRYPTERANDDECRYPTER'
    3 decrypt 'WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU'
    
    NB. Generate all 26 possibilities:
    (i. 26) decrypt 'WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU'
    

    reply permalink

  • Anonymous - 10 years, 8 months ago

    python 2.7 ``` string = 'WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU'

    top = ord('Z') full_shift = top - ord('A') + 1

    for i in xrange(1, full_shift): new_string = '' for l in string: dec = ord(l) + i if dec > top: dec -= full_shift new_string += chr(dec) print "index {}: {}".format(i, new_string) ```

    reply permalink

  • Anonymous - 10 years, 8 months ago

    whoops! Fixed the formatting... python 2.7

    string = 'WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU'
    
    top = ord('Z')
    full_shift = top - ord('A') + 1
    
    for i in xrange(1, full_shift):
      new_string = ''
      for l in string:
        dec = ord(l) + i
        if dec > top:
          dec -= full_shift
        new_string += chr(dec)
      print "index {}: {}".format(i, new_string)
    

    reply permalink

  • Jt - 10 years, 8 months ago

    My first attempt at Python. Not as pretty as the already submitted answers. I tried to add a little bit, by checking to see if the answer contained words in the dictionary. Unfortunately, I ran out of time and had to cheat a bit. Given more time I should check all permutations of the encrypted string to make sure that words can be made all the way across. This will only work if the decrypted string starts with a 4 letter word or greater.

    import enchant
    import random
    
    def DecryptString(encyptedStr):
      possibleSolutions = []
    
      offset = 0
      while offset <= 25:
        decryptedStr = ""
        for char in encyptedStr:
          charIndex = charList.index(char)
          charIndex = charIndex - offset
          if charIndex < 0:
            charIndex = charIndex + 26
          decryptedStr = decryptedStr + charList[charIndex]
    
        if ContainsAWord(decryptedStr):
          possibleSolutions.append(decryptedStr)
        offset = offset + 1
      return possibleSolutions
    
    def EncryptString(str, offset):
      encryptedStr = ""
      for char in str:
        charIndex = charList.index(char)
        charIndex = charIndex + offset
        if charIndex > 25:
          charIndex = charIndex - 26
    
        encryptedStr = encryptedStr + charList[charIndex]   
    
      return encryptedStr
    
    def ContainsAWord(str):
      dict = enchant.Dict("en_US")
      index = 4
      while index <= len(str):
        if dict.check(str[:index]):
          return True
        index = index + 1
      return False
    
    charList = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
    encryptedString = "WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU"
    
    print("Possible Decrypted Strings")
    for decryptedString in DecryptString(encryptedString):
      print(decryptedString)
    
    print()
    print("Randomly Encrypted String")
    randomlyEncryptedString = EncryptString(decryptedString, random.randint(1,26))
    print(randomlyEncryptedString)
    
    print()
    print("Possible Decrypted Strings")
    for decryptedString in DecryptString(randomlyEncryptedString):
      print(decryptedString)
    
    

    reply permalink

  • Jt - 10 years, 8 months ago

    I shouldn't say it only works with 4. You can lower the litmus (index) to 1, you'll just get some false positives. Apparently, "Z" is a word... The more you know.

    reply permalink

  • Hueho - 10 years, 8 months ago

    MESSAGE = "WRGDBVSUREOHPRIWKHGDBLVWRFUHDWHDFDHVDUFLSKHUHQFUBSWHUDQGGHFUBSWHU"
    
    def rot_num(num, n, range)
      wrap = num % range.begin
      range.begin + (n + wrap) % range.size
    end
    
    ALPHA = ('A'.ord)..('Z'.ord)
    
    # In-place
    def rot!(n, char_array)
      char_array.map! do |ch|
        rot_num(ch.ord, n, ALPHA).chr
      end
    end
    
    def cipher(shifts, message)
      rot!(shifts, message.chars).join
    end
    
    def decipher(shifts, message)
      cipher(shifts, message)
    end
    
    def brute_force
      char_array = MESSAGE.chars
      ALPHA.size.times do
        puts rot!(1, char_array).join
      end
    end
    
    brute_force
    

    reply permalink

Content curated by @MaxBurstein