Jump to content
Sign in to follow this  
WolfWorld

Encryption system NEW DSCV3 !

Recommended Posts

WolfWorld

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Boxscript\misc.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_Comment=Original DSCV2
#AutoIt3Wrapper_Res_Description=DSCV2
#AutoIt3Wrapper_Res_Fileversion=2.0.2.0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.12.1
    Author:,, Athiwat Chunlakhan
    
    Script Function:
    GenerateKeyDSCV2($Phrase, ByRef $CASE)
    DSCV2($Data, $KEY, $Encrypt)
    
    Encryption by DSCV3 Method
    
    ----------------------------------------------------------------------------
#ce
#NoTrayIcon
#include <GuiConstantsEx.au3>

;~ Opt("MustDeclareVars", 1)

;Use one Main or File
;Credit For Main goto the one who made it?
;Credit for _file gui goes to Andreik
_Main()
;~ _File()

Func _File()
    $GUI = GUICreate("File Encrypt/Decrypt DSCV3 CREDIT FOR GUI TO Andreik", 300, 150, -1, -1)
    $OPEN = GUICtrlCreateInput(@ScriptDir, 5, 5, 250, 20)
    $B1 = GUICtrlCreateButton("..", 270, 5, 20, 20)
    $SAVE = GUICtrlCreateInput(@ScriptDir, 5, 30, 250, 20)
    $B2 = GUICtrlCreateButton("..", 270, 30, 20, 20)
    $CODE = GUICtrlCreateInput("", 100, 55, 100, 20, BitOR(0x0001, 0x0020))
    $ENC = GUICtrlCreateButton("ENCRYPT", 5, 80, 100, 20)
    $DEC = GUICtrlCreateButton("DECRYPT", 195, 80, 100, 20)
    $PROGRESS = GUICtrlCreateProgress(5, 110, 290, 30)
    ControlDisable("File Encrypt/Decrypt", "", $PROGRESS)
    GUISetState(@SW_SHOW, $GUI)
    Local $KEY

    While 1
        $MSG = GUIGetMsg()
        Switch $MSG
            Case $B1
                $FILE = FileOpenDialog("OPEN", @ScriptDir, "All (*.*)", 1)
                GUICtrlSetData($OPEN, $FILE)
            Case $B2
                $FILE = FileSaveDialog("SAVE", @ScriptDir, "All (*.*)")
                GUICtrlSetData($SAVE, $FILE)
            Case $ENC
                $FILE_OPEN = FileOpen(GUICtrlRead($OPEN), 0)
                $DATA = FileRead($FILE_OPEN)
                FileClose($FILE_OPEN)
                $FILE_SAVE = FileOpen(GUICtrlRead($SAVE), 2)
                GENERATEKEYDSCV3(GUICtrlRead($CODE), $KEY)
                FileWrite($FILE_SAVE, DSCV3($DATA, $KEY, 1))
                FileClose($FILE_SAVE)
            Case $DEC
                $FILE_OPEN = FileOpen(GUICtrlRead($OPEN), 0)
                $DATA = FileRead($FILE_OPEN)
                FileClose($FILE_OPEN)
                $FILE_SAVE = FileOpen(GUICtrlRead($SAVE), 2)
                GENERATEKEYDSCV3(GUICtrlRead($CODE), $KEY)
                FileWrite($FILE_SAVE, DSCV3($DATA, $KEY, 0))
                FileClose($FILE_SAVE)
            Case - 3
                Exit
        EndSwitch
        Sleep(20)
    WEnd
EndFunc   ;==>_File

Func _Main()
    Local $WinMain, $EditText, $InputPass, $InputLevel, $UpDownLevel, $EncryptButton, $DecryptButton, $string, $KEY
    ; GUI and String stuff
    $WinMain = GUICreate('Encryption for DSCV3', 400, 400)
    ; Creates window
    $EditText = GUICtrlCreateEdit('', 5, 5, 380, 350)
    ; Creates main edit
    $InputPass = GUICtrlCreateInput('', 5, 360, 100, 20)
    ; 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)
    ; 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
                GENERATEKEYDSCV3(GUICtrlRead($InputPass), $KEY)
                GUICtrlSetData($EditText, DSCV3($string, $KEY, 1))
                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
                GENERATEKEYDSCV3(GUICtrlRead($InputPass), $KEY)
                GUICtrlSetData($EditText, DSCV3($string, $KEY, 0))
                GUISetState(@SW_ENABLE, $WinMain) ; This turns the window back on
        EndSwitch
    WEnd ; Continue loop untill window is closed
    Exit
EndFunc   ;==>_Main

