Jump to content

i need help with my script


Recommended Posts

ive been working on a script to encript and decript some text files and stuff

but the problom is it does not decript right can some one take a look at it and tell me whats wrong plz

if you run the script you will see what i mean

thank you

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 345, 300, 193, 115, 0, 0)
GUISetBkColor(0x808000)
$Button_encript = GUICtrlCreateButton("Encript", 256, 184, 83, 25, 0)
$Button_decript = GUICtrlCreateButton("Decript", 256, 240, 83, 25, 0)
$Button_open = GUICtrlCreateButton("opan file to cript", 256, 128, 83, 25, 0)
$Edit = GUICtrlCreateEdit("", 0, 0, 249, 273)
$Button_exit = GUICtrlCreateButton("Exit", 256, 72, 83, 25, 0)
$Label_pass = GUICtrlCreateLabel("", 266, 16, 54, 16)
GUICtrlSetBkColor(-1, 0x808000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button_open
        $get_notes = FileOpenDialog("Load notes", @ScriptDir, "Notes (*.txt)", 1 + 2, "Notes")
            If @error Then
                MsgBox(4096,"","No File(s) chosen")
                    Else
                $notes = FileRead($get_notes)
            GUICtrlSetData($Edit,$notes)
        EndIf
    Case $Button_encript
        $translate = _Encript(GUICtrlRead($Edit))
        GuiCtrlSetData($Edit, $translate)
        GUICtrlSetState($Button_encript, $GUI_DISABLE)
        GUICtrlSetState($Button_decript, $GUI_ENABLE)
    Case $Button_exit
        Exit
    Case $Button_decript
        $translate = _Decript(GUICtrlRead($Edit))
        GuiCtrlSetData($Edit, $translate)
        GUICtrlSetState($Button_decript, $GUI_DISABLE)
        GUICtrlSetState($Button_encript, $GUI_ENABLE)
    EndSwitch
WEnd


Func _Encript($text)
    ;  aA-zZ
$a = StringReplace($text, "a", "<", 0, 1)
$A = StringReplace($a, "A", ",", 0, 1)
$b = StringReplace($A, "b", ">", 0, 1)
$B = StringReplace($b, "B", "@", 0, 1)
$c = StringReplace($B, "c", ":", 0, 1)
$C = StringReplace($c, "C", "~", 0, 1)
$d = StringReplace($C, "d", "#", 0, 1)
$D = StringReplace($d, "D", "'", 0, 1)
$e = StringReplace($D, "e", "\", 0, 1)
$E = StringReplace($e, "E", "/", 0, 1)
$f = StringReplace($E, "f", "?", 0, 1)
$F = StringReplace($f, "F", "|", 0, 1)
$g = StringReplace($F, "g", ";", 0, 1)
$G = StringReplace($g, "G", "[", 0, 1)
$h = StringReplace($G, "h", "]", 0, 1)
$H = StringReplace($h, "H", "{", 0, 1)
$i = StringReplace($H, "i", "}", 0, 1)
$I = StringReplace($i, "I", "-", 0, 1)
$j = StringReplace($I, "j", "_", 0, 1)
$J = StringReplace($j, "J", "=", 0, 1)
$k = StringReplace($J, "k", "+", 0, 1)
$K = StringReplace($k, "K", "!", 0, 1)
$l = StringReplace($K, "l", "£", 0, 1)
$L = StringReplace($l, "L", "$", 0, 1)
$m = StringReplace($L, "m", "%", 0, 1)
$M = StringReplace($m, "M", "^", 0, 1)
$n = StringReplace($M, "n", "&", 0, 1)
$N = StringReplace($n, "N", "*", 0, 1)
$o = StringReplace($N, "o", "(", 0, 1)
$O = StringReplace($o, "O", ")", 0, 1)
$p = StringReplace($O, "p", ".", 0, 1)
$P = StringReplace($p, "P", "1", 0, 1)
$q = StringReplace($P, "q", "p", 0, 1)
$Q = StringReplace($q, "Q", "t", 0, 1)
$r = StringReplace($Q, "r", "o", 0, 1)
$R = StringReplace($r, "R", "h", 0, 1)
$s = StringReplace($R, "s", "i", 0, 1)
$S = StringReplace($s, "S", "j", 0, 1)
$t = StringReplace($S, "t", "l", 0, 1)
$T = StringReplace($t, "T", "r", 0, 1)
$u = StringReplace($T, "u", "e", 0, 1)
$U = StringReplace($u, "U", "q", 0, 1)
$v = StringReplace($U, "v", "w", 0, 1)
$V = StringReplace($v, "V", "y", 0, 1)
$w = StringReplace($V, "w", "u", 0, 1)
$W = StringReplace($w, "W", "3", 0, 1)
$x = StringReplace($W, "x", "2", 0, 1)
$X = StringReplace($x, "X", "6", 0, 1)
$y = StringReplace($X, "y", "8", 0, 1)
$Y = StringReplace($y, "Y", "9", 0, 1)
$z = StringReplace($Y, "z", "0", 0, 1)
$Z = StringReplace($z, "Z", "4", 0, 1)
    ;  0-9
$1 = StringReplace($Z, "1", "c", 0, 1)
$2 = StringReplace($1, "2", "s", 0, 1)
$3 = StringReplace($2, "3", "f", 0, 1)
$4 = StringReplace($3, "4", "d", 0, 1)
$5 = StringReplace($4, "5", "b", 0, 1)
$6 = StringReplace($5, "6", "g", 0, 1)
$7 = StringReplace($6, "7", "k", 0, 1)
$8 = StringReplace($7, "8", "x", 0, 1)
$9 = StringReplace($8, "9", "z", 0, 1)
$0 = StringReplace($9, "0", "m", 0, 1)
$Space = StringReplace($0, " ", "¬", 0, 1)
Return $Space
EndFunc

Func _Decript($text)
    ;aA-zZ
$a = StringReplace($text, "<", "a", 0, 1)
$A = StringReplace($a, ",", "A", 0, 1)
$b = StringReplace($A, ">", "b", 0, 1)
$B = StringReplace($b, "@", "B", 0, 1)
$c = StringReplace($B, ":", "C", 0, 1)
$C = StringReplace($c, "~", "C", 0, 1)
$d = StringReplace($C, "#", "d", 0, 1)
$D = StringReplace($d, "'", "D", 0, 1)
$e = StringReplace($D, "\", "e", 0, 1)
$E = StringReplace($e, "/", "E", 0, 1)
$f = StringReplace($E, "?", "f", 0, 1)
$F = StringReplace($f, "|", "F", 0, 1)
$g = StringReplace($F, ";", "g", 0, 1)
$G = StringReplace($g, "[", "G", 0, 1)
$h = StringReplace($G, "]", "h", 0, 1)
$H = StringReplace($h, "{", "H", 0, 1)
$i = StringReplace($H, "}", "i", 0, 1)
$I = StringReplace($i, "-", "I", 0, 1)
$j = StringReplace($I, "_", "j", 0, 1)
$J = StringReplace($j, "=", "J", 0, 1)
$k = StringReplace($J, "+", "k", 0, 1)
$K = StringReplace($k, "!", "K", 0, 1)
$l = StringReplace($K, "£", "l", 0, 1)
$L = StringReplace($l, "$", "L", 0, 1)
$m = StringReplace($L, "%", "m", 0, 1)
$M = StringReplace($m, "^", "M", 0, 1)
$n = StringReplace($M, "&", "n", 0, 1)
$N = StringReplace($n, "*", "N", 0, 1)
$o = StringReplace($N, "(", "o", 0, 1)
$O = StringReplace($o, ")", "O", 0, 1)
$p = StringReplace($O, ".", "p", 0, 1)
$P = StringReplace($p, "1", "P", 0, 1)
$q = StringReplace($P, "p", "q", 0, 1)
$Q = StringReplace($q, "t", "Q", 0, 1)
$r = StringReplace($Q, "o", "r", 0, 1)
$R = StringReplace($r, "h", "R", 0, 1)
$s = StringReplace($R, "i", "s", 0, 1)
$S = StringReplace($s, "j", "S", 0, 1)
$t = StringReplace($S, "l", "t", 0, 1)
$T = StringReplace($t, "r", "T", 0, 1)
$u = StringReplace($T, "e", "u", 0, 1)
$U = StringReplace($u, "q", "U", 0, 1)
$v = StringReplace($U, "w", "v", 0, 1)
$V = StringReplace($v, "y", "V", 0, 1)
$w = StringReplace($V, "u", "w", 0, 1)
$W = StringReplace($w, "3", "W", 0, 1)
$x = StringReplace($W, "2", "x", 0, 1)
$X = StringReplace($x, "6", "X", 0, 1)
$y = StringReplace($X, "8", "y", 0, 1)
$Y = StringReplace($y, "9", "Y", 0, 1)
$z = StringReplace($Y, "0", "z", 0, 1)
$Z = StringReplace($z, "4", "Z", 0, 1)
    ;  0-9
$1 = StringReplace($Z, "c", "1", 0, 1)
$2 = StringReplace($1, "s", "2", 0, 1)
$3 = StringReplace($2, "f", "3", 0, 1)
$4 = StringReplace($3, "d", "4", 0, 1)
$5 = StringReplace($4, "b", "5", 0, 1)
$6 = StringReplace($5, "g", "6", 0, 1)
$7 = StringReplace($6, "k", "7", 0, 1)
$8 = StringReplace($7, "x", "8", 0, 1)
$9 = StringReplace($8, "z", "9", 0, 1)
$0 = StringReplace($9, "m", "0", 0, 1)
$Space = StringReplace($0, "¬", " ", 0, 1)
Return $Space
EndFunc

thank you for helping

some of my scripts check them out and give feedback so i can learn from them :)autoclicker a autoclickernote taker a script to take notes with

Link to comment
Share on other sites

Haha, that is one interesting problem you have there. :rolleyes:

Ok, let's go through this:

Let's say you encrypt 'b' without the quotes. Encrypted this is >, following me so far? Good.

Now, let's decrypt: First > is converted to b. Then, later on, b is converted to 5 because that line is further in the program. It is a matter of order. :rambo:

Link to comment
Share on other sites

how can i fix that?

Here's a way of replacing one character with another

Dim $code[513], $codex[513]

If Not FileExists('code.ini') Then;generate a code sequence
    For $n= 1 To 512
        $code[$n] = $n
    Next

    For $n = 1 To 2000;any number really which is big enough tpo mix everything up
        $swap1 = Random(0,511,1)
        $swap2 = Random(0,511,1)
        $temp = $code[$swap1]
        $code[$swap1] = $code[$swap2]
        $code[$swap2] = $temp
    Next

    For $n = 1 To 512
        IniWrite('code.ini','translation',string($n),String($code[$n]))
    Next
Else
    ;read the premade code sequence
    For $n = 1 To 512
        $code[$n] = IniRead('code.ini','translation',string($n),'0')
    Next

EndIf

For $n=1 To 512
    
    $codex[$code[$n]] = $n;used to decode
Next


$e = Encrypt("bannanas")
MsgBox(0,'bannanas becomes',$e)

MsgBox(0,'decrypted ' & $e & ' is ',decrypt($e))


Func encrypt($ss)
    $result = ''
    For $n = 1 To StringLen($ss)
        $result = $result & Chr($code[Asc(StringMid($ss,$n,1))])
        
    Next

    Return $result
    
EndFunc

Func Decrypt($ss)
    $result = ''
    
    For $n = 1 To StringLen($ss)
        $result = $result & Chr($codex[Asc(StringMid($ss,$n,1))])
    Next
    
    Return $result
    
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

­

could you plz explain to me how it works so i can add it to my script i cant seem to understand it.

thank you

The script I wrote as an exaple for you can be seperated into two scripts.

The first one is just to create a code sequence and save it in an ini file. Once that sequence has been created this script is no use unless you want to make another sequence because it will never make the same sequence twice.( Or at least very unlikely to.)

The second part just reads the sequence then uses it to encode or decode something.

Here is the code generator

;code tags not working again=====================================================

;code generator - only run once for a new code

Dim $code[513], $codex[513] ;two arrays with 513 elements each

;actually only need 512 but I wanted to count from 1.

;512 because there are 512 possible characters

If Not FileExists('code.ini') Then;If there is no ini file then we will create a new code

;first fill the array with all the numbers, ie all the Ascii codes

For $n= 1 To 512

$code[$n] = $n

Next

;now mix them up

For $n = 1 To 2000;any number really which is big enough to mix everything up

$swap1 = Random(1,512,1);choose a random number <-- corrected, I made an error in my previous post

$swap2 = Random(1,512,1);choose another random number

$temp = $code[$swap1];now we swap them

$code[$swap1] = $code[$swap2]

$code[$swap2] = $temp

Next

;write the mixed up list of codes to the ini file

For $n = 1 To 512

;you will be able to see the result if you open the inifile in an editor

IniWrite('code.ini','translation',string($n),String($code[$n]))

Next

EndIf

;end of code generator script==============================================

Now we have a code list which we can use to encode and decode things. Someone needs this file to decode the text which was generated using the same file.

The idea of the list is that when you want to write 'a message', you take each character in turn from the start of the string and generate its ascii code. ;This will be a number from 1 to 512. Suppose it is the letter A, then the Ascii code is 65 so the encoded number for 'A' is $code[65] which will probably be something different.

To use the code created by the script above -

;start1==================================================================

If not FileExists("code.ini") then

msgbox(0,'Error','there is no code file!')

exit;;we can't go on like this

endif

;if the ini file exist then just read the list

For $n = 1 To 512

$code[$n] = IniRead('code.ini','translation',string($n),'0')

Next

;but we need an easy way to convert codes backwards and that's what this bit is for

For $n=1 To 512

$codex[$code[$n]] = $n

Next

;so if the value of $code[17] is 96, then $codex[96] = 17.

$e = Encrypt("bannanas")

MsgBox(0,'bannanas becomes',$e)

MsgBox(0,'decrypted ' & $e & 'is',decrypt($e))

Func encrypt($ss)

$result = ''

For $n = 1 To StringLen($ss); for each character in the string to encrypt

$char = StringMid($ss,$n,1); this is the next character

$ascii = Asc($char); the ascii code for the character

$translated = $code[$ascii]; now it's converted using our code

$newchar = Chr($code[$Ascii]);The character represented by the new Ascii code

$result = $result & $newchar; Add the new character to the encoded string

Next

Return $result

EndFunc

Func Decrypt($ss)

$result = ''

For $n = 1 To StringLen($ss)

$char = StringMid($ss,$n,1); next character

$charcode = Asc($char); the Ascii code for the character

$translatedback = $codex[$charcode]; the original Ascii code

$newchar = Chr($translatedback); the original character

$result = $result & $newchar)

Next

Return $result

EndFunc

;end1==============================================

Although this is a simple way to encrypt text, if you used it like this next example then it would be difficult to crack, and for short messages, extremely difficult.

;start2++++++++++++++++++++++++++++++++++

$text = fileread("sometextfile.txt")

Filewrite("codedtext.txt",encrpt($text))

;then to get the text back

$coded = FileRead("codedtext.txt")

Filewrite("recovered.txt",decrypt($coded))

;end2++++++++++++++++++++++++++++++++++++

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
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
 Share

  • Recently Browsing   0 members

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