2008脚本大赛PowerShell高级组Event 5解题及分析
来源:互联网 发布:深入了解java虚拟机 编辑:程序博客网 时间:2024/05/16 15:17
题目位置: http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/chs/aevent5.mspx
官方题目解答: http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/expssol05.mspx
这题确实没有什么可以讲的, 主要是利用hash表来确定密码是否是单词. 我的第13个检查就是把字符串变成数组, 利用hash表来看每一个字符出现了几次, 如果是第二次出现, ?{} 就会为真, 改对象就会沿着管道进入到%{$dup = $true}中, 也就标记了该密码有重复字符.
param([string]$password)
$script:score = 13;
$rating = "weak","weak","weak","weak","weak","weak","weak",`
"moderately-strong","moderately-strong","moderately-strong","moderately-strong",`
"strong", "strong", "strong"
# 0: prepare ...
$hash = @{}
$chars = @{}
$dup = $false
Get-Content -Path C:Scriptswordlist.txt | % { $hash[$_] = $null }
# 1
if ($hash.ContainsKey($password)) {$script:score--; "Password is an actual word"}
# 2
if ($hash.ContainsKey($password.Remove($password.Length-1,1))) {$script:score--; "Password, minus the last letter, is an actual word."}
# 3
if ($hash.ContainsKey($password.Remove(0,1))) {$script:score--; "Password, minus the first letter, is an actual word."}
# 4
if ($hash.ContainsKey(($password -match '0') -and ($password -replace '0','o'))) {$script:score--; "Password simply substitute 0 (zero) for the letter o."}
# 5
if ($hash.ContainsKey(($password -match '1') -and ($password -replace '1','l'))) {$script:score--; "Password simply substitute 1 (one) for the letter l."}
# 6
if ($password.Length -lt 10) {$script:score--; "password is less than 10 characters"}
if ($password.Length -gt 20) {$script:score--; "password is more than 20 characters"}
# 7
if ($password -notmatch 'd') {$script:score--; "No number in password."}
# 8
if ($password -cnotmatch '[A-Z]') {$script:score--; "No uppercase letter in password."}
# 9
if ($password -cnotmatch '[a-z]') {$script:score--; "No lowercase letter in password."}
# 10
if ($password -cnotmatch '[^0-9a-zA-Z]') {$script:score--; "No symbol in password."}
#11
if ($password -cmatch '[a-z]{4,}') {$script:score--; "Four or more consecutive lowercase letters in password."}
#12
if ($password -cmatch '[A-Z]{4,}') {$script:score--; "Four or more consecutive uppercase letters in password."}
#13
$password.ToCharArray() | ? { [bool] $chars["$_"]++ } | % {$dup = $true}
if ($dup) {$script:score--; "Duplicate letters in password.";}
# result
""
"A password score of $script:score indicates a $($rating[$script:score]) password."
$script:score = 13;
$rating = "weak","weak","weak","weak","weak","weak","weak",`
"moderately-strong","moderately-strong","moderately-strong","moderately-strong",`
"strong", "strong", "strong"
# 0: prepare ...
$hash = @{}
$chars = @{}
$dup = $false
Get-Content -Path C:Scriptswordlist.txt | % { $hash[$_] = $null }
# 1
if ($hash.ContainsKey($password)) {$script:score--; "Password is an actual word"}
# 2
if ($hash.ContainsKey($password.Remove($password.Length-1,1))) {$script:score--; "Password, minus the last letter, is an actual word."}
# 3
if ($hash.ContainsKey($password.Remove(0,1))) {$script:score--; "Password, minus the first letter, is an actual word."}
# 4
if ($hash.ContainsKey(($password -match '0') -and ($password -replace '0','o'))) {$script:score--; "Password simply substitute 0 (zero) for the letter o."}
# 5
if ($hash.ContainsKey(($password -match '1') -and ($password -replace '1','l'))) {$script:score--; "Password simply substitute 1 (one) for the letter l."}
# 6
if ($password.Length -lt 10) {$script:score--; "password is less than 10 characters"}
if ($password.Length -gt 20) {$script:score--; "password is more than 20 characters"}
# 7
if ($password -notmatch 'd') {$script:score--; "No number in password."}
# 8
if ($password -cnotmatch '[A-Z]') {$script:score--; "No uppercase letter in password."}
# 9
if ($password -cnotmatch '[a-z]') {$script:score--; "No lowercase letter in password."}
# 10
if ($password -cnotmatch '[^0-9a-zA-Z]') {$script:score--; "No symbol in password."}
#11
if ($password -cmatch '[a-z]{4,}') {$script:score--; "Four or more consecutive lowercase letters in password."}
#12
if ($password -cmatch '[A-Z]{4,}') {$script:score--; "Four or more consecutive uppercase letters in password."}
#13
$password.ToCharArray() | ? { [bool] $chars["$_"]++ } | % {$dup = $true}
if ($dup) {$script:score--; "Duplicate letters in password.";}
# result
""
"A password score of $script:score indicates a $($rating[$script:score]) password."
- 2008脚本大赛PowerShell高级组Event 5解题及分析
- 2008脚本大赛PowerShell高级组Event 2解题及分析
- 2008脚本大赛PowerShell高级组Event 1解题及分析
- 2008脚本大赛PowerShell高级组Event 4解题及分析
- 2008脚本大赛PowerShell高级组Event 6解题及分析
- 2008脚本大赛PowerShell高级组Event 7解题及分析
- 2008脚本大赛PowerShell高级组Event 9解题及分析
- 2008脚本大赛PowerShell高级组Event 8解题及分析
- 2008脚本大赛PowerShell高级组Event 3解题及分析
- 2008脚本大赛PowerShell初级组Event 9解题及分析
- 2008脚本大赛PowerShell初级组Event 10解题及分析
- 2008脚本大赛PowerShell Sudden Death Event 5解题及分析
- 2008脚本大赛PowerShell Sudden Death Event 4解题及分析
- 2008脚本大赛PowerShell Sudden Death Event 6解题及分析
- 2008脚本大赛PowerShell Sudden Death Event 7解题及分析
- 2008脚本大赛PowerShell Sudden Death Event 9解题及分析
- 2008脚本大赛PowerShell Sudden Death Event 10解题及分析
- [3月28日的脚本] 修复Event ID 4107 and Event ID 11 问题 (PowerShell)
- NHibernate Plug-In for VS2005
- IPC经典问题
- 判断内存流中的图片格式
- Restlet指南
- http服务与客户
- 2008脚本大赛PowerShell高级组Event 5解题及分析
- 链接器如何解析多处定义的全局符号
- 最佳ASP.NET编程习惯
- Symbian数据类型定义
- 链接器如何使用静态库来解析引用
- FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用简介
- ASP.NET中的事务处理和异常处理
- Fedora Core 5 内核模块编译
- 对DotNet分布式应用搭建的考虑