Func GENERATEKEYDSCV3($PHRASE, ByRef $CASE)
    Local $A, $B, $I, $SWAP, $TEMP, $PLEN, $TLEN = 256, $KEY[256]
    Dim $CASE[256] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 255, 256, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,255]
    $PLEN = StringLen($PHRASE)
    For $A = 0 To 255
        $KEY[$A] = Asc(StringMid($PHRASE, Mod($A, $PLEN) + 1, 1)) + BitAND($PLEN, $A)
    Next
    While $TLEN < $PLEN
        For $A = 0 To 255
            $KEY[$A] = Asc(StringMid($PHRASE, Mod($A, $PLEN) + $TLEN + 1, 1)) + BitAND($PLEN, $KEY[$A])
        Next
        $TLEN += 256
    WEnd
    For $I = 1 To 2
        For $A = 0 To 255
            $B = Mod(($B + $CASE[$A] + $KEY[$A]), 256)
            $SWAP = $CASE[$A]
            $CASE[$A] = $CASE[$B]
            $CASE[$B] = $SWAP
        Next
    Next
EndFunc   ;==>GENERATEKEYDSCV3

Func DSCV3($DATA, $KEY, $ENCRYPT)
    Local $CIPHERBY, $CIPHER, $CHECK, $A, $B, $I, $J, $K
    If $ENCRYPT Then
        For $A = 1 To StringLen($DATA)
            $I = Mod(($I + 1), 256)
            $J = Mod(($J + $KEY[$I]), 256)
            $K = $KEY[Mod(($KEY[$I] + $KEY[$J]), 256)]
            $CIPHERBY = BitXOR(Asc(StringMid($DATA, $A, 1)), $K)
            $CIPHER &= Hex($CIPHERBY, 2)
        Next
        Return $CIPHER
    Else
        For $A = 1 To StringLen($DATA) Step 2
            $I = Mod(($I + 1), 256)
            $J = Mod(($J + $KEY[$I]), 256)
            $K = $KEY[Mod(($KEY[$I] + $KEY[$J]), 256)]
            $CIPHERBY = BitXOR(Dec(StringMid($DATA, $A, 2)), $K)
            $CIPHER &= Chr($CIPHERBY)
        Next
        Return $CIPHER
    EndIf
EndFunc   ;==>DSCV3

Edited by athiwatc

Share this post


Link to post
Share on other sites
Andreik

If you are satisfied with this encryption is ok. If I don't have any encryption method I`ll use this. ;)

Like example is good. :D

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites
Andreik

Search on forum about RC4, maybe you will be inspired and a new encryption method will rising. ;)


When the words fail... music speaks

Share this post


Link to post
Share on other sites
Andreik

One more thing. You cannot encrypt/decrypt photos. Try to open files binary and then encrypt/decrypt.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
WolfWorld

One more thing. You cannot encrypt/decrypt photos. Try to open files binary and then encrypt/decrypt.

AND THIS IS THE LIMIT OF OF SCRIPT, ITS JUST TOOOOO SLOW!!

I will try to make a Delphi version or MASM32

and is there anyway to use asm in autoit??

Edited by athiwatc

Share this post


Link to post
Share on other sites
Andreik

For text documents I write a simple cipher, maybe you can inspire for the future encryption system.

Func FilterXOR($STRING,$NUM=5)
    Local $INDEX,$RESULT=""
    For $INDEX = 1 To StringLen($STRING)
        $RESULT &= Chr(BitXOR(Asc(StringMid($STRING,$INDEX,1)),$NUM))
    Next
    Return $RESULT
EndFunc

Func Cipher($DATA,$PASSWORD,$OPT=0)
    Local $INDEX,$RESULT="",$L1,$L2,$CARRY,$PWD
    $L1 = StringLen($DATA)
    $L2 = StringLen($PASSWORD)
    If $L1 < $L2 Then SetError(1,0,0)
    $CARRY = Mod($L1,$L2)
    For $INDEX = 1 To Int($L1/$L2)
        $PWD &= $PASSWORD
    Next
    $PWD &= StringLeft($PASSWORD,$CARRY)
    For $INDEX = 1 To $L1
        If $OPT = 0 Then
            $RESULT &= Chr(Asc(StringMid($DATA,$INDEX,1))+Asc(StringMid($PWD,$INDEX,1)))
        ElseIf $OPT = 1 Then
            $RESULT &= Chr(Asc(StringMid($DATA,$INDEX,1))-Asc(StringMid($PWD,$INDEX,1)))
        EndIf
        GUICtrlSetData($PROGRESS,$INDEX*100/$L1)
    Next
    Return $RESULT
EndFunc

