Jump to content

Filewrite multiple lines


 Share

Recommended Posts

Hello

my script:

Func aktivace()
$klic = InputBox("Aktivace","","","",200,150,0)
Switch $klic
  case 0

    FileOpen(@UserProfileDir & "\xxx.txt",2)
    $filedecrypt=_StringEncrypt(0,$klic,"abc")
    FileWrite(@UserProfileDir & "\xxx.txt",$filedecrypt)

  case 1
   Exit
EndSwitch 
EndFunc

so i want to decrypt string from inputbox

the problem is if the string to decrypt contais multiple lines, then script doesn´t write anything (encrypted strinng is always one line, if I'm correct)

thanks for advice

Link to comment
Share on other sites

  • Moderators

krboun,

if the string to decrypt contais multiple lines

But you are using an InputBox to get the string - by definition you cannot get multiple lines from an Input control. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

yes i know, look at _StringEncrypt in help there is example

e.g. i have a string containng a few lines of text, then i use _StringEncrypt(1,....) to engcrypt that multiple lines string. This function returns only 1 line of encrypted string always. This one line string i need to decrypt and filewrite with my script above.

Is it clear now?

Link to comment
Share on other sites

  • Moderators

krboun,

_StringEncrypt is pretty much deprecated nowadays - use the Crypt UDF instead. ;)

#include <Crypt.au3>

_Crypt_Startup() ; To optimize performance start the crypt library.

$sString = "Line 1" & @CRLF & "Line 2" & @CRLF & "line 3"

ConsoleWrite($sString & @CRLF)

Local $bEncrypted = _Crypt_EncryptData($sString, "fred", $CALG_RC4) ; Encrypt the text

ConsoleWrite($bEncrypted & @CRLF)

Local $bPlainText = _Crypt_DecryptData($bEncrypted, "fred", $CALG_RC4) ; Decrypt the text

ConsoleWrite(BinaryToString($bPlainText) & @CRLF)

_Crypt_Shutdown() ; Shutdown the crypt library.

As you can see it handles multiple lines without a problem:

Line 1
Line 2
Line 3
0xDB1560D4FA1209FAE8B619903D10E4948759174129A7
Line 1
Line 2
Line 3

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

i think i need something a little different

my text file:

fred
luis
peter

this file i encrypt with _StringEncrypt function, output from this function is one long string and this string i put to inputbox (first post here)

now i need to decrypt that long string again with _StringEncrypt function (different params of course), so output shoud be 3 lines with names, and that names i need to write to new file with 3 lines

i dont understand why but my script (from the first post here) doesn´t work

Edited by krboun
Link to comment
Share on other sites

  • Moderators

krboun,

I am confused. :)

this file i encrypt with _StringEncrypt function, output from this function is one long string and this string i put to inputbox

You want to write the encrypted string to the InputBox? What on earth for? ;)

Please try and explain in detail what you are trying to do instead of just posting a short snippet of code that does not work. What I understand so far: You have a text file with names on several lines - you want to encrypt it and get back the separate lines when you decrypt, which is what the code I gave you above does. Where does the InputBox come into the picture? What does the user enter into the InputBox? How does this user input interact with the file?

I am sure we can do what you want with the Crypt UDF - as I said before _StringEncrypt should not be used nowadays. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I think the encryption is a red herring. Choose a file handling method. Either FileOpen() and use the handle, or don't use FileOpen() and just refer to the string file path. Like this:

Func aktivace()
Local $klic, $hFile, $sFiledecrypt
; Get encrypted string
$klic = InputBox("Aktivace", "", "", "", 200, 150, 0)
Switch $klic
  Case 0
   $hFile = FileOpen(@UserProfileDir & "xxx.txt", 2)
   $sFiledecrypt = _StringEncrypt(0, $klic, "abc")
   FileWrite($hFile, $sFiledecrypt)
   FileClose($hFile)
  Case Else
   Exit
EndSwitch
EndFunc   ;==>aktivace

:)

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
Link to comment
Share on other sites

oh, i am sorry forget it, i think mistake is somewhere here :)

i just wanted to make simple progam which makes and reads crypted messages. I do not have any special reason to do that, i just study Autoit

Also i studyed encption at my school so i wanted to to genarate a key which would allow to run program only at specific one PC, so i based that key on motherboard ID.

i am amateur and autodidact so my questions could be confused and the answer so simple ;)

thakns for answers, i think i pregressed

Edited by krboun
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...