置换密码
#include <iostream>
#include<iomanip>
using namespace std;
#define N 6//密钥长度
int main()
{
string plaintext = "she sells seashells by the seashore";//明文
int secretKey[N] = { 3,5,1,6,4,2 };//密钥
cout << plaintext << endl;
string ciphertext = "";
string temp = "";
//加密
int count = 0;
for (int i = 0; i < plaintext.length(); i++)
{
if (plaintext[i] >= 'a' && plaintext[i] <= 'z')
{
temp += plaintext[i];
count++;
if (count == 6)
{
count = 0;
for (int j = 0; j < N; j++)
ciphertext += temp[secretKey[j]-1];
temp = "";
}
}
}
//加空格
for (int i = 0; i < plaintext.length(); i++)
{
if (plaintext[i] < 'a' || plaintext[i] > 'z')
{
ciphertext.insert(i, " ");
}
}
cout << endl;
cout << ciphertext << endl;
return 0;
}