Getting Input Key for Atbash Cipher An Atbash cipher is a simple substitution cipher wherein a key is used to determine what letters to swap, for example:

Original alphabet: abcdefghijklmnopqrstuvwxyz
Substitute (key):  zyxwvutsrqponmlkjihgfedcba
Original message:  hello world
Altered message:   svool dliow


In my program, I get the key by printing the original letter, and then getting the letter that is to substitute it, and adding it to a key string, for example:

a = &lt;user input&gt;
b = &lt;user input&gt;
c = &lt;user input&gt;
...


Here is the simple code that I use for it:

std::cout &lt;&lt; "Key:\n";
std::string key;

for(int i = 0; i &lt;= 25; i++){
    std::cout &lt;&lt; static_cast&lt;char&gt;('a' + i) &lt;&lt; " = ";
    char inputChar;

    std::cin &gt;&gt; inputChar;
    key += inputChar;

    std::cin.ignore();
    std::cin.clear();
    std::cout &lt;&lt; std::flush;
}


How can I improve this code?
For one thing, it is very inadvisable to use the += operator with strings, because it's slow and it requires the string to be relocated in the memory. This isn't much of a problem with higher-level languages like Python, but with C and also Java, it's not a good idea, and it's not good practice. Since you know that there are 26 letters in the alphabet, you can make a length 26 array to store the key instead. Otherwise, the rest of the code looks good! :)