原创 用TCL编写了一个生成密码字典的小测试程序,共享一下收藏

新一篇: 自动测试snmp、构造报文攻击的设想 | 旧一篇: TCL/EXPECT自动化测试脚本实例五 --- 由文件中读取一行

闲着无聊,编写了一个生成密码字典的小程序,做为学习tcl的一个阶段性总结。
可以生成包含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

发表于 @ 2006年05月30日 10:49:00|评论(loading...)|编辑

新一篇: 自动测试snmp、构造报文攻击的设想 | 旧一篇: TCL/EXPECT自动化测试脚本实例五 --- 由文件中读取一行

评论:没有评论。

发表评论  


登录
Csdn Blog version 3.1a
Copyright © Easwy