- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我完全是 C++ 的初学者,到目前为止,在学校里我们只学习和使用过 Java。我们今年的第一个项目是创建一个凯撒密码,但我们必须使用我们教授提供的头文件。在这一点上,我只是试图在编码加密和解密方法之前移动字母并证明我的概念。关于我做错了什么以及为什么这段代码没有编译的任何帮助都会很棒。
这是我们的头文件,我们根本不允许对此文件进行任何更改:
// include file for Caesar cipher code
//
#ifndef CAESAR_H
#define CAESAR_H
#include <string>
class Caesar {
private:
//pointers used to refer to the standard alphabet array and the Caesar shift array
char* std_alphabet;
char* c_alphabet;
public:
// The constructor . . .
// create the two arrays with the c_alphabet array contents representing the std_alphabet
// characters shifted by a value of the shift parameter
Caesar(int shift = 0);
// encrypt a message. Returns count of characters processed
// first string is message, second is encrypted string
int encrypt(const std::string& message, std::string& emessage);
// decrypt a message. Returns count of characters processed
// first string is encrypted string, second is decrypted string
int decrypt(const std::string& message, std::string& dmessage);
//delete any memory resources used by the class
~Caesar();
}; // end of class . . .
#endif
这是我的 .cpp 文件,我目前只是在尝试在数组中移动我的字母表,但我不明白为什么我的头文件使用指针或者我是否正确创建了我的数组(我能够让这个概念在单独的文件中工作但不使用头文件)。在进行任何编码之前,我只是尝试打印这些行以确保它能正常工作:
#ifndef CAESAR_C
#define CAESAR_C
#include <string>
#include <iostream>
#include "Caesar.h"
using namespace std;
int shift, i, k;
char letter = 'a';
Caesar::Caesar(const int n) {
shift = n;
std_alphabet[26];
c_alphabet[26];
for (i = 0; i < 26; i++) {
std_alphabet[i] = letter;
letter++;
}
for (i = 0; i < 26; i++) {
cout << std_alphabet[i] << " ";
}
cout << endl;
for (i = 0; i < 26; i++) {
k = (i + shift) % 26;
c_alphabet[i] = std_alphabet[k];
}
for (i = 0; i < 26; i++) {
cout << c_alphabet[i] << " ";
}
};
#endif
这是我的测试文件,我真的不知道如何正确启动 Caesar 对象。就像我说的那样,我是 C++ 的完全初学者,非常感谢任何指示:
#include <string>
#include <iostream>
#include "Caesar.h"
using namespace std;
int main() {
Caesar* test = new Caesar(5);
cout << test;
system("PAUSE");
return 0;
};
最佳答案
在问这个问题之前,您似乎没有对这个问题做太多研究,甚至没有尝试自己找出解决方案。但无论如何,我会尽量对你有所帮助。
先做这些(我猜已经知道这些事情):
关于c++ - Caesar Cipher C++(数组和指针),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46102748/
使用 Cipher.ENCRYPT_MODE 有什么区别/好处/缺点吗加密 key 以使用 Cipher.WRAP_MODE 进行传输? 我的理解是,我仍然需要第二个,可能更小的 key 来包装/加密
我创建了一个传递两个缓冲区的密码。 buf1 是它们的键,一个 32 字节的缓冲区,而 buf2,即 IV,也是一个 32 字节的缓冲区,我将其切片为仅使用 16 字节。文档说 cipher.upda
我刚刚将我的 Mac 升级到 Snow Leopard,并启动并运行了我的 Rails 环境。除了 OSX 之外,我之前安装的唯一区别是我现在运行的是 ruby 1.8.7 (2008-08-11 p
正在尝试在客户端和服务器之间建立 SSL 连接。但每当我尝试从客户端连接时,我的服务器上都会收到 javax.net.ssl.SSLHandshakeException: no cipher suit
在多线程 Java 应用程序中,我们使用 AES-256 对磁盘文件进行加密和解密。请注意,多个线程可以同时调用不同文件的加密和解密方法。 加密: Cipher encrypter = Cipher.
我试图将安全提供程序从 SunJCE 切换到 Bouncy CaSTLe (BC),并在 Cipher 对象中偶然发现了这种特殊行为。据我所知,SunJCE 的 cipher.update(bytes
我应该如何使用从服务器端传输的公钥在客户端加密 session key ? 我应该使用 Cipher.WRAP_MODE 还是 Cipher.ENCRYPT_MODE? Cipher cipher =
SecretKey key = keyFactory.generateSecret(keySpec); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS
我正在尝试使用 AES 解密字符串,并且使用 jce.jar 来执行此操作。 我有以下方法来解密。 public String decrypt(String strToDecrypt) {
我有一个带有解密功能的 Android 应用程序,如下所示: private static byte[] decrypt(byte[] keybytes, byte[] data) { Sec
我正在实现 DES - CBC。我对 cipher.init 、 cipher.update 和 cipher.dofinal 的作用感到困惑。我只是使用 init 来设置 key 并使用 dofin
使用 Digicert's SSL mechanism explanation我已经了解数据在浏览器和服务器之间是如何加密的,以下是我的理解。 浏览器将向服务器发送请求以获取一些资源。服务器检查请求的
我正在使用 javax.crypto 在 java 中进行 AES CBC 解密。我正在使用以下 Cipher 类方法: public final void init (int opmode, Key
我能否在多个方法中使用相同的 Cipher 对象,因为 getInstance 和 init 的方法参数不会改变? 例如,假设应用程序的多个部分使用实用程序类中的 decrypt 方法。所有传递的加密
很简单,javax.crypto.Cipher 的一个实例(例如 Cipher.getInstance("RSA"))可以从多个线程中使用,还是我需要将它们中的多个粘贴在 ThreadLocal 中(
Rails4默认使用加密的cookie session 存储。当应用程序尝试加密cookie时,会引发以下错误:OpenSSL::Cipher::CipherError: Illegal key si
我正在使用this code . 当所有代码都在 main 方法中的一个 try catch 中时,它似乎可以工作,但当它被分成另一个类并通过 Security 对象调用解密时,它就不起作用了。 我猜
我目前正在使用 Cipher 创建一个使用始终相同的 key 的解决方案。我知道这不是最安全的解决方案,但这是我被要求做的。我应该使用 AES256 和 EBC,但我无法正确加密。问题是我有未知的字符
我正在尝试读取一个大小为1KB的文件,然后使用CBC模式下的AES算法对其进行加密和解密。当我尝试初始化密码时,它抛出一个错误。请找到下面的代码。我在密码类中找不到接受“加密模式”、“ key ”和类
你好,我构建了这两种方法,加密工作正常,但解密出现错误,因为密码想要一个字节,我想从字符串加密 import javax.crypto.Cipher; import javax.crypto.spec
我是一名优秀的程序员,十分优秀!