Jump to content

StringReplace Func Returns 0...


layer
 Share

Recommended Posts

Hate to use it in this, but here ya go:

#include <GUIConstants.au3>
GUICreate ("AutoEncrypt", 400, 300)
GUISetState (@SW_SHOW)
$input= GUICtrlCreateInput ("", 10, 50)
$outcome= GUICtrlCreateInput ("", -1, 100)
GUICtrlCreateLabel ("Type what you want Encrypted or Decrypted:", 10, 20)
GUICtrlCreateLabel ("Results:", -1, 75)
$e= GUICtrlCreateButton ("Encrypt", 10, 150)
$d= GUICtrlCreateButton ("Decrypt", 10, 200)
While 1
  $get= GUIGetMsg ()
Select
Case $get= $GUI_EVENT_CLOSE
  ExitLoop
Case $get= $e
 $encrypted= Encrypt (GUIRead($input))
 GUICtrlSetData ($outcome, $encrypted, 1)
Case $get= $d
 $encrypted= Decrypt (GUIRead($input))
 GUICtrlSetData ($outcome, $encrypted, 1)
EndSelect
WEnd


Func Encrypt ($myen)
$replace= StringSplit ("&,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", ",")
$keys= StringSplit    ("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,&", ",")
for $i=1 to 27
$myen= StringReplace ($myen, $keys[$i], $replace[$i])
next
return $myen
EndFunc

Func DEcrypt ($myen)
$replace= StringSplit ("&,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", ",")
$keys= StringSplit    ("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,&", ",")
for $i= 27 to 1 step -1
$myen= StringReplace ($myen, $replace[$i], $keys[$i])
next
return $myen
EndFunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Sorry Layer, Used 99% of your Gui, and your theory.

Simple encryption can be fun:

$x="Hello there"
$y=funcrypt($x,13); see what 0 does :)
msgbox(1,$x,$y)
$y=funcrypt($y,-13)
msgbox(1,$x,$y)

func funcrypt($_in,$_offset)
$temp=""
for $i= 1 to StringLen($_in)
$temp= chr(asc(Stringleft($_in,$i))+$_offset) & $temp 
$_in=stringtrimleft($_in,1)
next
return $temp
endfunc
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Could someone post the .exe version of the script that scriptkitty finished...Im at my cusins and they won't let me download autoit (they don't let me download anything) so it MUST be the .EXE version...Thanks! :)

FootbaG
Link to comment
Share on other sites

this is your gui one. Compiled, no password, decompile to check that I am honest.

Funny won't let you download a known program from a know site, but would let you run code that some anonymous guy made?

I guess you mean they don't want anything installed on thier computers.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

On a side note, this is your first code fixed:

#include <GUIConstants.au3>
GUICreate ("AutoEncrypt", 400, 300)
GUISetState (@SW_SHOW)
$input= GUICtrlCreateInput ("", 10, 50)
$outcome= GUICtrlCreateInput ("", -1, 100)
GUICtrlCreateLabel ("Type what you want Encrypted or Decrypted:", 10, 20)
GUICtrlCreateLabel ("Results:", -1, 75)
$e= GUICtrlCreateButton ("Encrypt", 10, 150)
$d= GUICtrlCreateButton ("Decrypt", 10, 200)
While 1
  $get= GUIGetMsg ()
Select
Case $get= $GUI_EVENT_CLOSE
  ExitLoop
Case $get= $e
 $encrypted= Encrypt (GUIRead($input))
 GUICtrlSetData ($outcome, $encrypted, 1)
EndSelect
WEnd
  Func Encrypt ($a)
     $a= StringReplace ($a,  "a", "@")
     $a= StringReplace ($a,  "b", "a")
     $a= StringReplace ($a,  "c", "b")
     $a= StringReplace ($a,  "d", "c")
     $a= StringReplace ($a,  "e", "d")
     $a= StringReplace ($a,  "f", "e")
     $a= StringReplace ($a,  "g", "f")
     $a= StringReplace ($a,  "h", "g")
     $a= StringReplace ($a,  "i", "h")
     $a= StringReplace ($a,  "j", "i")
     $a= StringReplace ($a,  "k", "j")
     $a= StringReplace ($a,  "l", "k")
     $a= StringReplace ($a,  "m", "l")
     $a= StringReplace ($a,  "n", "m")
     $a= StringReplace ($a,  "o", "n")
     $a= StringReplace ($a,  "p", "o")
     $a= StringReplace ($a,  "q", "p")
     $a= StringReplace ($a,  "r", "q")
     $a= StringReplace ($a,  "s", "r")
     $a= StringReplace ($a,  "t", "s")
     $a= StringReplace ($a,  "u", "t")
     $a= StringReplace ($a,  "v", "u")
     $a= StringReplace ($a,  "w", "v")
     $a= StringReplace ($a,  "x", "w")
     $a= StringReplace ($a,  "y", "x")
     $a= StringReplace ($a,  "z", "y")
     $a= StringReplace ($a,  "@", "z")
     Return $a
  EndFunc

