hetinghtht 发表于 2011-5-23 18:14:08

[已解决]数组定义问题,请教,绝非初级问题,请大大门看程序

本帖最后由 hetinghtht 于 2011-6-7 10:12 编辑

;文本加密程序
;-------------------------------------------------------------------------------------
Dim $strUserInput, $strSimple, $strCipher, $i, $j, $k, $strIndex, $strCipherOutput
$strCipherOutput=""
$strUserInput = "Sir,Everything is under control.Over."
$strSimple = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ,."
$strCipher = "RxyopSTDPQXeE FGHIJzjkZa.bclmU,VWABCfghivwqrYdnKLMNOstu"
Dim $strUserInputArray
Dim $strSimpleArray
Dim $strCipherArray
Dim $strCipherOutputArray;这个地方必须加数字才能执行,否则出现错误,请大大们帮忙调试。
;Dim $strCipherOutputArray

;-------------------------------------------------------------------------
;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ,.
;RxyopSTDPQXeE FGHIJzjkZa.bclmU,VWABCfghivwqrYdnKLMNOstu;密文对应关系
;-------------------------------------------------------------------------

$strUserInputArray = StringSplit($strUserInput, "");将用户输入字符串存入数组
$strSimpleArray = StringSplit($strSimple, "");将明文存入数组
$strCipherArray = StringSplit($strCipher, "");将密文存入数组

;-------------------------------------------------------;枚举明文,并得到密文对应值
For $i = 1 To UBound($strUserInputArray) - 1
        For $j = 1 To UBound($strSimpleArray) - 1
                $strIndex = StringInStr($strSimple, $strUserInputArray[$i], 1, 1)
                If @error Then
                        MsgBox(0, "没有找到匹配结果", "“" & $strUserInputArray[$i] & "”搜索完毕,没有结果可显示。")
                        ExitLoop
                Else
                        $strCipherOutputArray[$i] = $strCipherArray[$strIndex]
                        ExitLoop
                EndIf
        Next
Next

;------------------------------------------------------;输出密文
For $k = 1 To UBound($strCipherOutputArray) - 1
        $strCipherOutput &= $strCipherOutputArray[$k]
Next
MsgBox(0, "密文输出", "待加密数据:" & $strUserInput & @LF & "已加密数据:" & $strCipherOutput)

afan 发表于 2011-5-23 20:09:08

第11行
Dim $strCipherOutputArray

3mile 发表于 2011-5-23 21:03:54

本帖最后由 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

papapa314 发表于 2011-5-24 00:21:06

null

数组溢出了,AU3不能自动调整数组的大小

hetinghtht 发表于 2011-5-24 10:45:44

回复 3# 3mile
太欣赏你的代码编写能力,呵呵
可是我还不咋会面向对象编程,有机会多像你学习

hetinghtht 发表于 2011-5-24 10:46:42

回复 2# afan
谢谢斑竹,但是是否可以说明啥原因导致的呢?还有为啥要"+1"?

ejzhang 发表于 2011-8-4 10:31:16

用_ArrayAdd()或_ArrayPush()
页: [1]
查看完整版本: [已解决]数组定义问题,请教,绝非初级问题,请大大门看程序