Ejemplo n.º 1
0
void decodeFile (FileContainer files, char * msgName) {
	int currentInt;
	char currentChar;

	FILE* msgFile = fopen(msgName, "r");

	if (files.msgCount == 0 || files.keyCount == 0) {
		printMessage(TYPE_ERROR, ERROR_UNKNOWN);
	} else {
		if (fileExists(decryptedFileName) == 1) {
			remove(decryptedFileName);
		}
		
		while (!feof(msgFile) && fscanf(msgFile, "%c", &currentChar) == 1) {
			if (currentChar == '[') {
				fscanf(msgFile, "%d", &currentInt);
				currentChar = findCharRepresentation(files, currentInt);
				writeCharToFile(currentChar, decryptedFileName);
			} else if (currentChar != ']') {
				writeCharToFile(currentChar, decryptedFileName);
			}
		}
	}
	free(files.msg);
	free(files.key);
	fclose(msgFile);
}
Ejemplo n.º 2
0
void encodeFile (FileContainer files, char * msgName, int d) {

	IndexHolder iHolder;
	FILE* msgFile = fopen(msgName, "r");

	files.msgCount = getSize(msgName);
	files.msg = malloc(files.msgCount * sizeof(int));

	if (files.msgCount == 0 || files.keyCount == 0) {
		printMessage(TYPE_ERROR, ERROR_UNKNOWN);
		exit(0);
	} else {
		if (fileExists(encryptedFileName) == 1) {
			remove(encryptedFileName);
		}
		
		iHolder.lastIndex = 30000; // High number so first distance is OK
		
		while (!feof(msgFile) && fscanf(msgFile, "%c", &iHolder.currentChar) == 1) {
			iHolder.currentIndex = findIntRepresentation(files, iHolder, d);
			
			if (iHolder.currentIndex != 0) {
				writeIntToFile(iHolder.currentIndex, encryptedFileName);
			} else {
				writeCharToFile(iHolder.currentChar, encryptedFileName);
			}
			iHolder.lastIndex = iHolder.currentIndex;
		}
	}
	free(files.msg);
	free(files.key);
	fclose(msgFile);
}
Ejemplo n.º 3
0
/**
* @brief	Deactivates the rules of the firewall, by writing '0' to the rules 'active' attribute.
*
* @return	TRUE for success, FALSE for failure.
*/
Bool deactivate(void)
{
	return writeCharToFile(RULES_ACTIVE_ATTR_PATH, '0');
}
Ejemplo n.º 4
0
/**
* @brief	Clears the log by writing a single character to the log 'clear' attribute file.
*
* @return	TRUE for success, FALSE for failure.
*/
Bool clearLog(void)
{
	return writeCharToFile(LOG_CLEAR_ATTR_PATH, 'a');
}