找回密码
 加入
搜索
查看: 2098|回复: 6

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

  [复制链接]
发表于 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[StringLen($strUserInput)]
Dim $strSimpleArray[StringLen($strSimple)]
Dim $strCipherArray[StringLen($strCipher)]
Dim $strCipherOutputArray[StringLen($strUserInput)];这个地方必须加数字才能执行,否则出现错误,请大大们帮忙调试。
;Dim $strCipherOutputArray[50]

;-------------------------------------------------------------------------
;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)
发表于 2011-5-23 20:09:08 | 显示全部楼层
第11行
Dim $strCipherOutputArray[StringLen($strUserInput) + 1]
发表于 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
发表于 2011-5-24 00:21:06 | 显示全部楼层

null

数组溢出了,AU3不能自动调整数组的大小
 楼主| 发表于 2011-5-24 10:45:44 | 显示全部楼层
回复 3# 3mile
太欣赏你的代码编写能力,呵呵
可是我还不咋会面向对象编程,有机会多像你学习
 楼主| 发表于 2011-5-24 10:46:42 | 显示全部楼层
回复 2# afan
谢谢斑竹,但是是否可以说明啥原因导致的呢?还有为啥要"+1"?
发表于 2011-8-4 10:31:16 | 显示全部楼层
用_ArrayAdd()或_ArrayPush()
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-1 21:33 , Processed in 0.071060 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表