Jump to content

Chaos Crypting Engine


mrbond007
 Share

Recommended Posts

One of my friends asked me to write a script that encrypts/decrypts files cause his brain was hurting.

The problem with encrypting files is reading each character in the file. The solution is:

$hFile = FileOpen($input, 0)
For $i = 1 To FileGetSize($input)
      $char = FileRead($hFile, 1)
Next

;old example
For $i = 1 To FileGetSize($input)
      $read = StringTrimLeft(FileRead($input, $i), $i - 1)
Next

$input is the name of the file you want to encrypt.

$read is a way i though of to be able to read each characters in the file, unlike : $read = FileRead($file, $i).

After $read you must put your encryption/decryption method :

$hFile = FileOpen($input, 0)
For $i = 1 To FileGetSize($input)
      $char = FileRead($hFile, 1)
      $crypt = _crypt($char,$password,0);example of an encryption method
      FileWrite($output_decrypted, Chr(Dec($crypt)));writes the encrypted string to the output file
Next

;old example
For $i = 1 To FileGetSize($input)
    $read = StringTrimLeft(FileRead($input, $i), $i - 1)
    $crypt = _crypt($read, $password, 0);example of an encryption method
    FileWrite($output, Chr(Dec($crypt)));writes the encrypted string to the output file
Next

Done :(

A different method that you can use is: random encryption pattern like characters swapping here's an example :

64 : 102 Chr(64) becomes Chr(102)

65 : 55 Chr(65) becomes Chr(55)

66 : 77 Chr(66) becomes Chr(77)

but don't use weak methods like the Reverse, Shifter or Flipper methods.

When using Random encryption you have the possibility of generating 65536 different types of patterns. Example :

$hFile = FileOpen($input, 0)
For $i = 1 To FileGetSize($input)
      $char = FileRead($hFile, 1)
      $str = StringTrimLeft(Hex(Asc($char)), 6)
      If $str = "07" Then FileWrite($output, Chr(59))
Next

;old example
For $i = 1 To FileGetSize($input)
    $read = StringTrimLeft(FileRead($input, $i), $i - 1)
    $str = StringTrimLeft(Hex(Asc($read)), 6)
    If $str = "07" Then FileWrite($output, Chr(59))
Next

The major problem is speed, looping in such ways makes the script really slow :shocked: . Many encryption programs cuts the input file into chuncks (each of +/- 32KB) and then encrypts each chunk in one time, that's why it's a lot faster comparing to AutoIt.

The first script that iv'e included is Crypt.au3, uses jaenster's crypting function so all credits

goes to jaenster, URL : http://www.autoitscript.com/forum/index.php?showtopic=37808

the script shows how easily you can encrypt/decrypt files.

The second script is the "Chaos Crypting Engine" Chaos.au3 Also encrypts and decrypts files easily.

The "Generate Table" button generates 2 files : encrypt.txt and decrypt.txt.

replace the script lines from 80 to 335 with the contents of encrypt.txt, then replace the script lines from 356 to 611 with the contents of decrypt.txt. This way you get a different crypting method everytime. you can use "Tidy AutoIt Source" to make the script clean :P

When done delete both encrypt.txt and decrypt.txt files.

The third script is a new FileRead UDF function that i created for you to include in your UDF collection.

Please Note that sometimes the encrypted or decrypted file might be missing one or more characters no matter what method you use, this is an AutoIt bug and i think it was solved in the beta version, Note when re-encrypting or re-decrypting, the problem gets solved.

I'm sorry that i couldn't provide more examples cause i was writing all of this with one hand

(my other hand is injured).

Have Fun

FileRead_UDF.zip

Crypt.zip

Chaos.zip

Edited by mrbond007
Link to comment
Share on other sites

For $i = 1 To FileGetSize($input)
      $read = StringTrimLeft(FileRead($input, $i), $i - 1)
Next
FileRead( $input, $i )

This way you avoid having read a lot of characters (which might be time-consuming), copying them into a String/BinaryString variable and then trimming that string in order to extract one character from it.

Link to comment
Share on other sites

Yes, maybe. But imagine the vacuity of reading more than FileGetSize( $input ) times more characters than there is need to read for :shocked: Imagine what the interpreter does: it calls a function to read n characters from the file, then (if there are a lot of characters) reallocates memory for a Variant variable so it can host all those read characters, and then extracts only one char which is needed by the programmer.

If you for some reason are not fond of the suggested way, you might consider than reading the entire file into a variable and then for()'ing and doing stuff with that buffer. I.e.:

Dim $Data = FileRead( $input )
For $i = 1 To StringLen( $Data )
    ; The needed char can be accessed by "$Data[ $i ]" now.
Next

Just a suggestion :(

I like the tutorial anyway. Thanks.

Link to comment
Share on other sites

I tried many ways but the Autoit is a scripting language that's why it's slowwwwww.

Anyway i wanted to provied many examples (like your's) but my hand is killing me :shocked:

Link to comment
Share on other sites

@zatorg

Added your example to the scripts :shocked:

guess after testing your example saves around 2% cpu cycles and 100kb of memory on my computer.

Edited by mrbond007
Link to comment
Share on other sites

Also, as to the encryption method It might also make it faster to break it into chunks of say (10?) characters and then skipping a certain number of parts for encryption depending on level of encryption, like Super skips none, Pretty good skips 2, ok skips 4 etc. etc. It would still be encrypted and unaccesable but It would have the option to go way faster as well.

[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

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...