功能2"修改联系人"还在编写之中,写完后会更新.
其它的功能请大家帮帮忙测试...- @echo off&cls
- mode con cols=50 lines=26
- title 批处理朋友录 %date%
- setlocal EnableDelayedExpansion
- set binnum=001011001100110001011001
- :start
- set enterpassword=
- if exist config.ini (
- for /f "tokens=1,2,3" %%i in (config.ini) do (
- if /i "%%i"=="color" (color %%k)
- if "%%i"=="password" (
- if not "%%k"=="!binnum!" (
- echo.&set /p enterpassword= 请输入密码:
- call :binpassword
- if "!binpassword!"=="%%k" (goto menu) else (
- echo.&echo. 错误的密码,请重新输入.
- goto start
- )
- )
- )
- )
- ) else (
- echo color = 07>config.ini
- echo password = !binnum!>>config.ini
- )
- :menu
- cls
- echo.&echo.&echo.
- echo. 欢迎使用批处理朋友录
- echo.&echo.
- set list=1.新增联系人,2.修改联系人,3.删除联系人,4.查询联系人,5.浏览联系人,6.朋友录设置,Q.退出通讯录
- for %%i in (%list%) do (set/p= %%i<nul&echo.&echo.)
- echo.
- set/p choice= 请输入你操作的选项:
- if /i "%choice%"=="Q" exit
- for %%i in (1,2,3,4,5,6) do if "%choice%"=="%%i" set choicn=1
- if defined choicn (goto choice%choice%) else (
- call :error 错误的输入,请重新输入.
- goto :menu
- )
- pause>nul&exit
- :choice1
- cls
- echo.
- echo. 增加新的联系人资料.输入/M返回主菜单.
- echo.
- echo. 请注意:当所有资料输入完毕才会保存,否则放弃.
- echo.
- echo. 回车则为空,资料中如有多项请用逗号分隔.
- echo.
- (set item=姓名,生日,手机号码,住宅电话,办公室电话,传真,电子邮件,QQ/MSN,家庭地址,其他)
- for %%i in (%item%) do (
- set %%i=
- set/p %%i= %%i:
- echo.
- if "!%%i!"=="" set %%i=空
- if /i "!%%i!"=="/m" goto menu
- set %%i=!%%i:α=a!
- set %%i=!%%i: = !
- set %%i=!%%i:,=,!
- )
- for %%i in (%item%) do (
- set/p (n=%%i:!%%i!α<nul)>>data.yrl
- )
- echo.>>data.yrl
- call :error 资料已经成功录入.
- goto choice1
- :choice2
- call :error 功能2正在完善中.
- goto menu
- :choice3
- cls
- echo.&echo. 输入/U撤销上一次删除资料,仅记忆一次.
- echo.&set /p delitem= 请输入要删除的联系人姓名(回车返回):
- if "%delitem%"=="" goto menu
- if /i "%delitem%"=="/u" (
- copy data.yrl_b data.yrl /y >nul 2>nul
- call :error 撤销上一次删除资料.
- goto menu
- ) else (
- copy data.yrl data.yrl_b /y >nul 2>nul
- echo.>data.yrl
- findstr . data.yrl_b | findstr /iv "[\< 姓名:!delitem! \>]" >>data.yrl
- call :error 操作完成.
- goto menu
- )
- :choice4
- cls
- set num=0
- echo.&echo. 关键字可为姓名、生日、手机号码等...
- echo.&echo. 资料中有此关键字的联系人均会列出.
- echo.&set/p rogatory= 请输入关键字(回车返回):
- if "%rogatory%"=="" goto menu
- for /f "delims=α tokens=1-10" %%a in ('type data.yrl ^| find "!rogatory!"') do (
- cls
- set/a num+=1
- echo. 关键字 "!rogatory!" ,查找到的第 !num! 个朋友资料.
- for /l %%z in (1,1,25) do (set/p=━<nul)
- echo.
- for %%k in (%%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i,%%j) do (
- echo. %%k
- echo.
- )
- for /l %%z in (1,1,25) do (set/p=━<nul)
- set enter=
- set/p enter= 回车显示下一条,其它返回主菜单.
- if not "!enter!"=="" goto menu
- )
- call :error 所有资料已查找完毕.
- goto menu
- :choice5
- set num=0
- for /f "delims=α tokens=1-10" %%a in (data.yrl) do (
- cls
- set/a num+=1
- echo. 正在浏览第 !num! 个朋友资料.按回车键显示下一条.
- for /l %%z in (1,1,25) do (set/p=━<nul)
- echo.
- for %%k in (%%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i,%%j) do (
- echo. %%k
- echo.
- )
- for /l %%z in (1,1,25) do (set/p=━<nul)
- set enter=
- set/p enter= 回车显示下一条,其它返回主菜单.
- if not "!enter!"=="" goto menu
- )
- call :error 所有朋友资料浏览完毕.
- goto :menu
- :choice6
- cls
- echo.&echo.&echo.
- echo. 批处理朋友录设置
- echo.&echo.
- set configlist=C.颜色设置,P.密码设置,X.修改密码,D.删除密码,M.返回菜单,Q.退出程序
- for %%i in (%configlist%) do (set/p= %%i<nul&echo.&echo.)
- echo.&echo.
- set/p configchoice= 请输入你操作的选项:
- if /i "%configchoice%"=="Q" exit
- if /i "%configchoice%"=="M" goto menu
- for %%i in (C,P,X,D) do if /i "%configchoice%"=="%%i" set configchoicen=1
- if defined configchoicen (goto configchoice%configchoice%) else (
- call :error 错误的输入,请重新输入.
- goto menu
- )
- :configchoicec
- cls
- echo.&echo.
- echo. 颜色属性由两个十六进制数字指定, 第一个为背景,
- echo. 第二个则为前景。每个数字可以为以下任何值之一:
- echo.
- echo. 0 = 黑色 8 = 灰色
- echo. 1 = 蓝色 9 = 淡蓝色
- echo. 2 = 绿色 A = 淡绿色
- echo. 3 = 湖蓝色 B = 淡浅绿色
- echo. 4 = 红色 C = 淡红色
- echo. 5 = 紫色 D = 淡紫色
- echo. 6 = 黄色 E = 淡黄色
- echo. 7 = 白色 F = 亮白色
- echo.
- echo. 例如: 输入 "fc" 将在亮白色上产生亮红色
- echo.&set /p color= 输入颜色代码:
- color !color!
- for /f "tokens=1,2,3" %%i in (config.ini) do (
- if "%%i"=="password" (
- set password=%%k
- )
- )
- echo color = !color!>config.ini
- echo password = !password!>>config.ini
- goto menu
- :configchoicep
- cls
- for /f "tokens=1,2,3" %%i in (config.ini) do (
- if "%%i"=="color" (set color=%%k)
- if "%%i"=="password" (
- if "%%k"=="!binnum!" (
- echo.
- echo. 密码只能为20位以内的纯数字.
- echo.
- set /p strpassword= 输入密码:
- set /p enterpassword= 确认密码:
- if "!strpassword!"=="!enterpassword!" (
- call :binpassword
- echo color = !color!>config.ini
- echo password = !binpassword!>>config.ini
- call :error 密码设置完毕.
- goto choice6
- ) else (
- call :error 两次输入的密码不相同)
- ) else (
- call :error 你已经设置了密码
- goto choice6
- )
- )
- )
- goto menu
- :configchoicex
- for /f "tokens=1,2,3" %%i in (config.ini) do (
- if "%%i"=="color" (set color=%%k)
- if "%%i"=="password" (
- if "%%k"=="!binnum!" (
- call :error 你还没有设置密码
- goto choice6
- ) else (
- cls
- echo.
- set /p enterpassword= 输入原始密码:
- call :binpassword
- if "!binpassword!"=="%%k" (
- set /p strpassword= 输入新密码:
- set /p enterpassword= 确认新密码:
- if "!strpassword!"=="!enterpassword!" (
- call :binpassword
- echo color = !color!>config.ini
- echo password = !binpassword!>>config.ini
- call :error 密码修改完毕.
- goto choice6
- ) else (
- call :error 两次输入的密码不相同)
- ) else (
- call :error 原始密码不在确
- goto choice6
- )
- )
- )
- )
- )
- goto menu
- :configchoiced
- for /f "tokens=1,2,3" %%i in (config.ini) do (
- if "%%i"=="color" (set color=%%k)
- if "%%i"=="password" (
- if "%%k"=="!binnum!" (
- call :error 你还没有设置密码
- goto choice6
- ) else (
- cls
- echo.
- set /p enterpassword= 输入原始密码:
- call :binpassword
- if "!binpassword!"=="%%k" (
- echo color = !color!>config.ini
- echo password = !binnum!>>config.ini
- call :error 密码已删除
- goto choice6
- ) else (
- call :error 原始密码不正确
- goto choice6
- )
- )
- )
- )
- goto menu
- :error
- cls
- echo.&echo.&echo.&echo.
- echo. %1<nul
- ping -n 2 127.1>nul
- goto :eof
- ::密码计算
- ::加密算法:把数字的每位相加,再乘以99,之后再算出乘积每位的二进制.
- ::这种算法相对来说是不可逆的,但是在批处理中却很好破解.
- :binpassword
- set passwordsum=
- set binpassword=
- set bin=0001,0010,0011,0100,0101,0110,0111,1000,1001
- for /l %%b in (0,1,19) do (set /a passwordsum+=!enterpassword:~%%b,1!>nul 2>nul)
- set /a passwordsum*=99
- for %%c in (%bin%) do ((set /a num+=1)&(set !num!=%%c)&(set 0=0000))
- for /l %%d in (0,1,5) do (set n%%d=!passwordsum:~%%d,1!)
- set binpassword=!%n0%!!%n1%!!%n2%!!%n3%!!%n4%!!%n5%!
- goto :eof
复制代码
|