小编Cza*_*ing的帖子

在派生函数中指定 void* 参数

我想做一些在 Cpp 中可能无法实现的事情,但我找不到专门针对此的帖子。

我想让派生类指定虚函数上的 void* 参数的类型。

我有一个名为 interface 的基类,带有一个发送函数。

// pure virtual
class Interface{
    virtual bool Send(const void*)=0;

};

struct Packet{
    DataType data;
};

class SpecificInterface{
     bool Send(const DataType*);
}
Run Code Online (Sandbox Code Playgroud)

有没有办法让这样的工作?意图是SpecificInterface::Send 实现Interface::Send。允许特定接口不是纯虚拟的,同时将 void* 限制为特定的数据包类型。

否则我知道我可以使用 void* 参数并将其 static_cast 转换为 Packet* 类型;但是,我不希望其他人发送无法转换为 Packet* 的指针类型。

如果这不清楚,请告诉我

c++ inheritance void-pointers

2
推荐指数
1
解决办法
83
查看次数

这有多安全

为了使其更适用于其他人,我想知道写代码是多么逼真,它会将消息加密到没有密码就不可能被解密的程度.我认为最好的方法是制作哈希算法并添加随机性.那么业余爱好者编写声音加密有多现实?任何工程师都能破解业余加密算法吗?编辑:几个答案讨论了对计算机内存的攻击,这是我很欣赏的有用信息,但我更感兴趣的是知道该消息是否可以直接解密.我假设cryptoanalyser无法访问计算机混淆消息,因为如果他这样做他无论如何都可以查看我的源代码并找到解密算法.这是我的例子:

public class Keys { // hold the methods and information used to lock, unlock, make the key, get the "keypad" after it has been locked, and a static method to change int[] to long[] 
// Fields
private String passphrase;
private long[] key;
private long keynum;
private long[] pad;
Random rands = new Random();
// Constructors
public Keys (String passphrase) // makes a key based of the given passphrase 
{
    this.passphrase = passphrase;
    key = keycipher(this.passphrase.toCharArray());
    key = keyfix(key);
    keynum …
Run Code Online (Sandbox Code Playgroud)

java encryption hash password-encryption

0
推荐指数
1
解决办法
123
查看次数