字母加密程序
alphabet encryption program
嗨,我正在开发一个加密程序。程序应该获取用户输入的字母,并将其替换为字母表中第 11 位的相应字母。例如,如果用户输入"joe",程序应该输出"uzp"。
我当前的代码做得很好,但它不能识别空格,程序应该环绕字母表。因此,"Y"变为"J","Z"将变为"K"等。有人知道我该如何解决这个问题吗?
void encrypt(std::string &e);
int main() {
string nameAttempt;
cout << "Enter your name to be Encrypted: ";
cin >> nameAttempt;
cout << "Original string is: " << nameAttempt << endl;
encrypt( nameAttempt );
cout << "Encrypted string is: " << nameAttempt << endl;
system("pause");
return 0;
}
void encrypt (std::string &e) {
const char* tempCharArray = e.c_str();
for( int i=0; i<e.size(); ++i )
e[i] = tempCharArray[i]+11;
} //
假设您要:
- 将小写字母
- 替换为小写字母 将大写字母
- 替换为大写字母
- 保留空格和任何其他非字母字符
void encrypt (std::string &e)
{
int size = e.size();
for (int i=0; i<size; i++)
{
char c = e[i];
if (('A' <= c && c <= 'Z'-11) || ('a' <= c && c <= 'z'-11))
e[i] = c+11;
else if ('Z'-11 < c && c <= 'Z')
e[i] = c+11-'Z'+'A';
else if ('z'-11 < c && c <= 'z')
e[i] = c+11-'z'+'a';
}
}
你可以做这样的事情:
char _character='X';
int _value=static_cast<int>(_character);
if(_value!=32)//not space
{
int _newValue=((_value+11)%90);
(_newValue<65)?_newValue+=65:_newValue+=0;
char _newCharacter=static_cast<char>(_newValue);
}
相关文章:
- 将加密消息从 php 发送到 C++ 应用程序,然后使用 CryptoPP 进行解密
- 邮件加密程序崩溃
- 如何制作一个程序,它使用特定单词加密和解密消息?
- C++加密程序不起作用
- 用于加密和解密的C ++程序
- 使用Microsoft安全支持提供程序接口 (SSPI) 对消息进行加密和签名
- 在Linux中寻找正确的方式,将C 应用程序从C 应用程序编写加密文本到加密的GPG文件
- 使用Qt程序构建加密++时发生链接器错误
- 加密用户数据,而不会丢失安卓应用程序中的登录用户
- 转录密码加密程序崩溃
- C :如何在iOS中已经存在的MFC应用程序中的加密SQLITE数据库重复使用
- 不能在没有对象 c++ 加密程序的情况下调用成员函数
- 程序集asm x86加密/解密程序
- C++程序加密加密
- 简单加密程序集程序-写入内存位置时发生访问冲突
- C++ ASM x86 加密/解密程序
- 将用户信息保存到加密文件中的程序
- OpenSSL:我使用存储外部文件的RSA密钥加密和解密文件,但有时我的程序会崩溃
- 修改程序以加密大写和小写输入
- 无法使用 RSA-Sha256 进行签名.WatchData CSP 不是 CNG(加密 API:下一代)提供程序吗?