BUUCTF - re [FlareOn4]login

BUUCTF - re [FlareOn4]login

下载下来之后一个html,里面有一段代码

<!DOCTYPE Html />
<html>
    <head>
        <title>FLARE On 2017</title>
    </head>
    <body>
        <input type="text" name="flag" id="flag" value="Enter the flag" />
        <input type="button" id="prompt" value="Click to check the flag" />
        <script type="text/javascript">
            document.getElementById("prompt").onclick = function () {
      
      
                var flag = document.getElementById("flag").value;
                var rotFlag = flag.replace(/[a-zA-Z]/g, function(c){
      
      return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);});
                if ("[email protected]" == rotFlag) {
      
      
                    alert("Correct flag!");
                } else {
      
      
                    alert("Incorrect flag, rot again");
                }
            }
        </script>
    </body>
</html>

(“[email protected]” == rotFlag) 关键位置应该是这了

[email protected]

charCodeAt(0)是返回当前字符的Unicode 编码
String.fromCharCode返回Unicode对应的字符串。这里的意思就是将字符后移13位,越界了就转到26个字母的开头(超过Z循环回A),循环进行,最后得到了字符串。事实上A-M是13个 字母,N-Z也是13个,共26个字母,就相当于在A-M就是加13,N-Z其实就是减13

写个脚本:

s = "[email protected]"

flag=''
for i in s:
    if i >='A'and i<='M':
        flag+=chr(ord(i)+13)
    elif i>='a'and i<='m':
        flag+=chr(ord(i)+13)
    elif i>='N' and i<='Z':
        flag+=chr(ord(i)-13)
    elif i>='n' and i<='z':
        flag+=chr(ord(i)-13)
    else:
        flag+=i
print(flag)
#[email protected]

后来了解到这种加密叫ROT13加密,在线解密网址

在这里插入图片描述

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/yzl_007/article/details/121257076