Beispiel #1
0
//arguments to output to file(input file, output file, frequency data file)
//arguments to output to console(input file, frequency data file)
int main(int argc, char* argv[])
{  
	
	float given[26], found[26];

	int key; 

	if (argc != 4 && argc != 3)
	{
		printf ("Arguments to output to file: infile, outfile, data file\nArguments to output to console: infile, data file\n");
		exit(1);
	}

	//prints to console
	if(argc == 3)
	{
		readFreq(given, argv[2]);



		calcFreq(found, argv[1]);



		key = findKey(given, found);	



		decrypt(key, argv[1]);
	}
	else if (argc == 4) //prints to output file
	{
		readFreq(given, argv[3]);



		calcFreq(found, argv[1]);



		key = findKey(given, found);


		decryptToFile(key, argv[1], argv[2]);
	}



	return 0;
}
Beispiel #2
0
void Channel1::SweepUnit::event() {
	unsigned long const period = nr0_ >> 4 & 0x07;

	if (period) {
		unsigned const freq = calcFreq();

		if (!(freq & 2048) && (nr0_ & 0x07)) {
			shadow_ = freq;
			dutyUnit_.setFreq(freq, counter_);
			calcFreq();
		}

		counter_ += period << 14;
	} else
		counter_ += 8ul << 14;
}
Beispiel #3
0
// Main method for decoder.c
int main(int argc, char* argv[]){
  
	FILE *fin;
	FILE *fout;
	int option;
	int key;
	char ch;
	// Applies all spots to 0
	float given[26] = {0};
	float found[26] = {0};

	// Initial check for correct arguments, take from cipher.c
	if (argc != 5){
		printf ("Parameters: cipher option, key, input file, output file\n");
		printf ("Cipher option 1 : encryption\tCipher option 2 : decryption\n");
		exit(1);
	}

	// Assign integer values to key and selection of encryption/decription
	option = atoi(argv[1]);
	key = atoi(argv[2]);
	
	// This invokes decription when user prompts input option as 2
	if (option == 2){
	  // Process for decoding:
	  // 1.Read file 2.Calcuate frequencies given
	  // 3.Find the key for decoding and 4.Decode the file 
		readFreq(given, "LetFreq.txt");
		calcFreq(found, argv[3]);
		int key = findKey(given, found);
		decrypt(key, argv[3], argv[4]);
	}
	
	// This was made as a fail safe to using the makefile, it will
	// encrypt regardless of if it was before when the user wishes to do
	// such. Also this made developing much easier because I only needed
	// to run my file for it to execute the full encrypt/decrypt process
	else{
		// Main files to receive code to encrypt and file to send output to
		fin = fopen(argv[3], "r");
		fout = fopen(argv[4], "w");

		// Checks if files exist
		if (fin ==  NULL || fout == NULL){
			printf("File could not be opened\n");
			exit(1);
		}

		// Prints encrypted text to the output file defined above
		while (fscanf(fin, "%c", &ch) != EOF){
			fprintf(fout, "%c", encrypt(ch, key));
		}

		// Seal off files after being written to or read from
		fclose(fin);
		fclose(fout);
	}

	return 0;
}
Beispiel #4
0
int main (int argc, char* argv[]) {
	readFreq (letFreq, argv[1]);
	calcFreq (inputFreq, argv[2]);
	decrypt(findKey (letFreq, inputFreq), argv[2]);
	return 0;
}