Search in an array or switch? For encryption by replacement

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.

(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).

+3
source share
3 answers

, , , , . :

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'];
+1

? 128- , ASCII. , . ( 32 96 , , .)

+6

, : ( , , ) .

, , , , , , .

+2

All Articles