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

本文介绍了一个使用TCL编写的密码字典生成器程序。该程序可在Debian环境下运行,并能够生成指定长度的密码组合,支持小写字母的任意组合。通过调整密码长度参数,可以生成不同长度的密码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

闲着无聊,编写了一个生成密码字典的小程序,做为学习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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值