/* Solution: A Coincidental Note */
/* E. Jason Riedy, ejr@cise.ufl.edu */
/*
  I'm hoping that simple non-numeric ones will be solved this year.  Last
  year, many of the very simple ones (like the one that required finding
  all the factors of a number) were passed over simply because they
  were overly numeric...

  This is nigh-trivial.

  BTW, Vigenere ciphers were considered difficult to break in the 1600s.
  Their status didn't really change until the late 20s...  Find Bruce
  Schneier's book Applied Cryptography if you're interested in both
  the history and science of cryptology...
*/

#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>

enum { MAX_LEN = 1000 };

void main(void)
{
  char ctext[MAX_LEN + 1];
  int shift, index;
  int i, len;

  /* Read the string, filtering out garbage and converting to lower case. */
  printf("Ciphertext: ");
  len = 0;
  while (len < MAX_LEN) {
    ctext[len] = getchar();
    if (isalpha(ctext[len])) {
      ctext[len] = tolower(ctext[len]);
      len++;
    }
    else if ('\n' == ctext[len]) {
      ctext[len] = '\000';
      break;
    }
  }

  printf("\nShift   Index\n");

  for (shift = 1; shift <= 10; shift++) {
    index = 0;
    for (i = 0; i < len; i++)
      if (ctext[i] == ctext[(i + shift) % len])
	index++;  /* Simply count the number of coincidences. */
    
    printf(" %2d     %.3f\n", shift, ((float)index)/((float)len));
  }
}

