Пример #1
0
 void ReadGame()       // stLine, edLine 알아내기
 {
     CryptoGrapher.ReadFile(ref buffer, fileName);
     stLine = -1;
     for (int i = 0; i < buffer.Length; ++i)
     {
         if (buffer[i] == "■" + game)
         {
             stLine = i; break;
         }
     }
     if (stLine == -1)           // 해당 게임이 존재하지 않음
     {
         stLine = buffer.Length;
         edLine = buffer.Length + 1;
         CreateGame();
     }
     else
     {
         for (int i = stLine; i < buffer.Length; ++i)
         {
             if (buffer[i] == "//End")
             {
                 edLine = i; break;
             }
         }
     }
 }
Пример #2
0
    void CreateLabel(string label, int numLine)
    {
        CryptoGrapher.ReadFile(ref buffer, fileName);
        int i, j;

        string[] newBuffer = new string[buffer.Length + numLine + 1];

        for (i = 0; i < edLine; ++i)
        {
            newBuffer[i] = buffer[i];
        }
        newBuffer[i++] = "//" + label;
        for (; i <= edLine + numLine; ++i)
        {
            newBuffer[i] = "Empty";
        }
        newBuffer[i++] = "//End";
        j = edLine + 1;
        for (; i < newBuffer.Length; ++i)
        {
            newBuffer[i] = buffer[j++];
        }
        edLine += numLine + 1;
        CryptoGrapher.WriteFile(newBuffer, fileName);
    }
        [TestMethod()]//Test working of Encrypt function in CryptoGrapher
        public void EncryptTest()
        {
            //Arrange
            crypt = new CryptoGrapher();
            string Key = DateTime.Now.ToString("ddmmyyyyhhMMssfffffff");

            //Act
            string EncryptedKey = crypt.Encrypt(Key);

            //Assert
            Assert.AreNotEqual(Key, EncryptedKey);
        }
Пример #4
0
    public string SelectMap(string digitMean)
    {
        quit = false;
        int numLabel = (edLine - stLine - 1) / (1 + l);

        if (numLabel == 0)
        {
            quit = true; return("");
        }
        // 모든 label 알아내기
        CryptoGrapher.ReadFile(ref buffer, FILENAME);
        string[] labels = new string[numLabel];
        for (int i = 0; i < numLabel; ++i)
        {
            int labelLine = stLine + 1 + i * (1 + l);
            labels[i] = buffer[labelLine].Substring(2);
        }
        while (Console.KeyAvailable)
        {
            Console.ReadKey(true);
        }
        while (true)
        {
            ShowMap(labels[cur], 0, 0);
            ConsoleKeyInfo cki = Console.ReadKey(true);
            string         s   = cki.Key.ToString();

            if (s == "Enter" || s == "Spacebar")
            {
                return(labels[cur]);
            }
            else if (s == "R")
            {
                RecordManager r = new RecordManager(game);
                r.ShowRecord(labels[cur], digitMean);
                MyFunction.WaitForExit();
            }
            else if (s == "LeftArrow")
            {
                cur = (cur - 1 + numLabel) % numLabel;
            }
            else if (s == "RightArrow")
            {
                cur = (cur + 1) % numLabel;
            }
            else if (s == "Q")
            {
                quit = true; return("");
            }
        }
    }
Пример #5
0
    void CreateGame()
    {
        CryptoGrapher.ReadFile(ref buffer, fileName);
        string[] tmp = new string[buffer.Length + 2];
        int      i   = 0;

        for (i = 0; i < buffer.Length; ++i)
        {
            tmp[i] = buffer[i];
        }
        tmp[i++] = "■" + game;
        tmp[i]   = "//End";
        CryptoGrapher.WriteFile(tmp, fileName);
    }
Пример #6
0
    public void RenameMap(string label, string newLabel)       // Map상의 label 수정
    {
        bool res = ReadLabel(label, l);

        if (!res)
        {
            DeleteMap(label); return;
        }
        buffer[labelLine] = "//" + newLabel;
        CryptoGrapher.WriteFile(buffer, FILENAME);
        // Record상의 label 수정
        RecordManager r = new RecordManager(game);

        r.ModifyRecord(label, newLabel);
    }
