gerry1 Posted August 28, 2021 Share Posted August 28, 2021 Hello! You need to encrypt only the first 10 kilobytes Here is the code for an example $a_files = _FileListToArray(@ScriptDir) For $i = 1 To $a_files[0] $rc = _Crypt_EncryptFile($a_files[$i],$a_files[$i] & ".crypt", "APASSWORD", $CALG_AES_256) If $rc Then ConsoleWrite("File " & $a_files[$i] & " has been enencrypted to " & $a_files[$i] & ".crypt" & @CRLF) Else ConsoleWrite("Error: " & @error & @CRLF) EndIf Next Link to comment Share on other sites More sharing options...
gerry1 Posted August 28, 2021 Author Share Posted August 28, 2021 this code encrypts the files completely😐 Link to comment Share on other sites More sharing options...
Nine Posted August 28, 2021 Share Posted August 28, 2021 (edited) Here. This example show how to encrypt the first 100 bytes of a readable text file. #include <Crypt.au3> Local $hFileIn = FileOpen("Test.txt", $FO_BINARY) Local $bContent = FileRead($hFileIn) Local $bFirst = BinaryMid($bContent, 1, 100) Local $bCrypt = _Crypt_EncryptData($bFirst, "APASSWORD", $CALG_AES_256) ConsoleWrite(BinaryLen($bCrypt) & @CRLF) ; note the lenght, you will need it to decrypt Local $hFileOut = FileOpen("Test2.txt", $FO_BINARY+$FO_OVERWRITE) FileWrite($hFileOut, $bCrypt) FileWrite($hFileOut, BinaryMid($bContent, 101)) FileClose($hFileIn) FileClose($hFileOut) Edited August 28, 2021 by Nine gerry1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gerry1 Posted August 28, 2021 Author Share Posted August 28, 2021 1 hour ago, Nine said: Here. This example show how to encrypt the first 100 bytes of a readable text file. #include <Crypt.au3> Local $hFileIn = FileOpen("Test.txt", $FO_BINARY) Local $bContent = FileRead($hFileIn) Local $bFirst = BinaryMid($bContent, 1, 100) Local $bCrypt = _Crypt_EncryptData($bFirst, "APASSWORD", $CALG_AES_256) ConsoleWrite(BinaryLen($bCrypt) & @CRLF) ; note the lenght, you will need it to decrypt Local $hFileOut = FileOpen("Test2.txt", $FO_BINARY+$FO_OVERWRITE) FileWrite($hFileOut, $bCrypt) FileWrite($hFileOut, BinaryMid($bContent, 101)) FileClose($hFileIn) FileClose($hFileOut) this works, but I need to do it for all the files in the directory Link to comment Share on other sites More sharing options...
Nine Posted August 28, 2021 Share Posted August 28, 2021 2 hours ago, gerry1 said: but I need to do it for all the files in the directory Just loop thru it, as you did in your OP...I am sure you can do it. gerry1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gerry1 Posted August 28, 2021 Author Share Posted August 28, 2021 41 minutes ago, Nine said: Just loop thru it, as you did in your OP...I am sure you can do it. I did so, but the speed of code execution is important for me.. tell me how to speed up the script as much as possible 😊 Link to comment Share on other sites More sharing options...
Nine Posted August 28, 2021 Share Posted August 28, 2021 Provide the final code, so we can have a look “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gerry1 Posted August 28, 2021 Author Share Posted August 28, 2021 3 minutes ago, Nine said: Provide the final code, so we can have a look #include <Array.au3> #include <File.au3> #include <Crypt.au3> $a_files = _FileListToArray(@ScriptDir) For $i = 1 To $a_files[0] Local $hFileIn = FileOpen($a_files[$i], $FO_BINARY) Local $bContent = FileRead($hFileIn) Local $bFirst = BinaryMid($bContent, 1, 100) Local $bCrypt = _Crypt_EncryptData($bFirst, "APASSWORD", $CALG_AES_256) ConsoleWrite(BinaryLen($bCrypt) & @CRLF) ; note the lenght, you will need it to decrypt Local $hFileOut = FileOpen($a_files[$i] & ".backup", $FO_BINARY+$FO_OVERWRITE) FileWrite($hFileOut, $bCrypt) FileWrite($hFileOut, BinaryMid($bContent, 101)) FileClose($hFileIn) FileClose($hFileOut) Next Link to comment Share on other sites More sharing options...
Nine Posted August 28, 2021 Share Posted August 28, 2021 That seems alright. But I wonder why you want to make backup using partly encrypted files ? gerry1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gerry1 Posted August 28, 2021 Author Share Posted August 28, 2021 2 minutes ago, Nine said: That seems alright. But I wonder why you want to make backup using partly encrypted files ? I just wanted to figure out how to encrypt a file not completely. Since I didn't find anything like this on the internet. I don't need to encrypt 10 kilobytes, I can also use a different size. Link to comment Share on other sites More sharing options...
jchd Posted August 28, 2021 Share Posted August 28, 2021 Will you need to decode such encrypted files as well? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
gerry1 Posted August 28, 2021 Author Share Posted August 28, 2021 23 minutes ago, jchd said: Will you need to decode such encrypted files as well? yes Link to comment Share on other sites More sharing options...
Nine Posted August 28, 2021 Share Posted August 28, 2021 It is just about the same script but using DecryptData. Like I wrote, as a comment in the script, the encrypted data is larger than the original data. You need to use the appropriate size. Another solution is to save the length as the first bytes of the backup file. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JockoDundee Posted August 28, 2021 Share Posted August 28, 2021 5 hours ago, gerry1 said: I just wanted to figure out how to encrypt a file not completely. Did you think there was something more complicated than encrypting part of the file and then appending the rest of original file? Code hard, but don’t hard code... 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