ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 1팀 이유진 Write-Ups (Suninatas_1)
    2021/Write-Ups 2022. 1. 4. 18:55

     

    I. 문제 소개

    써니나타스 1번

    http://suninatas.com/challenge/web01/web01.asp

     

    Game 01

    <%    str = Request("str")    If not str = "" Then        result = Replace(str,"a","aad")        result = Replace(result,"i","in")        result1 = Mid(result,2,2)        result2 = Mid(result,4,6)  

    suninatas.com

     

     

    II. 문제 풀이

    배운 적이 없는 언어지만 어느 정도 유추는 할 수 있을 것 같아서 몇 가지 함수들만 구글링을 하고 주어진 코드를 해석해보기로 했다.


    Replace() : 문자열을 다른 문자열로 대체하는 함수

    형식 : Replace(변수명, "변경하고 싶은 문자열", "새롭게 대체할 문자열")

    Mid() : 문자열에서 지정한 만큼의 문자를 잘라서 반환하는 함수

    형식 : Mid(변수명, 시작 위치, 잘라낼 개수)

     

    ex)

    str = helloWorld

    result = Replce(str, "h", "H") -> result에는 "HelloWorld"가 저장된다.

    result1 = Mid(str, 6, 5) -> helloWorld에서 6번째 문자인 W부터 5개를 자른 World가 result1에 저장된다.


    <%   
        str = Request("str") - 문자열을 입력받아 str에 저장한다.    
           If not str = "" Then - str이 공백이 아니라면 다음 코드를 실행한다.        
            result = Replace(str,"a","aad") - str에 문자 'a'를 'aad'로 바꾸고 result에 저장한다.        
            result = Replace(result,"i","in") - str에 문자 'i'를 'in'으로 변경해서 result에 저장한다.        
            result1 = Mid(result,2,2) - result에서 2번째 문자부터 2개를 잘라서 result1에 저장한다.        
            result2 = Mid(result,4,6) - result에서 4번째 문자부터 6개를 잘라서 result2에 저장한다.         
            result = result1 & result2 - result1과 result2의 문자열을 합쳐서 result에 저장한다.        
            Response.write result                             
            If result = "admin" Then - result가 'admin'과 같다면            
                pw = "????????" - pw를 알 수 있다.        
            End if     
        End if
    %>

    결과적으로 result가 admin이 되게 하는 str에 들어갈 값을 코드를 역순으로 추적해서 찾으면 될 것 같다. 

    result1의 문자 개수가 2개니까 'ad'가 들어가야 할 것이고 result2는 자동으로 'min'이 될 것이다. 따라서 7, 8번째 줄에서 result는 '_admin'일 것이라고 추측했다. 

    6번째 줄에서 in이 원래는 i였으므로 result는 '_admi'가 된다. 5번째 줄에서 'aad'가 기존의 'a'를 대체했기 때문에 _에 들어갈 문자는 a라는 것을 알 수 있고, str은 'ami'가 되어야 한다는 것을 알아냈다.

     

    str = "ami"

    result = Replace(str,"a","aad") -> result = "aadmi"
    result = Replace(result,"i","in") -> result = "aadmin"
    result1 = Mid(result,2,2) -> result1 = "ad"
    result2 = Mid(result,4,6) -> result2 = "min"
    result = result1 & result2 -> result = "admin"

     

    'ami'를 입력하고 check 버튼을 클릭해보았다.

     

    축하한다는 메시지 창과 함께 Authkey가 생긴 것을 확인할 수 있었다.

     

    Authkey인 k09rsogjorejv934u592oi를 복사해서 정답 창에 입력했더니 성공하였다!