OVH Cloud OVH Cloud

Optimisation

23 réponses
Avatar
nico
Bonjour,

A titre d'entrainement j'ai ecrit la fonction suivante :

string xor_crypte(string str_in,string clef) {
int str_len=str_in.length();
int clef_len=clef.length();
string str_out;
for(int i=0;i<str_len;i+=clef_len) {
for(int j=0;j<clef_len;j++) {
char c[1]={ static_cast<char>(*str_in.substr(i+j,1).c_str()) ^
static_cast<char>(*clef.substr(j,1).c_str()) };
str_out+=string(c,1);
}
}
return str_out;
}

Que faudrait-il faire pour éventuellement l'optimiser ?
Peut être une conversion std::string > char * avant le for ?

--
nico

3 réponses

1 2 3
Avatar
Matthieu Moy
Arnaud Meurgues writes:

Matthieu Moy wrote:

i := ma_string.end();


réminiscence du Pascal ? ;-)


Non, touche `:' trop proche de la touche `!' ;-)

--
Matthieu


Avatar
Matthieu Moy
drkm writes:

Matthieu Moy writes:

Si tu veux le 42ème caractère (en partant de 0) de la chaine
ma_string, un ma_string[42] me parait simple et adapté ;-)


Bof.


Tu aurais fait comment ?

--
Matthieu


Avatar
drkm
Matthieu Moy writes:

drkm writes:

Matthieu Moy writes:

Si tu veux le 42ème caractère (en partant de 0) de la chaine
ma_string, un ma_string[42] me parait simple et adapté ;-)


Bof.


Tu aurais fait comment ?


ma_string[ 41 ]

--drkm



1 2 3