value becoming 0 for no obvious reason
for some reason, the value mod
i am creating is becoming 0 in keygen
despite being correct when it is made and after keygen is run. i dont get why. can anyone tell me?
class RC5{
private:
uint64_t w, r, b;
uint128_t mod;
std::string mode;
std::vector <uint64_t> S;
public:
RC5(std::string KEY, std::string MODE, uint64_t W = 32, uint64_t R = 12, uint64_t B = 16){
uint128_t mod = 1;
mod <<= W;
mode = MODE;
w = W;
r = R;
b = B;
std::cout << mod << std::endl; // 1 << 32
keygen(KEY);
std::cout << mod << std::endl; // 1 << 32
}
void keygen(std::string key){
std::cout << mod << std::endl; // 0
// lots of commented out stuff
}
};
i am sure that uint128_t is开发者_开发问答 written correctly, so this doesnt seem to make sense. if necessary, uint128_t can be found here.
erm, because in the ctor you are modifying a local variable called mod
which shadows your class member.
This part of RC5
uint128_t mod = 1;
mod <<= W;
creates a new local variable mod
that hides the class member. In keygen
you use the other mod
.
精彩评论