FFTData FFTransformer::analyze(AudioData audioData)
{
    float *data = audioData.data;
    int dataLen = audioData.dataLen;
    int sampleRate = audioData.sampleRate;
    if(this->frequency != NULL)
        delete frequency;
    if(this->internalData != NULL)
        delete internalData;

    int internalCount = (int)pow(2, ceil(log2(dataLen)));
    internalCount *= 2;
    internalData = new float[internalCount];
    memset(internalData, 0, internalCount);
    for (int i=0; i < dataLen; i++)
        internalData[i*2] = data[i];

    resolution = ((float)sampleRate) / dataLen * audioData.numChannels;
    FFT(internalData, internalCount);
    countFrequency(internalData, internalCount);

    outputData.data = data;
    outputData.dataLen = dataLen;
    outputData.frequency = frequency;
    outputData.frequencyLen = frequencyLen;
    outputData.resolution = resolution;
    outputData.fundamentalFrequency = fundamentalFrequency;
    return outputData;
}
int main(void)
{
	char *str = "Rqfh pruh lqwr wkh euhdfk,ghdu iulhqgv,rqfh pruh;Ru forvh wkh zdoo xs zlwk rxu Hqjolvk ghdg.Lq shdfh wkhuh'v qrwklqj vr ehfrphv d pdq dv prghvw uwlooqhvv dqg kxplolwb:Exw zkhq wkh eodvw ri zdu eorzv lq rxu hduv,Wkhq lplwdwh wkh dfwlrq ri wkh wljhu;Vwliihq wkh vlqhzv,vxpprq xs wkh eorrg.";
	int frequency[26] = {0};   //存放频数

	//调用函数
	countFrequency(str,frequency);
}
int main(int argc, char **argv) {
	if (argc < 2) {
		printf("\nInput file needed. Exiting...\n");
		return 0;
	}

	FILE *input = fopen(argv[1], "r");
	char pt, c;
	int i = 0, numChars, shifts[3] = {0};
   	float charCount[26] = {0};
	table *alphabet = NULL;
	
	alphabet = readInFile(alphabet, "letterFrequencies.txt");
	
	numChars = countFrequency(input, charCount);
	computeFrequency(numChars, charCount);

	printf("\nFREQUENCY ANALYSIS ATTACK ON THE SHIFT CIPHER"
			"\n--------------------------------------");

	table *inputFrequencies = NULL;
	
	int a = 0;
	while (a < 26) {
		inputFrequencies = loadTable(inputFrequencies, a+97, charCount[a], 0);
		a++;
	}
	
	pickTopShifts(inputFrequencies, shifts);
	table *temp = inputFrequencies;

	printf("\nTESTING TOP 3 SHIFT POSSIBILITIES\n");
	for (i = 0; i < 3; i++) {
		rewind(input);
		printf("\nDecryption %d/3; Shift :%d\t", i+1, shifts[i]-4);
		while((c = getc(input)) != EOF){
			pt = decrypt(c, shifts[i]-4);
			putchar(pt);
		}
	}

	printf("\n");
	fclose(input);
	return 0;
}
bool isPermutationOfPallindrome1( const std::string & str )
{
    int frequency[ 26 ] = { 0 };
    countFrequency( str, frequency );

    /*
     * We will check here that letter frequencies are all even or all even except one odd.
     */
    bool oddAppeared = false;
    std::cout << std::endl;
    for ( int i = 0 ; i < 26; ++i ) {
        if ( frequency[i] % 2  && oddAppeared ) {
            return false;
        } else if ( frequency[i] % 2 && !oddAppeared ) {
            oddAppeared = true;
        }
    }
    return true;
}