Still wasteful, but thought you might think of it more as your own.

edit.. I left decrypting up to you...(not hard, just think you should take a crack at it)

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Thanks scriptkitty! =D I really appreciate it. = D

Nah, your right, it's just that there computer lags soooooo much when they run some programs...They blame it on me, they have like so much free space on there computer too. It sucks for them though =) And I showed thwem the code too let them know it was safe.

THANSK!

FootbaG
Link to comment
Share on other sites

Thanks scriptkitty! =D I really appreciate it. = D

Nah, your right, it's just that there computer lags soooooo much when they run some programs...They blame it on me, they have like so much free space on there computer too. It sucks for them though =) And I showed thwem the code too let them know it was safe.

THANSK!

<{POST_SNAPBACK}>

Paranoid people :) . Probably noobies.
Link to comment
Share on other sites

Guest Py7|-|[]/\/

Func Encrypt (ByRef $en)

This part of your originally posted code uses the variable $en which you do not include anywhere else. Your GUIRead is giving you an error because it is reading a different variable that is not used and this is screwing you up =)

Link to comment
Share on other sites

There were quite a few problems, But that is what this forum is for, learning and fixing.

Making good code doesn't come overnight, it comes to some folks easier than others.

One problem was taking good advice that wasn't fully understood and implementing it. But that is how you learn, if it worked out on your first try you might never understand when it wouldn't work.

You could say was just typed the wrong line in this part.

(Note this uses 26 variables instead of one and is not clean code)

$a=StringReplace ($a, "b", "a") ; see how $a changes and keeps only one variable?

Func Encrypt (ByRef $en)

    $a= StringReplace ($en, "a", "@")

    $b= StringReplace ($a, "b", "a")

    $c= StringReplace ($b, "c", "b")

    $d= StringReplace ($c, "d", "c")

    $e= StringReplace ($d, "e", "d")

    $f= StringReplace ($e, "f", "e")

    $g= StringReplace ($f, "g", "f")

    $h= StringReplace ($g, "h", "g")

    $i= StringReplace ($h, "i", "h")

    $j= StringReplace ($i, "j", "i")

    $k= StringReplace ($j, "k", "j")

    $l= StringReplace ($k, "l", "k")

    $m= StringReplace ($l, "m", "l")

    $n= StringReplace ($m, "n", "m")

    $o= StringReplace ($n, "o", "n")

    $p= StringReplace ($o, "p", "o")

    $q= StringReplace ($p, "q", "p")

    $r= StringReplace ($q, "r", "q")

    $s= StringReplace ($r, "s", "r")

    $t= StringReplace ($s, "t", "s")

    $u= StringReplace ($t, "u", "t")

    $v= StringReplace ($u, "v", "u")

    $w= StringReplace ($v, "w", "v")

    $x= StringReplace ($w, "x", "w")

    $y= StringReplace ($x, "y", "x")

    $z= StringReplace ($y, "z", "y")

  $en=  StringReplace ($y, "@", "z");Return $en

; since it is done by ref, it wouldn't need a return.

; scriptkitty does not endorse the above code. :)

endfunc

Note there are other parts of the first code that also needed changes to have this work.

I don't like to keep posting this, because others might use this to learn by, and much better code would be prefered by myself to use as a teaching tool.

heh heh so many disclaimers... Hope I am not comming off too harsh...

Edit... ok, an example of why you might use return with a ByRef:

$x="bob goes to town"
$test=0
MsgBox(1,"Encrypt",Encrypt ($x)); note, sometimes it is good to also return a value
$x="bob goes to town"
$test=1
MsgBox(1,"Encrypt",Encrypt ($x)); note, sometimes it is good to also return a value
$x="bob goes to town"

MsgBox(1,"Encrypt",$x)

Func Encrypt (ByRef $en)
    $en= StringReplace ($en, "Bob", "Sam")
If $test=1 Then Return $en; why did I use return on a ByRef value?
EndFunc
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

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...