Board logo

标题: 如何用批处理生成这样的纯数字字典 [打印本页]

作者: w1314ich     时间: 2010-1-5 13:34    标题: 如何用批处理生成这样的纯数字字典

字典要求:数字0~9
可生成AABB型
         ABAB型
         ABBA型
总共三种类型4位纯数字密码字典
作者: w1314ich     时间: 2010-1-5 15:12
有人帮帮我吗
作者: w1314ich     时间: 2010-1-5 16:57
用批处理实现不了吗?
作者: qinchun36     时间: 2010-1-5 17:43
可以拆成三个文件。
@echo off
setlocal enabledelayedexpansion
for /l %%i in (1000,1,9999) do (
  set a=%%i
  ::AABB
  if "!a:~0,1!"=="!a:~1,1!" (
    if not "!a:~0,1!"=="!a:~2,1!" (
      if "!a:~2,1!"=="!a:~3,1!" (
        echo !a!
        if "!a:~2,1!"=="0" echo !a:~2,2!!a:~0,2!
      )
    )
  )
  ::ABAB
  if "!a:~0,1!"=="!a:~2,1!" (
    if not "!a:~0,1!"=="!a:~1,1!" (
      if "!a:~1,1!"=="!a:~3,1!" (
        echo !a!
        if "!a:~1,1!"=="0" echo !a:~3,1!!a:~2,1!!a:~1,1!!a:~0,1!
      )
    )
  )
  ::ABBA
  if "!a:~0,1!"=="!a:~3,1!" (
    if not "!a:~0,1!"=="!a:~1,1!" (
      if "!a:~1,1!"=="!a:~2,1!" (
        echo !a!
        if "!a:~1,1!"=="0" echo !a:~1,1!!a:~0,1!!a:~3,1!!a:~2,1!
      )
    )
  )
)
echo OK.
pause>nul

作者: w1314ich     时间: 2010-1-6 15:59
如果不是纯数字的话,而是字母和数字按照AABB,ABAB,ABBA的规律任何混合的话应该如何写
作者: bat-zw     时间: 2010-1-8 11:18    标题: 献丑了。。。


@echo off&setlocal enabledelayedexpansion
set "code=abcdefghijklmnopqrstuvwxyz0123456789"
(for /l %%a in (35,-1,1) do (
    set "str=!code:~,1!"&set "code=!code:~1!"&set "codes=!code!"
    for /l %%b in (%%a,-1,1) do (
        set "var=!codes:~,1!"&set "codes=!codes:~1!"
        echo !str!!str!!var!!var!
        echo !str!!var!!str!!var!
        echo !str!!var!!var!!str!
        echo !var!!var!!str!!str!
        echo !var!!str!!var!!str!
        echo !var!!str!!str!!var!
    )
))>list.txt
start list.txt
[ Last edited by bat-zw on 2010-1-8 at 14:25 ]
作者: ligui0001     时间: 2010-1-8 13:27
呵呵,给个解释,FOR难学会
作者: 523066680     时间: 2010-1-8 20:32
尝试用那个东东做一次
@echo off
setlocal enabledelayedexpansion
call :func "" "12AB"
pause
exit

:func
setlocal
set str=%~2
if "%str:~2%"=="" (
   call :echo %~1
   goto :eof
)
set /a n=-1
  :next
   set /a n+=1,nb=n+1
   call :func "%~1 !str:~%n%,1!" "!str:~0,%n%!!str:~%nb%!"
  if not "!str:~%n%,-1!"=="" (goto :next)
endlocal
goto :eof

:echo
echo %1%1%2%2
echo %1%2%1%2
echo %1%2%2%1
goto :eof

作者: 523066680     时间: 2010-1-8 21:17
1-9
call多了速度很慢的说,不说速度,却算是锻炼了。
@echo off
setlocal enabledelayedexpansion
set long=9876543210
call :func "" "123456789"
pause
exit

:func
setlocal
set str=%~2
if "%str:~6%"=="" (
   call :echo %~1
   goto :eof
)
set /a n=-1
  :next
   set /a n+=1,nb=n+1
   call :func "%~1 !str:~%n%,1!" "!str:~0,%n%!!str:~%nb%!"
  if not "!str:~%n%,-1!"=="" (goto :next)
endlocal
goto :eof

:echo
echo %1%1%2%2
echo %1%2%1%2
echo %1%2%2%1
goto :eof