本帖最后由 yu2n 于 2015-7-17 10:22 编辑
回复 8# 328612167
a-Z,0-9 都教给你了,加几个特殊字符应该不难?
只需要 sSrc、sDes 保证唯一对应关系即可,随机打乱顺序……
纯英文、纯数字、特殊字符、汉字……原理都是一样的。
下面是英文、纯数字、特殊字符的对应。 | 将纯英文 | | sSrc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | | sDes = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM" | | 改为英文、纯数字、特殊字符 | | sSrc = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/*-+.~!@#$%^&*()_{}|:""<>?=[];',.\" | | sDes = "/*-+.~!@#$%^&*()_{}|:""<>?=[];',.\0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"COPY |
不罗嗦,下面贴代码: | Option Explicit | | | | | | Msgbox "Hello Word 加密后:" & MyEncryption("Hello Word", 0) | | | | | | Msgbox "{7EEH \HK6 解密后:" & MyEncryption("{7EEH \HK6", 1) | | | | Function MyEncryption(ByVal str, ByVal mode) | | Dim sSrc, sDes, sTmp, arrSrc(), arrDes(), arrTmp(), a, b | | sSrc = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/*-+.~!@#$%^&*()_{}|:""<>?=[];',.\" | | sDes = "/*-+.~!@#$%^&*()_{}|:""<>?=[];',.\0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | | If mode<>0 Then sTmp=sSrc : sSrc=sDes : sDes=sTmp | | ReDim arrSrc(Len(sSrc)) : ReDim arrDes(Len(sSrc)) : ReDim arrTmp(Len(str)) | | For a=0 To Len(sSrc)-1 | | arrSrc(a)=Mid(sSrc, a+1, 1) : arrDes(a)=Mid(sDes, a+1, 1) | | Next | | For b=0 To Len(str)-1 | | arrTmp(b)=Mid(str, b+1, 1) | | For a=0 To Len(sSrc)-1 | | If arrTmp(b)=arrSrc(a) Then arrTmp(b)=arrDes(a) : Exit For | | Next | | Next | | MyEncryption=Join(arrTmp,"") | | End FunctionCOPY |
结果: | Microsoft (R) Windows Script Host Version 5.7 | | 版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。 | | | | Hello Word 加密后:{7EEH \HK6 | | {7EEH \HK6 解密后:Hello WordCOPY |
I wrote a new program? No. 我只是在纯英文字符对应关系里面加了数字、特殊字符而已。Well, say no more you don't understand ... |