关卡地址

解决方案:

思路:

这一关就不贴图了,直接看图片下提示:

recognize the characters. maybe they are in the book, but MAYBE they are in the page source.

很明显,玄机在源代码中。在源代码中有这样的提示:

find rare characters in the mess below:

所以,从一堆混乱的字符中找到稀有的字符吧!

代码:

Challenge002.py

import helper
msg=helper.readFile(".\\Data\\002\\msg.txt")

dic={}

for ch in msg:
    if ch in dic:
        continue
    else:
        dic[ch]=msg.count(ch)

# print(dic)


outstr=[]
for key,value in dic.items():
    if value < 10:
        outstr.append(key)

print(''.join(outstr))
PS src\static> python .\Code\Python\Challenge002.py

Challenge002.ps1

$msg=(Get-Content ".\\Data\\002\\msg.txt" -Raw).Replace("`r`n","")

# powershell 中 hashtable 遍历的顺序与添加的顺序不一致

# $dic=@{}

$dic=New-Object 'System.Collections.Generic.Dictionary[string,int]'
for ($i = 0; $i -lt $msg.Length; $i++) {
    $ch=$msg[$i]
    if ($dic.ContainsKey($ch)) {
        $dic[$ch]+=1
    } else {
        $dic[$ch]=0
    }  
}

[string]$outstr=""
foreach ($key in $dic.Keys) {
    if ($dic[$key] -le 10) {
        $outstr+=$key
    }
}

Write-Output $outstr
PS src\static> .\Code\PowerShell\Challenge002.ps1

Challenge002.go

package main

import (
	"fmt"
	"strings"
)

func (c *Challenge) Challenge002()  {
	msg:=ReadFile(".\\Data\\002\\msg.txt")

	// go语言 遍历map时返回值是无序的,相同keys每次构建map时顺序都会变化,构建后多次遍历结果一致。
	dic:=map [rune] int {}
	outstr:=""
	// // 记录字符顺序
	// chars:=""

	// for _,ch := range msg {
	// 	_,exists:=dic[ch]
	// 	if (exists) {
	// 		continue
	// 	} else {
	// 		s:=string(ch)
	// 		chars+=s
	// 		dic[ch]=strings.Count(msg,s)
	// 	}
	// }

	// for _,ch := range chars {
	// 	value,exists:=dic[ch]
	// 	if (exists) {
	// 		if (value < 10) {
	// 			outstr+=string(ch)
	// 		}
	// 	}
	// }

	for _,ch := range msg {
		_,exists:=dic[ch]
		if (exists) {
			continue
		} else {
			s:=string(ch)
			count:=strings.Count(msg,s)
			dic[ch]=count
			if (count < 10) {
				outstr+=s
			}
		}
	}

	fmt.Println(outstr)
}
PS src\static> .\Code\Go\Challenge.exe -l 002

最终结果: equality

[下一关地址][5]