All pastes #1217176 Raw Edit

myVig.cpp

public text v1 · immutable
#1217176 ·published 2008-10-02 19:06 UTC
rendered paste body
/* ========================================================================== */
/*                                                                            */
/*   myVig.cpp                                                                */
/*   Brian Marsh                                                              */
/*                                                                            */
/*   Basic C++ program that is used for dealing with Vigenere ciphers         */
/*                                                                            */
/* ========================================================================== */

#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;
}