Sign in to follow this  
Followers 0
Erik.

Encrypt and decrypt

20 posts in this topic

Hello,

For my program i want to add a little thing that encrypt and decrypt all the files the program makes..

How to do that so other people can not read the file whit wordpad or something like that?

Could you give me a solution how to do that?

I needs to decrypt when the program starts and encrypt when the program will be closed.

Please help me.

Greatzz Erik


I little problem, hard to find and fix

Share this post


Link to post
Share on other sites



I'm pretty sure your only option is _StringEncrypt().. that will be overwhemingly long for a whole file but I think that's the only way to do it.


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Will try thanks!

Can you encrypt a file whit it?

Edited by Erik.

I little problem, hard to find and fix

Share this post


Link to post
Share on other sites

You can encrypt a string, not a file.

I don't think you need to encrypt all your variables.. ?


Sorry for my Bad English.

Share this post


Link to post
Share on other sites

I realsy want to encrypt a file not a string...


I little problem, hard to find and fix

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I haven't tried this one but maybe it will work :whistle:

should be something like this :

$value1 = FileRead("filename.txt")

FileWrite("encrypt.txt", _StringEncrypt($value1))

Or maybe adding a loop with reading ??

Edited by mrbond007

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi,

i will try it.

there are 2 ways to encrypt.

One is encrypt the whole file so you never can open it and read it or encrypt the data that is into the file.

It does not matter what way but it must be crypted.

EDIT:

C:\Nieuw - AutoIt v3 Script.au3 (12) : ==> Unknown function name.:

FileWrite("C:\encrypt.txt", _StringEncrypt($value1))

