示例#1
0
        private MappedPassword createSingleMapping(Password pw)
        {
            string[] ID1Arr = pw.ID1.Split(' '); // creates name in the PW file i.e. World_of_Tanks
            string   fullID = "";

            for (int i = 0; i < ID1Arr.Length; i++)
            {
                if (i + 1 == ID1Arr.Length)
                {
                    fullID += ID1Arr[i];
                }
                else
                {
                    fullID += ID1Arr[i] + "_";
                }
            }

            //System.Diagnostics.Debug.WriteLine(fullID);

            int actualLettersLength = letters.Length;

            for (int i = 0; i < letters.Length; i++)
            {
                if (letters[i] == null)
                {
                    actualLettersLength = i;
                    break;
                }
            }

            MappedPassword MP = new MappedPassword(fullID);

            char[]        pwChars      = pw.ID2.ToCharArray();
            LetterCoord[] pwCharsCoord = new LetterCoord[pwChars.Length];

            for (int i = 0; i < pwChars.Length; i++)
            {
                for (int j = 0; j < actualLettersLength; j++)
                {
                    try
                    {
                        if (pwChars[i] == letters[j].Let)
                        {
                            LetterCoord tmp = letters[j].useLocCoord();
                            pwCharsCoord[i] = new LetterCoord(tmp.getIntegerNumber(), tmp.getLetterID());
                            break;
                        }
                    }
                    catch (NullReferenceException)
                    {
                        continue;
                    }

                    if (j == actualLettersLength - 1)
                    {
                        pwCharsCoord[i] = new LetterCoord(-1, -1);
                        break;
                    }
                }
            }

            MP.createLineMap(pwCharsCoord);

            return(MP);
        }
示例#2
0
        private Password retrieveSinglePassword(string mapping)
        {
            string[] tmp = mapping.Split(' ');

            string[] ID1Arr = tmp[0].Split('_');
            string   ID1    = "";

            for (int i = 0; i < ID1Arr.Length; i++)
            {
                if (i + 1 == ID1Arr.Length)
                {
                    ID1 += ID1Arr[i];
                }
                else
                {
                    ID1 += ID1Arr[i] + " ";
                }
            }

            int actualLettersLength = letters.Length;

            for (int i = 0; i < letters.Length; i++)
            {
                if (letters[i] == null)
                {
                    actualLettersLength = i;
                    break;
                }
            }

            string retPW         = "";
            int    integerNumber = 0;
            int    letterID      = 0;

            for (int i = 1; i < tmp.Length; i += 2)
            {
                try
                {
                    integerNumber = Int32.Parse(tmp[i]);
                    letterID      = Int32.Parse(tmp[i + 1]);

                    if (integerNumber == -1)
                    {
                        retPW += "*";
                        continue;
                    }
                }
                catch (FormatException)
                {
                    continue;
                }


                for (int j = 0; j < actualLettersLength; j++)
                {
                    try
                    {
                        LinkedList <LetterCoord>     tempLetterCoords = letters[j].getLetterCoords();
                        LinkedListNode <LetterCoord> currentNode      = tempLetterCoords.First;
                        LetterCoord requiredNode = new LetterCoord(integerNumber, letterID);

                        while ((currentNode != null) && !((currentNode.Value.getIntegerNumber() == integerNumber) && (currentNode.Value.getLetterID() == letterID)))
                        {
                            currentNode = currentNode.Next;
                        }

                        if (currentNode != null)
                        {
                            retPW += letters[j].Let;
                        }
                    }
                    catch (NullReferenceException)
                    {
                        retPW += "*";
                        break;
                    }
                }
            }

            return(new Password()
            {
                ID1 = ID1, ID2 = retPW
            });;
        }