2008脚本大赛PowerShell高级组Event 5解题及分析

题目位置: 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 : Scripts wordlist . 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. "

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值