- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道如何将加密的 ASCII 范围限制在 32 - 126 之间。
对于我们的任务,我们应该将字符串转换为字符并加密/解密每个单独的字符。
我目前正在使用它进行加密
int value = (value-32+shift)%95+32 //value is the current ascii value of a
//character
//the first shift is given by the user with regards
//to how many shifts he wants to do to the right
这个用于解密
int value = (value-32-shift)%95+32
我的加密工作正常(当我引用解密函数时)但我的解密没有按预期工作。
补充说明:我们只需要在编码的时候右移,就给了一个字符串给我们整个程序加解密(“This is C++”)
Give shift: 3
Wklv#lv#F..
DECODE
Wklv#lv#F.. //must be 'THIS is C++'
ENCODE //shift=15
This is C++ //must be 'cwx#/x#/R::'
DECODE
EYZdpZdp4{{ //must be 'THIS is C++'
ENCODE //shift=66
cwx#/x#/R:: //must be "8LMWbMWb'mm"
DECODE
This is C++
ENCODE //shift=94
cwx#/x#/R:: //must be 'SGHR~hr~B**'
DECODE
This is C++
注:正在添加更多代码说明
最佳答案
您的问题在 Modulo operator with negative values 中有解释.我不确定这是否完全相同。问题是解码像“!”这样的密码字符有一个以上的转变(比如“3”)
int value = (value-32-shift)%95+32
= ('!'-32-3)%95+32
= (33-32-3)%95+32
= (-2)%95 + 32
= -2 + 32
= 30
糟糕。您需要使用:
int value = (value-32+(95-shift))%95+32
关于c++ - 凯撒加密解密C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40150116/
我刚刚开始学习 C 语言类(class),并且遇到了命令行参数的问题。分配是这样的(还有更多,但这是开头有关命令行参数的部分): - 你的程序必须接受一个命令行参数,一个非负整数。 - 如果您的程序在
我需要检查命令行参数中是否有非数字字符。例如: ./problem 20x 应该打印出“不是数字”,因为它包含一个 x。我的代码似乎没有循环遍历命令行参数中的所有字符。 我基本上尝试了不同类型的循环,
这里我有从标准输入将字符流输入到数组中的代码。然后将该数组转换为二维数组。然后,它将该数组从行列顺序更改为列行顺序。然后它打印出创建凯撒移位加密的新数组。我遇到的问题是我的数组开始使用第二个用户输入的
我有点被这个问题困住了。当我运行程序时,由于某种原因,循环经过 z 的所有字母都不会打印。问题来自这个链接:http://docs.cs50.net/2016/x/ap/problems/caesar
我是一名优秀的程序员,十分优秀!