jessem Posted April 2, 2007 Share Posted April 2, 2007 Pardon the dialog, but I feel it's important for the request. I'm a tech at a school school district and have a few kids (middle school) very interested in programming. I've suggested AutoIt as a great start to learn all of the fundimentals of programming. I've shown them a few things to get there feet wet, but I would like to show them something middle school boys would get excited about. Passwords and Encryption. We have made hotkeys that call a function that contains an input box that asks for a password. Now I would like to call a second function to encrypt a file using Switch/Case. i.e. Switch ($char(tolower)) Case $char = "a" Then $char = "c" etc. Ok, the question. Is it possible to do this without using FileReadLine into a stream? Is there a way to read a .txt file one char space at a time? And of course is there a 'tolower' and 'toupper' option in AutoIt? Thank you for your time. Link to comment Share on other sites More sharing options...
Paulie Posted April 2, 2007 Share Posted April 2, 2007 (edited) I wish my school taught a programming language. *Jealous* I would love that class , and its nice to see you chose Autoit as an intro Programming Language. Anyway, There are several functions much better suited to your request. In this example, I would look into "StringReplace" And in regards to "toupper"/"tolower" (I'm assuming Upper/Lower Case?) if yes Try "Stringupper" and "Stringlower" For this method of encryption, you are basically transposing the alphabet? For example: a=c b=d ... i=k etc. etc. I'll get my code up in a minute, but I just want to have "dibs" on this answer Edited April 2, 2007 by Paulie Link to comment Share on other sites More sharing options...
xcal Posted April 2, 2007 Share Posted April 2, 2007 I don't want to step on Paulie's 'dibs' so here's only a hint. For $i = 97 To 122 ConsoleWrite(@LF & Chr($i)) Next ConsoleWrite(@LF) ConsoleWrite(@LF) How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
Paulie Posted April 2, 2007 Share Posted April 2, 2007 (edited) I wish my school taught a programming language. *Jealous*I would love that class , and its nice to see you chose Autoit as an intro Programming Language.Anyway, There are several functions much better suited to your request. In this example, I would look into "StringReplace"And in regards to "toupper"/"tolower" (I'm assuming Upper/Lower Case?) if yes Try "Stringupper" and "Stringlower"For this method of encryption, you are basically transposing the alphabet? For example:a=c b=d ... i=k etc. etc.I'll get my code up in a minute, but I just want to have "dibs" on this answer LOL umm... I lied, I seem to be running into many problems with circular logic with what i'm attempting to do. :">my main problem is that as the string transposes, it ends up re transposing what it has already done, because it goes through every character and replaces it with one thats 2 letters laterso it encrypts a=c, but then when it gets to "c", it encrypts that "c" into a "e", and then to a "g", etc. until it loops around. and you end up with the exact same string as when you started basically, i need to try a new method, but i will get it done.as it truns out, "stringreplacing" won't be the best methodhowever, i reliquish my "dibs" to anyone else with an idea Edited April 2, 2007 by Paulie Link to comment Share on other sites More sharing options...
xcal Posted April 3, 2007 Share Posted April 3, 2007 (edited) Maybe something like... expandcollapse popup; _encrypt($string, $opt) ; $opt = 1 for encrypt, 0 for unencrypt $input = InputBox('', 'input some string') $encrypted = _encrypt ($input) MsgBox(0, 'encrypted...', $encrypted) $unencrypted = _encrypt($encrypted, 0) MsgBox(0, 'unencrypted...', $unencrypted) Func _encrypt($arg1, $arg2 = 1) Local $raw = '', $enc_nums = '', $enc_result = '', $init = StringSplit($arg1, '') For $i = 1 To UBound($init) - 1 $raw &= Asc($init[$i]) & '|' Next Local $pre_alpha = StringSplit($raw, '|') Switch $arg2 Case 1 For $i = 1 To $pre_alpha[0] If $pre_alpha[$i] = 121 Then $pre_alpha[$i] = 97 ContinueLoop ElseIf $pre_alpha[$i] = 122 Then $pre_alpha[$i] = 98 ContinueLoop Else $pre_alpha[$i] = $pre_alpha[$i] + 2 EndIf Next Case 0 For $i = 1 To $pre_alpha[0] If $pre_alpha[$i] = 97 Then $pre_alpha[$i] = 121 ContinueLoop ElseIf $pre_alpha[$i] = 98 Then $pre_alpha[$i] = 122 ContinueLoop Else $pre_alpha[$i] = $pre_alpha[$i] - 2 EndIf Next EndSwitch For $i = 1 To $pre_alpha[0] $enc_nums &= $pre_alpha[$i] & '|' Next $enc_nums = StringTrimRight($enc_nums, 3) $pre_enc_alpha = StringSplit($enc_nums, '|') For $i = 1 To $pre_enc_alpha[0] $enc_result &= Chr($pre_enc_alpha[$i]) Next Return $enc_result EndFunc edit - added unencrypt option. Edited April 3, 2007 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
jessem Posted April 3, 2007 Author Share Posted April 3, 2007 Excelent. I'll take this and try to make a basic Case structure with it. I'll post my over easy version of this in a bit. Thank you guys for the help! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now