- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作和扩展版本的 Caesar Cipher,包括用于 ASCII 值 32(这是一个空格)到 126(这是波浪号)的所有 7 位 ASCII 字符,但问题是我如何确保我的程序只使用那些 ASCII 字符,而不是跳转到使用奇怪的 DEL 符号或扩展的 ASCII 图表。
例如 - 如果我键入小写字母“u”并输入 10 作为键,我将得到 del 符号,但我想在键入小写字母“u”时得到一个空格
这是我目前的代码
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
string Encrypt(string, int);
int main(int argc, char *argv[])
{
string Source;
int Key;
cout << "Source: ";
getline(cin, Source);
cout << "Key: ";
cin >> Key;
cout << "Encrypted: " << Encrypt(Source, Key) << endl;
system("pause");
}
string Encrypt(string Source, int Key)
{
string Crypted = Source;
for (int Current = 0; Current < Source.length(); Current++)
Crypted[Current] += Key;
return Crypted;
}
最佳答案
简单:只需复制任何超出祝福范围的输入值而不做修改,你只需要两次比较:
if(x<' ' || x>126)
copy();
else
encode();
凯撒密码的算法是:
旁白:您可能还必须在应用前映射 key 。
关于c++ - 扩展凯撒密码 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23017981/
我刚刚开始学习 C 语言类(class),并且遇到了命令行参数的问题。分配是这样的(还有更多,但这是开头有关命令行参数的部分): - 你的程序必须接受一个命令行参数,一个非负整数。 - 如果您的程序在
我需要检查命令行参数中是否有非数字字符。例如: ./problem 20x 应该打印出“不是数字”,因为它包含一个 x。我的代码似乎没有循环遍历命令行参数中的所有字符。 我基本上尝试了不同类型的循环,
这里我有从标准输入将字符流输入到数组中的代码。然后将该数组转换为二维数组。然后,它将该数组从行列顺序更改为列行顺序。然后它打印出创建凯撒移位加密的新数组。我遇到的问题是我的数组开始使用第二个用户输入的
我有点被这个问题困住了。当我运行程序时,由于某种原因,循环经过 z 的所有字母都不会打印。问题来自这个链接:http://docs.cs50.net/2016/x/ap/problems/caesar
我是一名优秀的程序员,十分优秀!