Beispiel #1
0
        private StringBuilder MoveString(StringBuilder inputSrting, int key, TypeCoding typeCoding)
        {
            StringBuilder outputString = new StringBuilder();

            int tempKey = key;

            if (typeCoding == TypeCoding.DECODING)
            {
                tempKey = -key;
            }

            for (int i = 0; i < inputSrting.Length; i++)
            {
                if (Char.IsLetter(inputSrting[i]))
                {
                    int temp = UA_Alphabet.GetNumber(inputSrting[i]);
                    if (Exist(temp))
                    {
                        temp += tempKey;
                        if (IsCorrectNumber(temp))
                        {
                            outputString.Append(UA_Alphabet.GetChar(temp));
                        }
                        else
                        {
                            if (typeCoding == TypeCoding.DECODING)
                            {
                                outputString.Append(UA_Alphabet.GetChar(UA_Alphabet.AlphabetLength + tempKey));
                            }
                            else
                            {
                                outputString.Append(UA_Alphabet.GetChar(UA_Alphabet.AlphabetLength - tempKey));
                            }
                        }
                    }
                    else
                    {
                        outputString = new StringBuilder(_messageErrorLetter + inputSrting[i]);
                        return(null);
                    }
                }
            }

            return(outputString);
        }
Beispiel #2
0
        public StringBuilder DecodingWithoutKey(StringBuilder inputString)
        {
            StringBuilder res = null;

            char offerLetter = TextAnalyser.GetOffenLetter(inputString);

            for (int i = 0; i < UA_Alphabet.LoudLetterLenght; i++)
            {
                int           numbetween     = UA_Alphabet.GetNumBetweenLetter(offerLetter, UA_Alphabet.GetLoudLetter(i));
                StringBuilder partText       = GetFirstPart(inputString);
                StringBuilder partTextResult = DecodingUA(partText, numbetween);
                if (CorrectText(partTextResult))
                {
                    return(DecodingUA(inputString, numbetween));
                }
            }

            return(res);
        }