用TCL编写了一个生成密码字典的小测试程序,共享一下
2006-05-30 10:49
921 查看
闲着无聊,编写了一个生成密码字典的小程序,做为学习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
可以生成包含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
相关文章推荐
- 有一个帐号类,包含有(id、用户名和密码),编写程序使用List接口来存储多个帐号对象,注意id是自动生成(规则是为List中所有帐号中最大的id再加1)
- 随机生成一些数字并传入某个方法。编写一个程序,每当收到新字符数字时,找出并记录中位数。
- 编写程序,生成一个包含20个随机整数的列表,然后对其中偶数下标的元素进行降序排列,基数下标的元素不变
- //1.编写代码模拟三次密码输入的场景。//2.编写一个程序,可以一直接收键盘字符,如果是小写字符就输出对应的大写字符,如果接收的是大写字符,就输出对应的小写字符,如果是数字不输出。
- 作业二:个人编程项目——编写一个能自动生成小学四则运算题目的程序
- 一个生成随机密码的WPF小程序
- 编写一个程序读入一行输入,然后反向打印该行,您可以把输入存储在一个char数组中: 假定该行不超过255个字符。回忆一下,您可以使用具有%c说明符的scanf()从输入中一次 读入一个字符,而且当您按下回车键时会产生换行符(/n)
- 编写一个小程序,从标准输入读入一系列string对象,寻找连续重复出现的单词。程序应该找出满足一下条件的单词:该单词的后面紧接着再次出现自己本身。跟踪重复次数最多的单词及其重复次数,输出.
- 一个生成COBOL测试数据的小程序——解释数据中的数据类型
- 最近设计了一个生成asp代码的程序,同时也可以作为数据库管理查询的软件,发两张图,等完全做好了,给大家共享!
- 编写多线程程序,模拟多个人通过一个山洞。这个山洞每次只能通过一个人,每个人通过山洞的时间为2秒(sleep)。随机生成10个人,都要通过此山洞,用随机值对应的字符串表示人名,打印输出每次通过山洞的人名
- 编写多线程程序,模拟多个人通过一个山洞。这个山洞每次只能通过一个人,每个人通过山洞的时间为2秒(sleep)。随机生成10个人,都要通过此山洞,用随机值对应的字符串表示人名,打印输出
- 一个最简单的测试在dev/下生成字符设备的程序
- 用javascript语言编写一个小程序:在一个文本框(用户名框)中按回车键时,跳转到另一个文本框(密码框)中,密码框回车之后,打一个登陆成功。点击button也是登陆成功。
- 一个自动测试程序的编写
- 作业二:编写一个自动生成四则运算的程序
- 编写一个程序对Largest函数进行测试,找出一组数据的最大值
- 编写一个JAVA程序,创建指定长度的 int 型数组,并生成 100 以内随机数为数组中的每个元素赋值,然后输出数组
- 一个玩具程序——测试密码强度(pure C)
- 编写一个程序,输入一串不超过60个字符组成的且不包含换行符的字符串,将字符串中的A到Z的字母按英文字典字母顺序重新排列,排列后的单词的长度要与原始句子中的长度相同,并且要求只对A到Z的字母重新排列,其