Пример #7
0
    protected void DeleteLabel(string label, int numLine)
    {
        ReadLabel(label, numLine);
        string[] newBuffer = new string[buffer.Length - numLine - 1];
        int      i;

        for (i = 0; i < labelLine; ++i)
        {
            newBuffer[i] = buffer[i];
        }
        for (i = labelLine + numLine + 1; i < buffer.Length; ++i)
        {
            newBuffer[i - numLine - 1] = buffer[i];
        }
        CryptoGrapher.WriteFile(newBuffer, fileName);
    }
Пример #8
0
    public bool ReadLabel(string label, int numLine, ref string[] buffer)       // labelLine 알아내기
    {
        CryptoGrapher.ReadFile(ref buffer, fileName);
        int i;

        labelLine = -1;
        for (i = stLine; i <= edLine; ++i)
        {
            if (buffer[i] == "//" + label)
            {
                labelLine = i; break;
            }
        }
        if (labelLine == -1)           // 해당 식별자가 존재하지 않음
        {
            labelLine = edLine;
            CreateLabel(label, numLine);
            CryptoGrapher.ReadFile(ref buffer, fileName);
            return(false);
        }
        return(true);
    }
        [TestMethod()]//Test working of decrypt function in CryptoGrapher
        public void DecryptTest()
        {
            //Arrange
            xmlReader = XmlReader.Create(@"..\XMLTestFiles\TPA_500.xml");
            var tpa        = new TPAScaffold();
            var serializer = new XmlSerializer(tpa.GetType());

            input = (TPAScaffold)serializer.Deserialize(xmlReader);
            crypt = new CryptoGrapher();

            tpaController = new TaxProfileAssistantController();
            tpaController.ControllerContext = new ControllerContext();
            string resultstr = tpaController.Post(input);
            string key       = resultstr.Substring(38);

            key = key.Replace(Constants.APPLICATION_URL_DUMMY_TEXT, "/");

            //Act
            string DecryptedKey = crypt.Decrypt(key);

            //Assert
            Assert.AreNotEqual(key, DecryptedKey);
        }
Пример #10
0
    public void ModifyMap(string label)
    {
        ShowMap(label, 0, 0, true);
        bool save = false;
        // (x,y) = (1,1)~(w,l), 절대좌표는 x*2
        // buffer상에서 (x,y) = (y+y0, x+x0)
        int x0 = -1, y0 = labelLine;
        int x = 1, y = 1;

        Console.SetCursorPosition(2, 1);
        if (buffer[1 + labelLine][0] == '■')
        {
            Console.BackgroundColor = ConsoleColor.Red;
            Console.Write("■");
        }
        else
        {
            Console.BackgroundColor = ConsoleColor.Green;
            Console.Write("  ");
        }
        // 키 입력받기
        while (Console.KeyAvailable)
        {
            Console.ReadKey(true);
        }
        while (true)
        {
            ConsoleKeyInfo cki = Console.ReadKey(true);
            string         s   = cki.Key.ToString();

            if (s == "W")
            {
                save = true; break;
            }
            else if (s == "Q")
            {
                break;
            }
            else if (s == "Spacebar")
            {
                Console.SetCursorPosition(x * 2, y);
                if (buffer[y + y0][x + x0] == '■')
                {
                    buffer[y + y0]          = MyFunction.Substitute(buffer[y + y0], x + x0, ' ');
                    Console.BackgroundColor = ConsoleColor.Green;
                    Console.Write("  ");
                }
                else
                {
                    buffer[y + y0]          = MyFunction.Substitute(buffer[y + y0], x + x0, '■');
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.Write("■");
                }
            }
            else if (s.Contains("Arrow"))
            {
                int nx = x, ny = y;
                if (s == "UpArrow")
                {
                    --ny;
                }
                else if (s == "DownArrow")
                {
                    ++ny;
                }
                else if (s == "LeftArrow")
                {
                    --nx;
                }
                else
                {
                    ++nx;
                }

                if (nx < 1 || nx > w || ny < 1 || ny > l)
                {
                    continue;
                }
                Console.SetCursorPosition(x * 2, y);
                Console.BackgroundColor = ConsoleColor.Black;
                if (buffer[y + y0][x + x0] == '■')
                {
                    Console.Write("■");
                }
                else
                {
                    Console.Write("  ");
                }

                x = nx; y = ny;
                Console.SetCursorPosition(x * 2, y);
                if (buffer[y + y0][x + x0] == '■')
                {
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.Write("■");
                }
                else
                {
                    Console.BackgroundColor = ConsoleColor.Green;
                    Console.Write("  ");
                }
            }
        }
        if (save)
        {
            CryptoGrapher.WriteFile(buffer, FILENAME);
        }
    }
