All pastes #2052719 Raw Edit

Mine

public cpp v1 · immutable
#2052719 ·published 2011-05-02 03:53 UTC
rendered paste body
#include <iostream>   using namespace std;#include "rabbit.h"#include <fstream>#include <iomanip>long int getFileSize(fstream& inFile){inFile.seekg(0L, ios::end);long int fs = inFile.tellg();inFile.seekg(0L, ios::beg);return fs;}void dump(unsigned char *buf, int size, ofstream& outFile){	int segSize = 16;	int position = 0;	while (position < size)	{	int lineLen = position + segSize <= size ?	segSize : size - position;	for (int i = 0; i < lineLen; i++)		outFile << " " << setfill('0') << setw(2)		<< hex << (int)buf[position + i];	for (int i = lineLen; i < segSize; i++)		outFile << "";		outFile << "";	for (int i = 0; i < lineLen; i++)	if (buf[position + i] >= 32 &&		buf[position + i] < 127)		outFile << buf[position + i];	else outFile << '.';		outFile << endl;		position += lineLen;	}}int main(int argc, char *argv[]){	fstream keyFile;	keyFile.open (argv[1], fstream::in | fstream::out);	if( !keyFile.is_open() ) {		cerr << "File could not be opened on load!" << endl;		return(1);   	}	rabbit_byte key[16];	keyFile.read( (char *)key, sizeof(key) );	keyFile.close();	rabbit_instance state;		rabbit_key_setup( &state, key, sizeof(key) );	const int bufSZ = 1024;	unsigned char inbuf[bufSZ];	unsigned char outbuf[bufSZ];	fstream inFile(argv[2], ios::binary | ios::in);	if (!inFile)	{		cout << argv[2] << " cannot open1" << endl;		return 1;	}	ofstream outFile(argv[3], ios::out | ios::binary);	if (!outFile)	{		cout << argv[3] << " cannot open" << endl;		return 1;	}	long int fileSize = getFileSize(inFile);	long int currentPos = 0;	int blockSZ = 0;	int blockSZoffSet = 0;	while (currentPos < fileSize)	{	if (currentPos + bufSZ <= fileSize)		blockSZ = bufSZ;	else blockSZ = fileSize - currentPos;	if(blockSZ%16 != 0) blockSZoffSet = 16 - blockSZ%16; 	else blockSZoffSet = 0;	inFile.read((char *)inbuf, blockSZ);	rabbit_cipher( &state, inbuf, outbuf, blockSZ+blockSZoffSet );	outFile.write((char *)outbuf, blockSZ);	currentPos += blockSZ;		}		outFile.flush();	outFile.close();	inFile.close();}