mardi 26 juin 2018

Cesar code function, two "check" if's seem not to work

I was making a function which chenges textto cesar code, i wanted to make it in this way, that if after adding value to ASCII, it would exceed 122 or 90 then it checks the differance and adds to either 64 or 96

Those ifs seem not to work, any idea why? Here is all code necessary

    std::string CesarCode(std::string begin, int howmanychar, bool encrypt_decrypt)
{
    char cSpace = ' ';
    std::vector<char> vecLett(0);
    for (auto y : begin)
    {
        vecLett.push_back(y);
    }

    std::vector<int> vecCharSwapToInt;
    int iTemp;
    for (auto x : vecLett)
    {
        iTemp = (int)x;
        vecCharSwapToInt.push_back(x);
    }
    std::vector<char> vecIntSwapToChar;
    char cTemp = ' ';
    int iCheck;
    for (char v : vecCharSwapToInt)
    {
        if (v == cSpace)
        {
            vecIntSwapToChar.push_back(v);
        }
        else if(v != cSpace)
        {
            cTemp = (int)v + howmanychar;
            if (((int)v + howmanychar) > 90)
            {
                iCheck = (int)cTemp - 90;
                (int)cTemp == 64 + iCheck;
            }
            else if (((int)v + howmanychar) > 122)
            {
                iCheck = (int)cTemp - 122;
                (int)cTemp == 96 + iCheck;
            }
            cTemp = (char)cTemp;
            vecIntSwapToChar.push_back(cTemp);
        }
    }
    std::string sComplete = "";
    for (auto s : vecIntSwapToChar)
    {
        sComplete += s;
    }

    return sComplete;
}

Aucun commentaire:

Enregistrer un commentaire