抽象クラスを使用できます。
class CryptoAlgorithm
{
public:
// whatever functions all the algorithms do
virtual vector<char> Encrypt(vector<char>)=0;
virtual vector<char> Decrypt(vector<char>)=0;
virtual void SetKey(vector<char>)=0;
// etc
}
// user algorithm
class DES : public CryptoAlgorithm
{
// implements the Encrypt, Decrypt, SetKey etc
}
// your function
class mode{
public:
mode(CryptoAlgorithm *algo) // << gets a pointer to an instance of a algo-specific class
//derived from the abstract interface
: _algo(algo) {}; // <<- make a "Set" method to be able to check for null or
// throw exceptions, etc
private:
CryptoAlgorithm *_algo;
}
// in your code
...
_algo->Encrypt(data);
...
//
このように電話をかける_algo->Encrypt
と、使用している特定のアルゴリズムがわからず、気にせず、すべての暗号化アルゴリズムが実装する必要のあるインターフェイスが実装されているだけです。