64,633
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <stdio.h>
#include "colorcursor.h"
using namespace std;
void explain()
{
setcolor(15);
gotoxy(25,10);
cout << "欢迎使用文本转换程序,请先将待转";
gotoxy(21,11);
cout << "换的文本放在该程序所在目录下!\n";
setcolor();
}
void menu()
{
setcolor(10);
gotoxy(24,7);
cout << "***************菜单***************";
gotoxy(24,9);
cout << " 1: 编码 ";
gotoxy(24,11);
cout << " 2: 解码 ";
gotoxy(24,13);
cout << " 0: 退出 ";
gotoxy(24,15);
cout << "**********************************";
setcolor();
}
void main()
{
char select;
string name, ctrl;
char key[] = "liujian619";
unsigned char ch;
int i = 1;
ifstream infile;
ofstream outfile;
explain();
gotoxy(32,14);
cout << "按任意键继续...";
getch();
system("cls");
menu();
setcolor(15);
gotoxy(24,17);
cout << "输入你的选择:[ ]";
gotoxy(38,17);
select = getche();
while('0' != select && '1' != select && '2' != select)
{
setcolor(12);
gotoxy(20,19);
cout << "\a!!!错误: 输入不合法,请重新输入";
setcolor();
gotoxy(38,17);
select = getche();
}
system("cls");
if('0' == select)
{
return;
}
cout << "待转换文件的文件名:";
cin >> name;
if('2' == select)
{
cout << "输入解码密钥:";
int x = wherex();
int y = wherey();
setcolor(12);
cout << "\n【注意:解码密钥须与编码密钥相同,否则得不到原内容!!!】";
setcolor(15);
gotoxy(x,y);
cin >> key;
cout << "\n\n";
}
infile.open(name.c_str());
if(!infile)
{
cout<<"无法打开!\n";
exit(0);
}
outfile.open("文本转换.txt");
if(!outfile)
{
cout<<"无法打开!\n";
exit(0);
}
outfile << flush;
while(infile >> noskipws >> ch)
{
if('1' == select)
{
ch = ~(ch ^ key[(i%10)-1]);
}
if('2' == select)
{
ch = (~ch) ^ key[(i%10)-1];
}
outfile << ch;
i++;
}
infile.close();
outfile.close();
cout << "转换成功!!!\n";
remove(name.c_str()); //删除文件
rename("文本转换.txt",name.c_str()); //重命名文件
ctrl = "start " + name;
system(ctrl.c_str());
system("pause");
}