闲着无聊,编写了一个生成密码字典的小程序,做为学习tcl的一个阶段性总结。
可以生成包含dictChar任意组合的字符,密码长度也可以设置。
在debian下使用tclsh8.4测试通过。
可以生成包含dictChar任意组合的字符,密码长度也可以设置。
在debian下使用tclsh8.4测试通过。
#! /usr/bin/tclsh
#************************************************
# Password Dictionary Generator
# Just for learning, by easwy, Mar 31, 2006
#
# len - the length of password
#
# RETURN
# none, password group in file $dictName
#************************************************
proc genDict {len} {
# chars in password
set dictChar "abcdefghijklmnopqrstuvwxyz"
# count of chars
set charCnt [string length $dictChar]
# last item's index in array a
set last [expr "$len - 1"]
# dictionary file name
set dictName "passwd.txt"
# initial array a
for {set i 0} {$i < $len} {incr i} {
set a($i) 0
}
# open dictionary file
set dictFile [open "passwd.txt" w]
# starting...
while {true} {
# construct new passwd
set passwd ""
for {set i 0} {$i < $len} {incr i} {
# append char which index is $a($i) to passwd str
set passwd "$passwd[string index $dictChar $a($i)]"
}
# output passwd
puts $dictFile $passwd
# incr last char's index
incr a($last)
# update all indices
for {set i $last} {$i > 0} {incr i -1} {
if {$a($i) >= $charCnt} {
set a($i) 0
set ind [expr "$i - 1"]
incr a($ind)
}
}
# exit
if {$a(0) >= $charCnt} {break}
}
close $dictFile
}
# generate passwd string, len 3
genDict 3
#************************************************
# Password Dictionary Generator
# Just for learning, by easwy, Mar 31, 2006
#
# len - the length of password
#
# RETURN
# none, password group in file $dictName
#************************************************
proc genDict {len} {
# chars in password
set dictChar "abcdefghijklmnopqrstuvwxyz"
# count of chars
set charCnt [string length $dictChar]
# last item's index in array a
set last [expr "$len - 1"]
# dictionary file name
set dictName "passwd.txt"
# initial array a
for {set i 0} {$i < $len} {incr i} {
set a($i) 0
}
# open dictionary file
set dictFile [open "passwd.txt" w]
# starting...
while {true} {
# construct new passwd
set passwd ""
for {set i 0} {$i < $len} {incr i} {
# append char which index is $a($i) to passwd str
set passwd "$passwd[string index $dictChar $a($i)]"
}
# output passwd
puts $dictFile $passwd
# incr last char's index
incr a($last)
# update all indices
for {set i $last} {$i > 0} {incr i -1} {
if {$a($i) >= $charCnt} {
set a($i) 0
set ind [expr "$i - 1"]
incr a($ind)
}
}
# exit
if {$a(0) >= $charCnt} {break}
}
close $dictFile
}
# generate passwd string, len 3
genDict 3