$GUI = GUICreate("File Encrypt/Decrypt",300,150,-1,-1)
$OPEN = GUICtrlCreateInput(@ScriptDir,5,5,250,20)
$B1 = GUICtrlCreateButton("..",270,5,20,20)
$SAVE = GUICtrlCreateInput(@ScriptDir,5,30,250,20)
$B2 = GUICtrlCreateButton("..",270,30,20,20)
$CODE = GUICtrlCreateInput("",100,55,100,20,BitOR(0x0001,0x0020))
$ENC = GUICtrlCreateButton("ENCRYPT",5,80,100,20)
$DEC = GUICtrlCreateButton("DECRYPT",195,80,100,20)
$PROGRESS = GUICtrlCreateProgress(5,110,290,30)
ControlDisable("File Encrypt/Decrypt","",$PROGRESS)
GUISetState(@SW_SHOW,$GUI)

While 1
    $MSG = GUIGetMsg()
    Switch $MSG
        Case $B1
            $FILE = FileOpenDialog("OPEN",@ScriptDir,"All (*.*)",1)
            GUICtrlSetData($OPEN,$FILE)
        Case $B2
            $FILE = FileSaveDialog("SAVE",@ScriptDir,"All (*.*)")
            GUICtrlSetData($SAVE,$FILE)
        Case $ENC
            $FILE_OPEN = FileOpen(GUICtrlRead($OPEN),0)
            $DATA = FileRead($FILE_OPEN)
            FileClose($FILE_OPEN)
            ControlEnable("File Encrypt/Decrypt","",$PROGRESS)
            $CIPHER = FilterXOR(Cipher($DATA,GUICtrlRead($CODE),0),5)
            ControlDisable("File Encrypt/Decrypt","",$PROGRESS)
            $FILE_SAVE = FileOpen(GUICtrlRead($SAVE),2)
            FileWrite($FILE_SAVE,$CIPHER)
            FileClose($FILE_SAVE)
        Case $DEC
            $FILE_OPEN = FileOpen(GUICtrlRead($OPEN),0)
            $DATA = FileRead($FILE_OPEN)
            FileClose($FILE_OPEN)
            ControlEnable("File Encrypt/Decrypt","",$PROGRESS)
            $CIPHER = Cipher(FilterXOR($DATA,5),GUICtrlRead($CODE),1)
            ControlDisable("File Encrypt/Decrypt","",$PROGRESS)
            $FILE_SAVE = FileOpen(GUICtrlRead($SAVE),2)
            FileWrite($FILE_SAVE,$CIPHER)
            FileClose($FILE_SAVE)
        Case -3
            Exit
    EndSwitch
    Sleep(20)
WEnd

When the words fail... music speaks

Share this post


Link to post
Share on other sites
WolfWorld

Its very nice but I have to say its very very weak(Sorry) encryption that password 111 and 1111 is the same

the password 111 and 112 give some of the text out

This is very weak because you can randomly generate a password about 1000 of them and take the char that is the most common of everyone of them and you will get the original text, then after that you can use the different to generate the password

--------------------------------------------------------------------------------------------------------------------------

I also change from 54BIT key to 216BIT key in DSCV3 and remove the signature thing

Test file for DSCV2 is here http://skypower.axspace.com/DSCV2/test.ntxt

Have not generate DSCV3 Test file yet

Here is a test result for your encryption

http://skypower.axspace.com/aaa2.txt

In DSCV3 can encrypt text file and the size is less(the same as original thanks to you)

I think DSCV3 is very secure, much more than RC4(A LOT) that its originally from

UPDATED DSCV3 and sorry i used your gui if you dont like it I will remove it

Share this post


Link to post
Share on other sites
Andreik

Its very nice but I have to say its very very weak(Sorry) encryption that password 111 and 1111 is the same

the password 111 and 112 give some of the text out

This is very weak because you can randomly generate a password about 1000 of them and take the char that is the most common of everyone of them and you will get the original text, then after that you can use the different to generate the password

--------------------------------------------------------------------------------------------------------------------------

I also change from 54BIT key to 216BIT key in DSCV3 and remove the signature thing

Test file for DSCV2 is here http://skypower.axspace.com/DSCV2/test.ntxt

Have not generate DSCV3 Test file yet

Here is a test result for your encryption

http://skypower.axspace.com/aaa2.txt

In DSCV3 can encrypt text file and the size is less(the same as original thanks to you)

I think DSCV3 is very secure, much more than RC4(A LOT) that its originally from

UPDATED DSCV3 and sorry i used your gui if you dont like it I will remove it

I know that is not a very strong encryption. I use only for some not important data. Exemple: Encrypt data send from server to client. If you want some very strong I saw on forum implementation in autoit for Blowfish,Rijndael. :)


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.