Пример #11
0
    public static void OverWrite()
    {
        const string FILENAME1 = "Record1";

        Console.ResetColor();
        Console.Clear();
        Console.SetCursorPosition(2, 1);
        Console.Write("※도움말※");
        Console.SetCursorPosition(2, 3);
        Console.Write("1. 외부에서 {0}.dll 파일을 구해옵니다", FILENAME);
        Console.SetCursorPosition(2, 4);
        Console.Write("2. 파일 이름을 {0}.dll로 바꾸고 폴더 안에 넣어주세요", FILENAME1);
        Console.SetCursorPosition(2, 5);
        Console.Write("3. 덮어쓰기가 완료되면 Record1.dll을 폴더에서 빼내주세요");
        Console.SetCursorPosition(2, 7);
        Console.Write("♠ W를 누르면 덮어쓰기를 시작합니다 ♠");
        Console.SetCursorPosition(50, 10);
        Console.Write("뒤로가기(Spacebar/Enter)");

        while (Console.KeyAvailable)
        {
            Console.ReadKey(true);
        }
        while (true)
        {
            ConsoleKeyInfo cki = Console.ReadKey(true);
            string         s   = cki.Key.ToString();
            if (s == "W")
            {
                break;
            }
            else if (s == "Spacebar" || s == "Enter")
            {
                return;
            }
        }
        // 덮어쓰기 시작
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.SetCursorPosition(2, 8);
        Console.Write("♠ 덮어쓰기중.. ♠");
        Thread.Sleep(1000);

        // 덮어쓰기 실패
        if (!File.Exists(FILENAME1 + ".dll"))
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.SetCursorPosition(2, 8);
            Console.Write("♠ 실패: Record1.dll을 찾을 수 없습니다 ♠");
            MyFunction.WaitForExit();
            return;
        }
        // 덮어쓰기 진행
        string[] res = new string[1];
        CryptoGrapher.ReadFile(ref res, FILENAME);
        string[] buffer = new string[1];
        CryptoGrapher.ReadFile(ref buffer, FILENAME1);
        FileManager fm = new FileManager();

        for (int i = 0; i < buffer.Length; ++i)
        {
            if (buffer[i][0] == '■')
            {
                string game = buffer[i].Substring(1);
                CryptoGrapher.WriteFile(res, FILENAME);
                fm = new FileManager(FILENAME, game);
                CryptoGrapher.ReadFile(ref res, FILENAME);
            }
            else if (buffer[i] == "Empty" || buffer[i] == "//End")
            {
                continue;
            }
            else if (buffer[i][0] == '/')
            {
                string label = buffer[i].Substring(2);
                CryptoGrapher.WriteFile(res, FILENAME);
                fm.ReadLabel(label, MAXRANK, ref res);
            }
            else               // 현재 label의 점수에 대해
            {
                string[] tmp      = buffer[i].Split(' ');
                int      newDigit = int.Parse(tmp[0]);
                string   userName = tmp[1];
                int      curRank  = -1;

                for (int j = fm.labelLine + 1; j <= fm.labelLine + MAXRANK; ++j)
                {
                    int    rank  = j - fm.labelLine;
                    int    digit = 0;
                    string name  = "-";
                    if (res[j] != "Empty")
                    {
                        string[] tmp2 = res[j].Split(' ');
                        digit = int.Parse(tmp2[0]);
                        name  = tmp2[1];
                    }
                    if (digit <= newDigit)
                    {
                        if (digit != newDigit || userName != name)
                        {
                            curRank = rank;
                        }
                        break;
                    }
                }
                if (curRank == -1)
                {
                    continue;
                }
                for (int j = fm.labelLine + MAXRANK; j > fm.labelLine + curRank; --j)
                {
                    res[j] = res[j - 1];
                }
                res[fm.labelLine + curRank] = newDigit.ToString() + " " + userName;
            }
        }
        // 덮어쓰기 종료
        CryptoGrapher.WriteFile(res, FILENAME);
        Console.ForegroundColor = ConsoleColor.Green;
        Console.SetCursorPosition(2, 8);
        Console.Write("♠ 덮어쓰기 성공 ♠");
        MyFunction.WaitForExit();
    }
