省略字符 z 和 y 的字符串数组

string array omiting characters z and y

本文关键字:字符串 数组 字符      更新时间:2023-10-16

im 为我的实验室做一项作业,这与将字符串从另一个文件加密到文本文件中有关,效果很好,但我唯一的问题是当我加密或解密加密时,加密省略了字母 Z 和 Y。我尝试改变一些事情,但没有任何效果,如果你知道如何解释,因为我迷路了。

这是我到目前为止的代码:

 #include iostream
==
 #include fstream
==
 #include cstring
==
 #include string
==
 using namespace std;
 int main()
 {
    ifstream inputFile;
    ofstream outputFile;
    const int SIZE=150;
    char file[SIZE];
    char message[SIZE+1];
    char letter;  
    char alphabet[]={'A','B','C','D','E','F','G','H','I','J','K','L',
            'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',''};

    cout<<"Enter the message you want to encrypt: "<<endl;     //getmessage
    cin.getline(message,SIZE,'n');
    for(int i=0;i<strlen(message);i++){
       if(islower(message[i]))                               //change to 
            message[i]=toupper(message[i]);                 //uppercase
    }

    outputFile.open("textoNoEncrypt.txt");
    for(int i=0;i<strlen(message);i++){                  //copy message to 
       outputFile.put(message[i]);                      //file
     }
    outputFile.close();
    inputFile.open("textoNoEncrypt.txt");
    if (inputFile.is_open()){
         int i=0;
        while (!(inputFile=='')){
            inputFile>>file[i];                       //reading and copying
            i++;                                     //data from file        
        }
    }
    inputFile.close();
    outputFile.open("textoEncrypt.txt");
    for(int i=0;i<strlen(file);i++){
        int j=0;
        int P=0;
        int index=0;
        bool found=false;
        while(!found){
            if(file[i]==alphabet[j]){
                P=j;
                index=(P+3)%26;                     //encrypting message
                file[i]=alphabet[index];        
                found=true;
                cout<<j<<" ";
            }
        j++;
        }
        outputFile.put(file[i]);
    }
    outputFile.close();
    cout<<message<<endl;                        //show original message
    cout<<file<<endl;                           //show encrypted message
    return 0;
 }

我认为这是由 P+3 线引起的