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

byd20

spiyekboboknsxqdrscsdsclomkecoiyecyvfondrozbylvowypdronkigrsmrgkcoxmynsxqecsxqkbyd20mszroblocebodydovvkvviyebpbsoxnckxnzycdsxdromywwoxdcrygiyemkwoezgsdrdrocyvedsyx

Permalink: http://problemotd.com/problem/byd20/

Comments:

  • Anonymous - 10 years, 4 months ago

    ifyouarereadingthisitisbecauseyousolvedtheproblemofthedaywhichwasencodingusingarot20cipherbesuretotellallyourfriendsandpostinthecommentshowyoucameupwiththesolution

    Hmm...i got rot 10 not 20 :)

    http://rumkin.com/tools/cipher/caesar.php

    reply permalink

  • James - 10 years, 4 months ago

    Based on the fact that almost all the characters in the encoded string are lowercase letters, I amused the encoding was some sort of 1 to 1 mapping for each letter of the alphabet. The simplest 1 to 1 mapping is a rotation cipher, so I attempted that first. Assuming the plaintext was written in English, I printed the frequency of each letter in the encoded string, and mapped the most frequent letter ('o') to the most frequent letter in English 'e' (which is rot16). Since I can read the output, I assume I've located the correct answer.

    #include <stdio.h>
    #include <string.h>
    
    char rotate_n( char c, int n )
    {
       while( n < 0 ) n += 26;
       while( n >= 26 ) n -= 26;
    
       if ( c >= 'A' && c <= 'Z' )
       {
          c = ( ( ( c - 'A' ) + n ) % 26 ) + 'A';
       }
       else if ( c >= 'a' && c <= 'z' )
       {
          c = ( ( ( c - 'a' ) + n ) % 26 ) + 'a';
       }
       return c;
    }
    
    void rotate_string_n(char * str, int n)
    {
       size_t const length = strlen( str );
       int i;
    
       for ( i = 0; i < length; i++ )
       {
          str[i] = rotate_n( str[i], n );
       }
    }
    
    void frequency( char const * str )
    {
       size_t const length = strlen( str );
       unsigned char freq['z'-'A'+1] = { 0 };
       int i;
    
       for ( i = 0; i < length; i++ )
       {
          if ( str[i] >= 'A' && str[i] <= 'z' )
          {
             freq[str[i]-'A']++;
          }
       }
    
       for ( i = 32; i <= 'z'-'A'; i++ )
       {
          printf( "%c : %d\n", i+'A', freq[i] );
       }
    
       printf( "\n" );
    }
    
    int main( void )
    {
       char encoded[] = "spiyekboboknsxqdrscsdsclomkecoiyecyvfondrozbyl"
                        "vowypdronkigrsmrgkcoxmynsxqecsxqkbyd20mszroblo"
                        "cebodydovvkvviyebpbsoxnckxnzycdsxdromywwoxdcry"
                        "giyemkwoezgsdrdrocyvedsyx";
    
    // frequency( encoded );
       rotate_string_n( encoded, -10 ); // == rot16.
    // frequency( encoded );
    
       printf( "%s\n", encoded );
       return 0;
    }
    

    reply permalink

Content curated by @MaxBurstein