FileWrite("C:\encrypt.txt", ^ ERROR

Edited by Erik.

I little problem, hard to find and fix

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Found something:

http://www.autoitscript.com/forum/index.ph...l=file++encrypt

I only don't know how to edit it so i can use it into my script.

It does not work what i want.

Could some try to make a little code that can encrypt data into a file?

When you open the file when it is encrypted you can not read it anymore..

And also an decryptor:P

Edited by Erik.

I little problem, hard to find and fix

Share this post


Link to post
Share on other sites

Hi,

I have found this:

Opt("TrayIconDebug",1)

$INPUT = FileOpen(FileOpenDialog("File To Encrypt","c:\","All (*.*)",7),0)

global $key[27][27]

$letters = StringSplit("abcdefghijklmnopqrstuvwxyz","")

$x = 1

while $x <= 26

$key[$x][1] = $letters[$x]

if $key[$x][2] = "" then

$cypher = InputBox("Key","What letter would you like to replace " & $letters[$x] & " with?",$letters[26 - ($x-1)])

$key[$x][2] = $cypher

EndIf

for $y = 1 to $x-1

if $key[$y][2] = $cypher Then

$key[$y][2] = ""

$key[$x][2] = $cypher

$x = $y-1

MsgBox(0,"error","You already had " & $cypher & " assigned to " & $key[$y][1] & ". That assignment has been removed")

ExitLoop

Else

$key[$x][2] = $cypher

EndIf

Next

$x = $x + 1

WEnd

$output = FileOpen(FileSaveDialog("Output File","c:\","All (*.*)"),2)

While 1

$chars = FileRead($input, 1)

if @error = -1 then ExitLoop

$chars = enc($chars)

FileWrite($output,$chars)

Wend

FileWrite($output,@crlf)

for $z = 1 to 25

FileWriteLine($output,$key[$z][2])

Next

FileClose($input)

FileClose($output)

Func enc($blah)

if $blah = " " then Return " "

if $blah = "." then return "."

if $blah = "?" then Return "?"

if $blah = "!" then Return "!"

if $blah = "-" then Return "-"

FOR $X = 1 to 26

if $key[$x][1] = StringLower($blah) then Return $key[$x][2]

Next

EndFunc

I have tried it and it works fine

I only need to say what letter it must be replaced.

This is a encryption but how to decrypt this?

Could someone help me please?

I don't need that messagebox i want to use the standard. a=z b=y etc..

Please help me


I little problem, hard to find and fix

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

there is no 'only' way to do anything. worst case scenario you can implement your own encryption, or a third party encryption. if you're encrypting whole files, you could just find a free XOR encryption program that executes via command line and fileinstall() it into your script for a more than reasonably secure encryption. Then throw a password on your script so that you have to enter a password to open it, and it uses the installed file with a password passed via command line to display files.

***edit***

here are some pre-made encryption solutions you could implement.

Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Hi,

I have found this:

Opt("TrayIconDebug",1)
$INPUT = FileOpen(FileOpenDialog("File To Encrypt","c:\","All (*.*)",7),0)
global $key[27][27]
$letters = StringSplit("abcdefghijklmnopqrstuvwxyz","")
$x = 1
while $x <= 26
    $key[$x][1] = $letters[$x]
    if $key[$x][2] = "" then
        $cypher = InputBox("Key","What letter would you like to replace " & $letters[$x] & " with?",$letters[26 - ($x-1)])
        $key[$x][2] = $cypher
    EndIf
    for $y = 1 to $x-1
        if $key[$y][2] = $cypher Then
            $key[$y][2] = ""
            $key[$x][2] = $cypher
            $x = $y-1
            MsgBox(0,"error","You already had " & $cypher & " assigned to " & $key[$y][1] & ".  That assignment has been removed")
            ExitLoop
        Else
            $key[$x][2] = $cypher
        EndIf
    Next
    $x = $x + 1
WEnd
$output = FileOpen(FileSaveDialog("Output File","c:\","All (*.*)"),2)
While 1
    $chars = FileRead($input, 1)
    if @error = -1 then ExitLoop
    $chars = enc($chars)
    FileWrite($output,$chars)
Wend
FileWrite($output,@crlf)
for $z = 1 to 25
    FileWriteLine($output,$key[$z][2])
Next
FileClose($input)
FileClose($output)
        Func enc($blah)
            if $blah = " " then Return " "
            if $blah = "." then return "."
            if $blah = "?" then Return "?"
            if $blah = "!" then Return "!"
            if $blah = "-" then Return "-"
            FOR $X = 1 to 26
                if $key[$x][1] = StringLower($blah) then Return $key[$x][2]
            Next
        EndFunc
I have tried it and it works fine

I only need to say what letter it must be replaced.

This is a encryption but how to decrypt this?

Could someone help me please?

I don't need that messagebox i want to use the standard. a=z b=y etc..

Please help me

I am looking at this code - what does the enc() function do and where is it?

EDIT fixed grammar

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

I am looking at this code - what does the enc() function do and where is it?

EDIT fixed grammar

Never mind - found it.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

CODE

#include <string.au3>

$i = 0

FileOpen("file.txt",0)

FileOpen("new.txt",1)

For $i = 1 To FileGetSize("file.txt")

$value = FileReadLine("file.txt", $i)

FileWrite("new.txt", _StringEncrypt(1, $value, "password"))

Next

FileClose("file.txt")

FileClose("new.txt")

or

CODE

#include <string.au3>

#include <file.au3>

$i = 0

FileOpen("file.txt",0)

FileOpen("new.txt",1)

For $i = 1 To _FileCountLines("file.txt")

$value = FileReadLine("file.txt", $i)

FileWrite("new.txt", _StringEncrypt(1, $value, "password"))

Next

FileClose("file.txt")

FileClose("new.txt")

Assuming that file.txt is the file you want to encrypt. delete file.txt when done and rename new.txt to file.txt

works but takes too long if the file size is > 100KB.

Hope this helps

Share this post


Link to post
Share on other sites

Hallo,

What mrbond007 has made it works.

The only problem is that i can not use blank lines,and toher caracters how to make it so i can use them?


I little problem, hard to find and fix

Share this post


Link to post
Share on other sites

Hello,

I have made a tekst encryptor and decyptor:

;====================================================
;============= Encryption Tool With GUI ============= 
;====================================================
; This script is made to encrypt and decrypt file's whit as password nothing
; Made by Erik
; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------
#include <guiconstants.au3>
#include <string.au3>

$WinMain = GuiCreate('Encryption tool', 300, 100)

$EditText = GuiCtrlCreateEdit('',1,1,1,1)

$InputLevel = GuiCtrlCreateInput(1, 10, 10, 50, 20, 0x2001)
$UpDownLevel = GUICtrlSetLimit(GuiCtrlCreateUpDown($inputlevel),10,1)

$EncryptButton = GuiCtrlCreateButton('Encrypt', 65, 10, 105, 35)
$DecryptButton = GuiCtrlCreateButton('Decrypt', 180, 10, 105, 35)

GuiCtrlCreateLabel('Level',10,35)

GuiSetState()


Do
   $Msg = GuiGetMsg()
   If $msg = $EncryptButton Then

      GuiSetState(@SW_DISABLE,$WinMain)

      $string = FileOpenDialog("Select a file to encrypt","C:\","All (*.*)")
      $fileopen = FileRead($string)

      GuiCtrlSetData($EditText,_StringEncrypt(1,$fileopen,"nothing",GuiCtrlRead($InputLevel)))
      $savefile = FileSaveDialog("Save encrypted","C:\","All (*.*)")
      FileWrite($savefile,GUICtrlRead($EditText))

      GuiSetState(@SW_ENABLE,$WinMain)

   EndIf
   If $msg = $DecryptButton Then
     
      GuiSetState(@SW_DISABLE,$WinMain)
     
      $string = FileOpenDialog("Select a file to de crypt","C:\","All (*.*)")
      $fileopen = FileRead($string)

      GuiCtrlSetData($EditText,_StringEncrypt(0,$fileopen,"nothing",GuiCtrlRead($InputLevel)))
      $savefile = FileSaveDialog("Save decrypted","C:\","All (*.*)")
      FileWrite($savefile,GUICtrlRead($EditText))
      
      GuiSetState(@SW_ENABLE,$WinMain)

   EndIf
Until $msg = $GUI_EVENT_CLOSE

Hope i could help you

I am now trying so let it read a hole folder and encrypt it but that is a bit hard for me


I little problem, hard to find and fix

Share this post


Link to post
Share on other sites

Hello,

I have made a tekst encryptor and decyptor:

;====================================================
;============= Encryption Tool With GUI ============= 
;====================================================
; This script is made to encrypt and decrypt file's whit as password nothing
; Made by Erik
; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------
#include <guiconstants.au3>
#include <string.au3>

$WinMain = GuiCreate('Encryption tool', 300, 100)

$EditText = GuiCtrlCreateEdit('',1,1,1,1)

$InputLevel = GuiCtrlCreateInput(1, 10, 10, 50, 20, 0x2001)
$UpDownLevel = GUICtrlSetLimit(GuiCtrlCreateUpDown($inputlevel),10,1)

$EncryptButton = GuiCtrlCreateButton('Encrypt', 65, 10, 105, 35)
$DecryptButton = GuiCtrlCreateButton('Decrypt', 180, 10, 105, 35)

GuiCtrlCreateLabel('Level',10,35)

GuiSetState()
Do
   $Msg = GuiGetMsg()
   If $msg = $EncryptButton Then

      GuiSetState(@SW_DISABLE,$WinMain)

      $string = FileOpenDialog("Select a file to encrypt","C:\","All (*.*)")
      $fileopen = FileRead($string)

      GuiCtrlSetData($EditText,_StringEncrypt(1,$fileopen,"nothing",GuiCtrlRead($InputLevel)))
      $savefile = FileSaveDialog("Save encrypted","C:\","All (*.*)")
      FileWrite($savefile,GUICtrlRead($EditText))

      GuiSetState(@SW_ENABLE,$WinMain)

   EndIf
   If $msg = $DecryptButton Then
     
      GuiSetState(@SW_DISABLE,$WinMain)
     
      $string = FileOpenDialog("Select a file to de crypt","C:\","All (*.*)")
      $fileopen = FileRead($string)

      GuiCtrlSetData($EditText,_StringEncrypt(0,$fileopen,"nothing",GuiCtrlRead($InputLevel)))
      $savefile = FileSaveDialog("Save decrypted","C:\","All (*.*)")
      FileWrite($savefile,GUICtrlRead($EditText))
      
      GuiSetState(@SW_ENABLE,$WinMain)

   EndIf
Until $msg = $GUI_EVENT_CLOSE

Hope i could help you

I am now trying so let it read a hole folder and encrypt it but that is a bit hard for me

It's nice, you can try changing "C:\" with @HomeDrive just in case.

Multiple file support is not suggested cause encrypting one file can take sometimes forever :whistle:

Share this post


Link to post
Share on other sites

Haha, i was trying to encrypt a powerpoint presentation but that toke to long:P

Could you help me, the program must look into all directorys in one directory and find all files and encrypt them into the same folder.

Hope you can help me


I little problem, hard to find and fix

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Haha, i was trying to encrypt a powerpoint presentation but that toke to long:P

Could you help me, the program must look into all directorys in one directory and find all files and encrypt them into the same folder.

Hope you can help me

why don't you add drag-and-drop option and then split the file name using StringStrip, i have created AU3-SC that uses this option you can try checking it:

http://www.autoitscript.com/forum/index.php?showtopic=42308

Edited by mrbond007

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

When my programs start it needs to decrypt everyting and when it is closing it needs to encrypt everything..

I need it because in that files you can find all data of people and i don't want that people can read it

So it needs to go automaticly

EDIT: is there a way to encrypt a folder whit data into it?

Edited by Erik.

I little problem, hard to find and fix

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

srry wrong one

Edited by Erik.

I little problem, hard to find and fix

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