All pastes #1217175 Raw Edit

myVig.cpp

public text v1 · immutable
#1217175 ·published 2008-10-02 19:05 UTC
rendered paste body
/* ========================================================================== */
/*                                                                            */
/*   Filename.c                                                               */
/*   (c) 2001 Author                                                          */
/*                                                                            */
/*   Description                                                              */
/*                                                                            */
/* ========================================================================== */

#include <iostream>
#include <string>

using namespace std;

int main() {
  string cipher;
  int len;
  double ic;
  cin >> cipher;
  
  len = cipher.size();

  return 0;
}

double index(string cipherText, int colSize, int offset){
  //Convert string to array of chars
  char cipherArray[cipherText.size()];
  strncpy(cipherArray, cipherText.c_str());

  // initialize variables
  int len = 0;
  double ic = 0;
  
  int holding[26] = getFreq(colSize, offset, cipherArray);
  for (int i = 0; i < 26; i++){
  
    ic = ic + holding[i]*(holding[i]-1);
    len = len + holding[i];
  
  }
  
  return ic/(len*(len-1));
}

static int[] getFreq( int keyLen, int offsetBy, char[] cipher){
  int sums[26];
  for (int i = offsetBy; i < sizeof(cipher); i+=keyLen){
    sums[cipher[i]]++;
  }
  
  return sums;
}