c++ - 包括 Vigenere Cipher 中的空格?
问题描述
我正在尝试创建一个对 Vigenere Cipher 进行解码/编码的程序。它适用于所有字母(AZ),但我不知道如何在密码中包含空格。
#include<bits/stdc++.h>
using namespace std;
string generateKey(string str, string key)
{
int x = str.size();
for (int i = 0; ; i++)
{
if (x == i)
i = 0;
if (key.size() == str.size())
break;
key.push_back(key[i]);
}
return key;
}
// This function returns the encrypted text
string cipherText(string str, string key)
{
string cipher_text;
for (int i = 0; i < str.size(); i++)
{
// converting in range 0-25
char x = (str[i] + key[i]) %27;
// convert into alphabets(ASCII)
x += 'A';
cout << cipher_text << endl;
cipher_text.push_back(x);
}
return cipher_text;
}
解决方案
推荐阅读
- python - 在 Python 中解析包含“\u 作为 UTF-8 字节”的 JSON
- python - 如何使用正则表达式提取引号内的值?
- machine-learning - 使用什么类型的神经网络来区分真假图像?
- python - 未找到“”的反向。'' 不是有效的视图函数或模式名称 - Django App
- c# - 等待加载网页,直到找到元素
- node.js - 使用 Node.js 设置获取内部服务器错误 (500) 以使用 HTTPS
- vaadin - vaadin 应用程序的路径上下文是什么
- sql - 商店问题的数据库设计:存储可变价格
- git - 根据 git repo 设置名称和电子邮件设置?
- laravel - 如何在 Laravel 中创建用户?