本帖最后由 3mile 于 2011-5-24 10:33 编辑
#include <array.au3>
Dim $strUserInput, $strSimple, $strCipher, $i, $j, $k, $strIndex
$strUserInput = "Sir,Everything is under control.Over."&@crlf&"Newlines test"
;文本加密程序
;-------------------------------------------------------------------------------------
$strSimple = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ,."
$strCipher = "RxyopSTDPQXeE FGHIJzjkZa.bclmU,VWABCfghivwqrYdnKLMNOstu"
If StringLen($strSimple) = StringLen($strCipher) Then
Local $dic_encryption = ObjCreate("scripting.dictionary")
Local $dic_decryption = ObjCreate("scripting.dictionary")
For $i = 1 To StringLen($strSimple)
$dic_encryption.item(StringMid($strSimple, $i, 1)) = StringMid($strCipher, $i, 1)
$dic_decryption.item(StringMid($strCipher, $i, 1)) = StringMid($strSimple, $i, 1)
Next
EndIf
$stringout = Encryption($strUserInput)
MsgBox(0, "加密", $stringout)
$stringout1 = Decryption($stringout)
MsgBox(0, "解密", $stringout1)
;=============以下为加密代码================
Func Encryption($String)
Local $strCipherOutput
For $i = 1 To StringLen($String)
If $dic_encryption.Exists(StringMid($String, $i, 1)) Then
$strCipherOutput &= $dic_encryption.item(StringMid($String, $i, 1))
Else
$strCipherOutput &= StringMid($String, $i, 1)
EndIf
Next
Return $strCipherOutput
EndFunc ;==>Encryption
;============以下为解密代码==============
Func Decryption($String)
Local $strCipherOutput1
For $i = 1 To StringLen($String)
If $dic_decryption.Exists(StringMid($String, $i, 1)) Then
$strCipherOutput1 &= $dic_decryption.item(StringMid($String, $i, 1))
Else
$strCipherOutput1 &= StringMid($String, $i, 1)
EndIf
Next
Return $strCipherOutput1
EndFunc ;==>Decryption
|