base64decoder.cpp

来自「用于base64的解密 将一个包含base64的文件内容取出以后进行解密放到指」· C++ 代码 · 共 75 行

CPP
75
字号
#include <iostream>
using std::cout;
using std::cin;
using std::cerr;
using std::endl;
using std::ios;

#include <fstream>
using std::ofstream;
using std::ifstream;

#include <cstdlib>

#include <string.h>
#include "base64decoder.h"

int main()
{
	//array to allocate the space for the file name
	const int size = 100;
	char source[size];
	char target[size];

	cout<<"Enter the name of the file"<<endl;
	cout<<"The first one is the name of the source file"<<endl;
	cin.getline(source,size);
	
	cout<<"and the second one is the name of the target file: "<<endl;
	cin.getline(target,size);

	cout<<source<<endl<<target<<endl;

	ifstream sourceFile(source, ios::in);
	if( !sourceFile )
	{
		cerr<<"source file could not be open!"<<endl;
		exit(1);
	}

	ofstream targetFile(target,ios::out);
	if( !targetFile )
	{
		cerr<<"target file could not be open!"<<endl;
		exit(2);
	}

	sourceFile.seekg(0,ios::end);
    int len = sourceFile.tellg();
	cout<<len<<endl;

	char *copy=new char[len];

	sourceFile.seekg(0);
	sourceFile.read(reinterpret_cast< char * >(copy),len);
	int i;
	for(i = 0; i < len; i++)
	cout<<copy[i];
	cout<<endl;

	//while(sourceFile && !sourceFile.eof())
	char* pszSrc = new char[len];
	int len_src = Base64Decode(pszSrc, copy);
	printf("[源文]:\r\n%s\r\n\r\n", pszSrc);
	cout<<endl<<len_src<<endl;

	targetFile.write(reinterpret_cast< const char *>(pszSrc),len_src);

	for(i = 0; i < len_src; i++)
		cout<<pszSrc[i];


	cout<<endl<<"success!";

	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?