I am coding a classic cipher by substitution in C ++ using all printable characters in ASCII, and I wonder what is faster? Searching in an array ( edit: not associative, just something like letters[] = {'a', 'b', ...);(linear or binary) or a switch statement. The compiler can optimize the switch, right? The difference in memory usage? My choice is the switch, although the code is bigger, but maybe maybe i missed something.
letters[] = {'a', 'b', ...);
(Perhaps this question seems subjective, but I think that it would be objective reasons to choose one way or another. And sorry for my English).
, , , , . :
char alphabet[] = { 'Z', 'E', 'B', 'R', 'A', 'S', 'C', 'D', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'T', 'U', 'V', 'W', 'X', 'Y' }; // now you can get the ciphertext for a single uppercase character with: alphabet[ch - 'A'];
? 128- , ASCII. , . ( 32 96 , , .)
, : ( , , ) .
, , , , , , .