为游戏中使用的对称密码输入字符

inputing char for a symmetric cipher to be used in a game

我正在寻找一个允许用户(玩家)将字母表中的字母分配给其他字母的简单函数。例如:"a = n"。然后将这些字母放在一个数组中:alb[n,..]。我应该使用指针吗?

使用std::vector

首先,想想翻译功能会是什么样子。这会告诉您所需数据的形状。最初在测试程序中对翻译 table 进行硬编码,否则您会因担心与用户交谈而分心。

一旦您理解了您将需要的 tx table 以及如何存储它,然后再担心输入它。

我有答案。这里有一些使用字母表前三个字母的测试代码。

int i = 0, j = 0;
string alp[] = { "a", "b", "c" }, alpc[] = { "0", "1", "2" };

while (i <= 2) {
    cout << "Enter the letter substitution: " << alp[i] << " = ";
    cin >> alpc[i];
    for (j = 0; j < i; ++j) {
        while (alpc[j] == alpc[i]) {
            cout << "Please enter a non-redundant letter substitution: ";
            cin >> alpc[i];
        }

    }
    ++i;
    }