Пример #12
0
 public void ModifyRecord(string label, string newLabel)       // label 변경하기
 {
     ReadLabel(label, MAXRANK);
     buffer[labelLine] = "//" + newLabel;
     CryptoGrapher.WriteFile(buffer, FILENAME);
 }
Пример #13
0
    public void UpdateRecord(string label, string digitMean, int newDigit, bool reverse)
    {
        ReadLabel(label, MAXRANK);
        string[] prev = new string[buffer.Length];
        int      i;

        for (i = 0; i < buffer.Length; ++i)
        {
            prev[i] = buffer[i];
        }

        int curRank = -1;

        for (i = labelLine + 1; i <= labelLine + MAXRANK; ++i)
        {
            int rank  = i - labelLine;
            int digit = 0;
            if (buffer[i] != "Empty")
            {
                digit = int.Parse(buffer[i].Split(' ')[0]);
            }
            else if (reverse)
            {
                digit = int.MaxValue;
            }
            if ((!reverse && digit <= newDigit) || (reverse && digit >= newDigit))
            {
                curRank = rank; break;
            }
        }
        if (curRank == -1)
        {
            return;                        // 랭킹 안에 들지 못함
        }
        // base.buffer수정, stLine/edLine/labelLine이 바뀌지 않는다
        for (i = labelLine + MAXRANK; i > labelLine + curRank; --i)
        {
            buffer[i] = buffer[i - 1];
        }
        buffer[labelLine + curRank] = newDigit.ToString();

        CryptoGrapher.WriteFile(buffer, FILENAME);
        ShowRecord(label, digitMean);
        // 아이디 입력 도중 창을 닫으면 점수를 등록하지 않는다
        CryptoGrapher.WriteFile(prev, FILENAME);

        // 유저 아이디 입력받기
        Console.SetCursorPosition(46, 23);
        Console.CursorVisible = true;
        Console.Write("<아이디 입력 후 Spacebar/Enter>");

        int x0 = 0, x = 23;
        int y = 4 + 2 * (curRank - 1);

        Console.BackgroundColor = ConsoleColor.Magenta;
        Console.SetCursorPosition(x0 + 3, y);
        if (curRank < 10)
        {
            Console.Write(" ");
        }
        Console.Write("{0}.", curRank);

        Console.ResetColor();
        Console.SetCursorPosition(x, y);
        int cur = x;

        char[] userName = new char[MAXLEN];

        while (Console.KeyAvailable)
        {
            Console.ReadKey(true);
        }
        while (true)
        {
            ConsoleKeyInfo cki = Console.ReadKey(true);
            string         s   = cki.Key.ToString();

            if (s == "Enter" || s == "Spacebar")
            {
                if (cur == x)
                {
                    continue;
                }
                Console.CursorVisible = false;
                break;
            }
            else if (s == "Backspace")
            {
                if (cur == x)
                {
                    continue;
                }
                Console.SetCursorPosition(--cur, y);
                Console.Write(" ");
            }
            else
            {
                if (s.Length > 1 || s[0] < 'A' || s[0] > 'Z')
                {
                    continue;
                }
                if (cur >= x + MAXLEN)
                {
                    continue;
                }
                Console.SetCursorPosition(cur, y);
                Console.Write(s);
                userName[cur - x] = s[0];
                ++cur;
            }
        }
        string tmp = "";

        for (i = x; i < cur; ++i)
        {
            tmp += userName[i - x];
        }
        buffer[labelLine + curRank] += " " + tmp;
        CryptoGrapher.WriteFile(buffer, FILENAME);
    }