Sign in to follow this  
Followers 0
jessem

Read file lines, one letter at a time.

6 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I wish my school taught a programming language. *Jealous*

I would love that class :whistle: , 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 :P

Edited by Paulie

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I wish my school taught a programming language. *Jealous*

I would love that class :whistle: , 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 :P

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 later

so 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 :D

basically, i need to try a new method, but i will get it done.

as it truns out, "stringreplacing" won't be the best method

however, i reliquish my "dibs" to anyone else with an idea

Edited by Paulie

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Maybe something like...

; _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 by xcal

Share this post


Link to post
Share on other sites

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!

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  
Followers 0