Jump to content
Sign in to follow this  
John117

decrypt txt file while adding to array?

Recommended Posts

John117

I am working on the following code. It is intended to decrypt a txt file line and add it to an array. -not working :P Can this be done? I just need the txt to stay encrypted, but the code to pull the info with the correct decryption . . .

; Read file into an array
_FileReadToArray($sFile, _StringEncrypt(0,$avFile, "12345", "1"))
If @error Then
    MsgBox(16, "Error", "Error opening file: " & $sFile)
    Exit
EndIf

Share this post


Link to post
Share on other sites
DW1

Hope this gets you on your way. If you have any questions, just ask. If I misunderstood your question, please let me know where I went wrong.

#include <String.au3>
#include <File.au3>
#include <Array.au3>
Dim $filecontents
Dim $decryptedfile[1]
$sFile = "C:\testenc.txt"
_FileReadToArray($sFile, $filecontents)
If @error Then
    MsgBox(16, "Error", "Error opening file: " & $sFile)
    Exit
EndIf
MsgBox(0,"test", $filecontents[0] )
$decryptedfile[0] = $filecontents[0]
For $avar = 1 to $filecontents[0]
    ReDim $decryptedfile[$avar + 1]
    $decryptedfile[$avar] = _StringEncrypt(0, $filecontents[$avar], "12345")
Next
_ArrayDisplay( $decryptedfile, "Decrypted File Contents In Array" )

Share this post


Link to post
Share on other sites
PsaltyDS

Demo of encrypt/decrypt from/to and array:

#include <array.au3>
#include <string.au3>

Global $sFile = "C:\Temp\Test.txt"
Global $avArray[10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Global $sPasswd = "12345"

Global $hFile = FileOpen($sFile, 2) ; 2 = overwrite
FileWrite($hFile, _StringEncrypt(1, _ArrayToString($avArray, Chr(01)), $sPasswd, 1))
FileClose($hFile)

Run("notepad.exe " & $sFile)

MsgBox(32, "Continue", "Ready to decrypt?")

Global $avRead = StringSplit(_StringEncrypt(0, FileRead($sFile), $sPasswd, 1), Chr(01))
_ArrayDisplay($avRead, "Debug: $avRead")

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
John117

I had hoped to beet you P :P

Working on one of your posts. ;)

#include <file.au3>
#include <guiconstants.au3>
#include <string.au3>

; Each line of file is "User Name, Password"
Global $sFile = "D:\Autoit Help\test.txt"
Global $avFile, $sPasswd = "<not found>"

; Get user name to search for
$sUser = InputBox("User Data", "Enter user name:")
If @error Then Exit

; Read file into an array
_FileReadToArray($sFile, $avFile)
If @error Then
    MsgBox(16, "Error", "Error opening file: " & $sFile)
    Exit
EndIf

; Search array for user name and get password
For $i = 1 To $avFile[0]
;The Below line decrypts at level "1" using "12345" as password. "1" Being lowest, "10" being highest.
$Temp = _StringEncrypt(0,$avFile[$i], "12345", "1")
    If StringLeft($Temp, StringLen($sUser) + 1) = $sUser & ","  Then
        $sPasswd = StringStripWS(StringMid($Temp, StringInStr($Temp, ",") + 1), 8)
        ExitLoop
    EndIf
Next

; Display results
MsgBox(64, "Results", "User:  " & $sUser & @CRLF & "Passwd:  " & $sPasswd)
Edited by Hatcheda

Share this post


Link to post
Share on other sites
John117

Hope this gets you on your way. If you have any questions, just ask. If I misunderstood your question, please let me know where I went wrong.

Hey, I'll still study it up, see what I can learn from it! Thanks always!

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  

×