In my programm a string (may contain umlauts like "ä", "ö" or other exotic characters like "ß") is to be enciphered.
The second argument is argv[2]
and stored in the string text.
The function findInMap looks the passed character up in an map containing of 26 keys (representing columns) and string vector values (representing rows).
Returned is a vector of integer pairs representing rows and columns.
Everything works as expected as long as no exotic characters are used. If they are used a floating point exception occurs.
// Iterate over all characters in string.
for (int i = 0; i < text.size(); i++) {
vector<pair<int, int>> possibilites
= findInMap(cipherTable, text.substr(i, 1));
// Choose one possibility.
int choice = rand() % possibilites.size();
cipherString = cipherString + alphabet[possibilites[choice].first]
+ to_string(possibilites[choice].second + 1);
}
Interestingly, when I change the code above to
vector<pair<int, int>> possibilites
= findInMap(cipherTable, "ü");
ignoring the input and just looking up "ü", no error occurs, but this for loop is executed twice. Seemingly the string "ü" has size 2.
How can I
- iterate over the actual number of characters
- extract the correct character from text?
Help is very much appreciated.
Full code: https://github.com/BooneyNoobington/bbfe/tree/master/