函数参考


_StringEncrypt

一个基于 RC4 字符串加密的函数.

#Include <String.au3>
_StringEncrypt($i_Encrypt, $s_EncryptText, $s_EncryptPassword [, $i_EncryptLevel = 1])

参数

$i_Encrypt 1 为加密, 0 为解密.
$s_EncryptText 要加密/解密的文本.
$s_EncryptPassword 加密/解密使用的密码.
$i_EncryptLevel [可选参数] 加密解密等级. 默认(Default) = 1

返回值

成功: 返回加密/解密后的字符串.
失败: 返回空白字符串并设置 @error = 1

注意/说明

警告: 这个函数会随着加密等级的提高,返回的字符串长度越长!

相关

示例/演示


#include <GUIConstantsEx.au3>
#include <String.au3>

_Main()

Func _Main()
    Local $WinMain, $EditText, $InputPass, $InputLevel, $EncryptButton, $DecryptButton, $string
    ; GUI and String stuff
    $WinMain = GUICreate('Encryption tool', 400, 400)
    ; Creates window
    $EditText = GUICtrlCreateEdit('', 5, 5, 380, 350)
    ; Creates main edit
    $InputPass = GUICtrlCreateInput('', 5, 360, 100, 20, 0x21)
    ; Creates the password box with blured/centered input
    $InputLevel = GUICtrlCreateInput(1, 110, 360, 50, 20, 0x2001)
    GUICtrlSetLimit(GUICtrlCreateUpdown($InputLevel), 10, 1)
    ; These two make the level input with the Up|Down ability
    $EncryptButton = GUICtrlCreateButton('Encrypt', 170, 360, 105, 35)
    ; Encryption button
    $DecryptButton = GUICtrlCreateButton('Decrypt', 285, 360, 105, 35)
    ; Decryption button
    GUICtrlCreateLabel('Password', 5, 385)
    GUICtrlCreateLabel('Level', 110, 385)
    ; Simple text labels so you know what is what
    GUISetState()
    ; Shows window

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $EncryptButton
                GUISetState(@SW_DISABLE, $WinMain) ; Stops you from changing anything
                $string = GUICtrlRead($EditText) ; Saves the editbox for later
                GUICtrlSetData($EditText, 'Please wait while the text is Encrypted/Decrypted.') ; Friendly message
                GUICtrlSetData($EditText, _StringEncrypt(1, $string, GUICtrlRead($InputPass), GUICtrlRead($InputLevel)))
                ; Calls the encryption. Sets the data of editbox with the encrypted string
                ; The encryption starts with 1/0 to tell it to encrypt/decrypt
                ; The encryption then has the string that we saved for later from edit box
                ; It then reads the password box & Reads the level box
                GUISetState(@SW_ENABLE, $WinMain) ; This turns the window back on
            Case $DecryptButton
                GUISetState(@SW_DISABLE, $WinMain) ; Stops you from changing anything
                $string = GUICtrlRead($EditText) ; Saves the editbox for later
                GUICtrlSetData($EditText, 'Please wait while the text is Encrypted/Decrypted.') ; Friendly message
                GUICtrlSetData($EditText, _StringEncrypt(0, $string, GUICtrlRead($InputPass), GUICtrlRead($InputLevel)))
                ; Calls the encryption. Sets the data of editbox with the encrypted string
                ; The encryption starts with 1/0 to tell it to encrypt/decrypt
                ; The encryption then has the string that we saved for later from edit box
                ; It then reads the password box & Reads the level box
                GUISetState(@SW_ENABLE, $WinMain) ; This turns the window back on
        EndSwitch
    WEnd ; Continue loop untill window is closed
    Exit
EndFunc   ;==>_Main