Jul 8, 2019 at 6:26am UTC
Sorry I didn't coded this weekend.
Now it's perfectly working (using a key rotation).
Here's the code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/** rotate the key */
void rotation(std::string& key){
if (key.size()<2){
return ;
} else {
key=key.substr(1)+key[0];
return ;
}
}
std::string crypt(std::string& key, std::string msg){
std::string tmp("" );
for (int i(0);i<msg.size();++i){
tmp+=(msg[i]+atoi(key.substr(0,2).c_str()))%255;
rotation(key);
}
return tmp;
}
std::string uncrypt(std::string& key, const std::vector<char >& msg){
std::string tmp("" );
for (int i(0);i<msg.size();++i){
char tmp_val=msg[i]-atoi(key.substr(0,2).c_str());
if (tmp_val<0) tmp_val+=255;
rotation(key);
tmp+=tmp_val;
}
return tmp;
}
Thank you for help !
Last edited on Jul 8, 2019 at 6:28am UTC
Jul 8, 2019 at 6:34am UTC
This is not help, Zaap. It's self-help. One day I can start socket programing and to bump my head over the same problem too. I'd better be prepared in advance. Have a nice day!
P.s.Key rotation is a wise choice.
Last edited on Jul 8, 2019 at 6:36am UTC