?? code.cpp
字號:
#include "code.h"
#include <iostream>
#include <istream>
#include <string>
#include<fstream>
using namespace std;
code_uncode::code_uncode()
{
for(int i=0;i<95;i++)
for (int j=0;j<95;j++)
a[i][j]=(i+j)%95+32;
}
void code_uncode::code()
{ string p;
string q;
cout<<"請輸入明文:"<<endl;
cin>>source;
cout<<"請輸入密鑰:"<<endl;
cin>>key;
int m,n,h;
for (int i=0;i<source.length();i++)
{
m=source[i]-32;
n=i%(key.length());
h=key[n]-32;
p+=a[m][h];
}
cout<<"密文為:"<<p<<endl;
}
void code_uncode::uncode()
{
string p;
int m,n;
cout<<"請輸入密文:"<<endl;
cin>>keyword;
cout<<"\n請輸入密鑰:"<<endl;
cin>>key;
for(int i=0;i<keyword.length();i++)
{
m=i%key.length();
n=key[m]-32;
for(int j=0;j<95;j++)
{
if (a[j][n]==keyword[i])
{
p+=char(j+32);
break;
}
}
}
cout<<"明文為:"<<p<<endl;
}
void code_uncode::file_code()
{
char ch;
string q;
ifstream in("a.txt");
if(in)
{ in.get(ch);
while(in.good())
{
q+=ch;
in.get(ch);
}
in.close();
cout<<"請輸入密鑰:"<<endl;
cin>>key;
int m,n,h;
ofstream tfile("b.txt");
for (int i=0;i<q.length();i++)
{
m=q[i]-32;
n=i%(key.length());
h=key[n]-32;
tfile.put(a[m][h]);
}
tfile.close();
cout<<"文件加密成功!"<<endl;
}
else cout<<"文件不存在!"<<endl;
}
void code_uncode::file_uncode()
{
char ch;
string q;
int m,n;
ifstream in("b.txt");
if(in)
{ in.get(ch);
while(in.good())
{
q+=ch;
in.get(ch);
}
in.close();
cout<<"請輸入密鑰:"<<endl;
cin>>key;
ofstream tfile("c.txt");
for(int i=0;i<q.length();i++)
{
m=i%key.length();
n=key[m]-32;
for(int j=0;j<95;j++)
{
if (a[j][n]==q[i])
{
tfile.put(char(j+32));
break;
}
}
}
tfile.close();
cout<<"文件解密成功!"<<endl;
}
else cout<<"文件不存在!"<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -