?? 004 b.cpp
字號:
// 004 b.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream.h"
#include <string>
using namespace std;
//代換密碼加密
void C(char a[],int n)
{
string s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string s2 = "abcdefghijklmnopqrstuvwxyz";
string s3,k;
cout<<"請輸入大寫字母的密鑰:"<<endl;
char ch;
while((ch=cin.get())!='\n')
k+=ch;
cout<<"加密前明文為:";
for(int p=0;p<n;p++)
cout<<a[p];
cout<<endl;
cout<<"加密后密文為:";
for(int i=0;i<k.length();i++)
{
for(int j=0;j<26;j++)
{
if(k[i]==s1[j])
{
s3+=k[i];
s1.erase(j,1);
}
}
}
s3.append(s1);
for(int l=0;l<n;l++)
{
for(int h=0;h<26;h++)
if(a[l]==s2[h])
a[l]=s3[h];
cout<<a[l];
}
cout<<endl;
}
//代換密碼解密
void D(char a[],int n)
{
string s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string s2 = "abcdefghijklmnopqrstuvwxyz";
string s3,k;
cout<<"請輸入大寫字母的密鑰:"<<endl;
char ch;
while((ch=cin.get())!='\n')
k+=ch;
cout<<"解密前密文為:";
for(int p=0;p<n;p++)
cout<<a[p];
cout<<endl;
cout<<"解密后明文為:";
for(int i=0;i<k.length();i++)
{
for(int j=0;j<26;j++)
{
if(k[i]==s1[j])
{
s3+=k[i];
s1.erase(j,1);
}
}
}
s3.append(s1);
for(int l=0;l<n;l++)
{
for(int h=0;h<26;h++)
if(a[l]==s3[h])
a[l]=s2[h];
cout<<a[l];
}
cout<<endl;
}
void main()
{
int sign=1;
int m;
while(sign==1)
{
cout<<"代換密碼加密----1,代換密碼解密----2,退出----0 :"<<endl;
cin>>m;
char s[100];
switch(m)
{
case 0: sign=0;
break;
case 1: cout<<"請輸入要加密的小寫字母字符串:"<<endl;
cin>>s;
cin.get();
C(s,strlen(s));
break;
case 2: cout<<"請輸入要加密的大寫字母字符串:"<<endl;
cin>>s;
cin.get();
D(s,strlen(s));
break;
default: cout<<"Input error!"<<endl;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -