Beispiel #1
0
int main(int argc, string argv[])
{
    //if there less or more then one argument
    if (argc != 2 )
    {
        printf ("usage : ./vigenere + key word \n");
        return 1;
    }
    
    //if key word contains anything other than letters   
    string keyPhrase = convertStringToLower(argv[1]);
    
    for (int i = 0, n = strlen(keyPhrase); i < n; i++)
    {
        if (keyPhrase[i] < 'a' || keyPhrase[i] > 'z')
        {
            printf ("usage : ./vigenere + key word \n");
            return 1;
        }
    }
    
    string plainText = GetString();
    


    for (int i = 0, j = 0, l = strlen(plainText), m = strlen(keyPhrase); i < l; i++)
    {
        if ((plainText[i] >= 'a' && plainText[i] <='z') || (plainText[i] >= 'A' && plainText[i] <='Z'))
        {
            if(isupper(plainText[i]))
            {
                if (j >= m)
                    j = 0;
            
                plainText[i] = ((plainText[i] + returnIndexOfAlphabetChar(&keyPhrase[j]) - 'A') % 26) + 'A';
                printf("%c", plainText[i]);
                j++;
            }
        
            if(islower(plainText[i]))
            {
                if (j >= m)
                    j = 0;
            
                plainText[i] = ((plainText[i] + returnIndexOfAlphabetChar(&keyPhrase[j]) - 'a') % 26) + 'a';
                printf("%c", plainText[i]);
                j++;
            }
        }
        else
            printf("%c", plainText[i]);
    }
    printf("\n");
}
Beispiel #2
0
void LDModelParser::parseCommentLine(
	LDLCommentLine *commentLine,
	TREModel *treModel)
{
	if (commentLine->isStepMeta())
	{
		treModel->nextStep();
	}
	else if (commentLine->isOBIMeta())
	{
		if (m_flags.obi)
		{
			// 0 !OBI SET <token>
			// 0 !OBI UNSET <token>
			// 0 !OBI NEXT <color> [IFSET <token>|IFNSET <token>] 
			// 0 !OBI START <color> [IFSET <token>|IFNSET <token>]
			// 0 !OBI END
			switch (commentLine->getOBICommand())
			{
			case LDLCommentLine::OBICSet:
				if (commentLine->hasOBIToken())
				{
					std::string token = commentLine->getOBIToken();

					convertStringToLower(&token[0]);
					m_obiTokens.insert(token);
				}
				break;
			case LDLCommentLine::OBICUnset:
				if (commentLine->hasOBIToken())
				{
					std::string token = commentLine->getOBIToken();

					convertStringToLower(&token[0]);
					unsetToken(m_obiTokens, token.c_str());
				}
				break;
			case LDLCommentLine::OBICNext:
			case LDLCommentLine::OBICStart:
				m_obiInfo->start(commentLine, m_obiTokens);
				break;
			case LDLCommentLine::OBICEnd:
				m_obiInfo->end();
				break;
			default:
				// Gets rid of warning.
				break;
			}
		}
	}
	else if (commentLine->isTexmapMeta() && getTexmapsFlag() &&
		commentLine->isValid())
	{
		bool isStart = commentLine->containsTexmapCommand("START");
		bool isNext = commentLine->containsTexmapCommand("NEXT");
		
		if (isStart || isNext)
		{
			// Note: the data has already been copied out of this command and
			// into the associated action lines.  We just want to know that we
			// got here so we can activate the new texmap.
			m_flags.newTexmap = true;
			m_flags.texmapNext = isNext;
		}
		else if (commentLine->containsTexmapCommand("END"))
		{
			if (m_flags.texmapStarted)
			{
				treModel->endTexture();
				m_flags.texmapStarted = false;
			}
		}
	}
}