VB常用算法(十)字符处理(统计与加密)
1.算法描述
1)加密和解密
最简单的加密方法是:给每个字母加一个序数,比如5。此时:
"A"→"F "," A"→"F "," B" →"G "," b" →"g"……"Y" →"D "," Y" →"D "," Z" →"E "," z" →"e "
解密是加密的逆过程。
界面如下:
代码如下:
选项显式
私有子命令1_Click()
Dim strInput$,Code$,Record$,c为String * 1
Dim i%,长度%,iAsc%
strInput = Text1。文本
length = Len(Trim(strInput))
Code = " "
对于i = 1到长度
c = mid(strInput,I,1)
选择案例c
案例“A”到“Z”
iAsc = Asc(c) + 5
如果iAsc > Asc("Z "),则iAsc = iAsc - 26
Code = Code & Chr(iAsc)
案例“a”到“z”
iAsc = Asc(c) + 5
如果iAsc > Asc("z "),则iAsc = iAsc - 26
Code = Code & Chr(iAsc)
0条评论