按ctrl+u打开网页源代码
<!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 ("PyvragFvqrYbtvafNerRnfl@syner-ba.pbz" == rotFlag) {
alert("Correct flag!");
} else {
alert("Incorrect flag, rot again");
}
}
</script>
</body>
</html>
这一行是加密
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);}); |
加密后是PyvragFvqrYbtvafNerRnfl@syner-ba.pbz
我们首先要了解一些函数
1.replace()函数两个参数,用后一个替换前一个,这里就是用function函数得到的结果去替换26个字母。
2.charCodeAt(0)用来获取到一串字符的首字母,这里就是单个字母啦。
3.fromCharCode()可接受一个指定的 Unicode 值,然后返回一个字符串。这
先判断c是大于Z,还是小于等于Z;若小于等于Z,令c=90,否则等于122。
再判断90或122对应的字符是否大于等于原来的c+13,若大于等于c+13,则取c+13,否则取c+13-26,即c-13。
#include <iostream>
using namespace std;
int main() {
char a[] = "PyvragFvqrYbtvafNerRnfl@syner-ba.pbz";
char b[37];
char flag[37];
for (int i = 0; i < 37; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') {
b[i] = a[i];
a[i] = 90;
if (a[i] >= b[i] + 13)
flag[i] = b[i] + 13;
else
flag[i] = b[i] + 13 - 26;
} else if ('a' <= a[i] && a[i] <= 'z') {
b[i] = a[i];
a[i] = 122;
if (a[i] >= b[i] + 13)
flag[i] = b[i] + 13;
else
flag[i] = b[i] + 13 - 26;
} else
flag[i] = a[i];
}
for (int i = 0; i < 37; i++)
cout << flag[i];
}