I wrote a bunch of crypto algorithms as classes and now I want to implement encryption modes (generalized modes shown in wikipedia, not the specific ones in the algorithms' specifications). How would I write a function that can accept any of the classes?
edit:
here's what i want to accomplish
class mode{
private:
algorithm_class
public:
mode(Algorithm_class, key, mode){
algorithm_class = Algorithm_class(key, mode);
}
};
You can use abstract classes:
In this way when you call
_algo->Encrypt
- you don't know and don't care about which specific algorithm you're using, just that it implements the interface all the crypto algorithms should be implementing.Well, how about
?
No need for
mode
andkey
parameters, as the algorithm can be created by the user: