Jump to content

Recommended Posts

Posted (edited)

Hello i'm learning a little of cryptography only for educationals purporses. In my case i'm only trying to encrypt a easy string any string and then decrypt it and show it.

The code is:

ConsoleWrite(EnDeCrypt("What i am doing wrong","1234"))


;To ENcrypt and to DEcrypt your data.
Func EnDeCrypt($plaintxt, $psw)
    Local $a, $b, $i, $j, $k, $cipherby, $cipher
    Local $tempSwap, $temp, $intLength
    Local $sbox[256]
    Local $key[256]

    $intLength = StringLen($psw)
    For $a = 0 To 255
        $key[$a] = asc(Stringmid($psw, Mod($a ,$intLength)+1, 1))
        $sbox[$a] = $a
    Next

    $b = 0
    For $a = 0 To 255
        $b = Mod(($b + $sbox[$a] + $key[$a]),256)
        $tempSwap = $sbox[$a]
        $sbox[$a] = $sbox[$b]
        $sbox[$b] = $tempSwap
    Next

    For $a = 1 To StringLen($plaintxt)
        $i = Mod(($i + 1) ,256)
        $j = Mod(($j + $sbox[$i]) ,256)
        $k = $sbox[Mod(($sbox[$i] + $sbox[$j]) , 256)]

        $cipherby = BitXOR(Asc(StringMid($plaintxt, $a, 1)) , $k)
        $cipher = $cipher & Chr($cipherby)
    Next
    
    Return $cipher
EndFunc

Never write me the encrypted and decrypted string in console., only for string nothing bad.. thx!

Edited by SoyArcano

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...