Obfuscator / TextCrypter -AES -x86/64 -Unicode -Module

Share your advanced PureBasic knowledge/code with the community.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Obfuscator / TextCrypter -AES -x86/64 -Unicode -Module

Post by Saki »

Obfuscator / TextCrypter - QAES - AES enhanced - x86/64 -Unicode - Module

This tool is a chimera between Obfuscator and Crypter.
It should be able to be used in many ways.
With AES based encryption.

Inclusive AES enhanced password creator.

Extremelly fast - Converts on my machine more as 171,000 characters in one second.

It is as easy to handle as UCase and LCase.

It does not destroy a text, string, or script and keeps its formatting.
But it makes it impossible to even begin to recognize what it actually is or to edit or make something readable.
:wink: Strings can be converted on the fly.

It is a basic code, which you can easily use or adapt to create e.g. a specific obfuscator or crypter for many things.
The process of converting plain text components, for example, can be automated very easily.
A customized obfuscator for source codes should be able to be very quickly created.

The Shift parameter transfers the used character set for the encrypted text arbitrarily.
Once you understand this, it's very easy and nice.

It always depends on what you want.

Have fun.

This looks as sample so :

Try as sample shift=$A000 - with latin based source text
Image

With latin based source text
Image

With hidden characters - Character offset $E600
Image

Code: Select all


DeclareModule Obfuscator_QAES
  EnableExplicit
  UseMD5Fingerprint()
  Declare.s Obfuscator_QAES(string$, mode, password$="", strongness=4, shift=200)
EndDeclareModule

Module Obfuscator_QAES
  Procedure.s Obfuscator_QAES(string$, mode, password$="", strongness=4, shift=200)
    ; Obfuscator / TextCrypter - AES enhanced - x86/64 - Unicode - This code is free for changing and enhancing
    ; No warranty whats ever - Using on your own risk
    ; mode=0 - encode // mode=1 - decode
    ; shift - Shift to visible encrypted characters - Mostly you must not change the preset
    ; strongness - 3 > 6 - preset=4 - This is the AES based randomized max shift - 3=31 - 4=63 - 5=127 - 6=255 
    Dim register.q(1)
    If SizeOf(character)=1 : ProcedureReturn "Created for Unicode" : EndIf
    If string$="" : ProcedureReturn "" : EndIf
    If strongness<3 : strongness=3 : EndIf : If strongness>6 : strongness=6 : EndIf
    Protected string_length=StringByteLength(string$)-2 : strongness=6-strongness
    Protected i, ii, iii, depth, *pos_w.word, fixed$=StringFingerprint(password$+"%$(s4DäÖ", #PB_Cipher_MD5)
    Repeat ; 16 Bytes
      PokeA(@register(0)+i, Val("$"+PeekS(@fixed$+ii, 2))) : ii+SizeOf(character)<<1 : i+1 ; Create a key
    Until ii=StringByteLength(fixed$) : i=0 : ii=0
    Repeat
      Repeat
        If Not iii : AESDecoder(@register(0), @register(0), 16, @register(0), 128, 0, #PB_Cipher_ECB) : EndIf
        depth=PeekA(@register(0)+iii)>>strongness : iii+1 : If iii>15 : iii=0 : EndIf
      Until depth
      depth=depth+shift : *pos_w=@string$+i
      If *pos_w\w<>10 And *pos_w\w<>13 : If mode : *pos_w\w-depth : Else : *pos_w\w+depth : EndIf : EndIf
      i+2 : *pos_w+2
    Until i>string_length
    ProcedureReturn string$
  EndProcedure
EndModule
UseModule Obfuscator_QAES

; ###### Get the result ######

CompilerIf #PB_Compiler_IsMainFile
  EnableExplicit
  
  Procedure.s CreatePassword_QAES(password$, salt$="", enhancement$="")
    If password$=""
      Protected requester=1
      password$=InputRequester("Set your passord", "I put the result it in your clipboard", "")
    EndIf
    Protected password_1$=Obfuscator_QAES(password$, 0, password$+salt$, 6)+enhancement$
    If requester
      SetClipboardText(password_1$)
      MessageRequester("Obfuscator_QAES - Password generating"+Space(50),
                       "The password is now in your clipboard"+#LF$+#LF$+
                       "Complexity : "+Len(password$)+" ^ 255"+#LF$+#LF$+
                       "Extension for optimal acceptance :  "+enhancement$+#LF$+#LF$+#LF$+
                       password$+#LF$+#LF$+
                       password_1$+#LF$+#LF$+#LF$+
                       "Closing the window clear your clipboard")
      SetClipboardText("")  
      password$=#Null$
      ProcedureReturn password_1$
    EndIf
    password$=#Null$
    ProcedureReturn password_1$
  EndProcedure 
  
  Define string$="Hello World"+#LF$+
                 "How are you ?"+#LF$+
                 "I hope you are well"+#LF$+
                 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"+#LF$+
                 "the quick brown fox jumps over the lazy dog"+#LF$+
                 "0123456789"+#LF$+
                 "+#§$%&/()=[]\!?-"+#LF$+
                 "Have fun with "+Chr(34)+"QAES"+Chr(34)+" crypting tools"
  
  Define password$="My Password" ; Password
  
  Define shift=$C8 ; $E600       ; Shift to visible encrypted characters - UCS-2 - Mostly you must not change the preset
                   ; For example, if you use $E600 as shift instead of $C8,
                   ; the characters are automatically anonymized and cannot be distinguished visually.
  
  Define strongness=4            ; Strongness - 3 to 6
  
  ; ################### Test part 1 ###################
  Debug "###### encoded ######"
  Define result$=Obfuscator_QAES(string$, 0, password$, strongness, shift) ; Encode - Mode 0
  Debug result$
  Debug " "
  Debug "###### decoded ######"
  Define result$=Obfuscator_QAES(result$, 1, password$, strongness, shift) ; Decode - Mode 1
  Debug result$
  
  Define i, ii, iii=Len(string$)+3
  Define loops=3000     ; Test loops - This test your config
  Define test_range=255 ; Character space Ascii
  Debug ""
  Debug "### WAIT ###"
  Delay(1200)
  Define time=ElapsedMilliseconds()
  For i=1 To loops
    string$+Chr(Random(test_range-1)+1)+Chr(Random(test_range-1)+1)+Chr(Random(test_range-1)+1)
    Define result_0$=Obfuscator_QAES(string$, 0, password$+Str(i), strongness, shift)   ; Encode - mode 0
    Define result_1$=Obfuscator_QAES(result_0$, 1, password$+Str(i), strongness, shift) ; Decode - mode 1
    If result_1$<>string$ : Debug "Fail : "+ i : End : EndIf
    ii+1 : If ii=100 : ii=0 : Debug i : EndIf
  Next i
  time=(ElapsedMilliseconds()-time)/1000
  Debug "All OK : "+Str(iii*loops*2/time)+" Characters coded in one second"
  Debug ""
  
  ; ############ Test Part 2 - Password creating #############
  Debug "Password creating demo"
  Define salt$="Salt_479()x*#"      ; You must not set
  Define enhancement$="_@35ahDB"    ; Extension for optimal acceptance - You must not set
  Define password$="Hello Password" ; Leave empty to call a dialog 
  Debug CreatePassword_QAES(password$, salt$, enhancement$) 
  
  ; ################### Test Part 3 Sample ###################
  string$="ĦŚņųĹėĨũťľŅ"+#LF$+
          "ĤĹŵûĹņļĜŌňŁêĊ"+#LF$+
          "ėąťųųŕĊŽĸťðįĻŐĆūŕŊŗ"+#LF$+
          "ōŇʼnĀğĽʼnĖĻîĝĥĠĭIJôĮĨĢóŋĪŌĦĮøőōġʼnĉĠĖďïĘĢıŃĤģĠĕ"+#LF$+
          "ŠŗŒĈŗ੹ŏĦŖŖĻœšĉšŲŒĖşşŜőťĆŭżŢĽĄŗţŕìĸŒŞŹĔłŢŏ"+#LF$+
          "ijĀĆĐąĶĝđĭĎ"+#LF$+
          "ĮĩƇĀïĜğĞøĎŋňĴČđÿ"+#LF$+
          "ĵřŒŔĥĻŜńăŬůŴŭĝùĸĭĪġĨĉŊʼnŗŕʼnťŐŠęĿŔűŁů"
  
  Define password$="My Password" ; Password
  Define shift=$C8               ; Shift to visible encrypted characters - UCS-2
  Define strongness=4            ; Strongness - 3 to 6
  
  MessageRequester("Obfuscator_QAES", Obfuscator_QAES(string$, 1, "My Password", strongness, shift))
CompilerEndIf
UCS-2 Code table :
http://www.columbia.edu/kermit/ucs2.html
Last edited by Saki on Wed Jun 23, 2021 8:18 pm, edited 51 times in total.
地球上の平和
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Obfuscator / TextCrypter -AES enhanced -x86/64 -Unicode

Post by Saki »

Code updated

Is a bit fiddly in detail, is quickly what overlooked.

If you notice something else, please write.
地球上の平和
fluent
User
User
Posts: 68
Joined: Sun Jan 24, 2021 10:57 am

Re: Obfuscator / TextCrypter -AES enhanced -x86/64 -Unicode

Post by fluent »

Thanks for sharing!
Is it possible to tweak it so output has printable characters only?
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Obfuscator / TextCrypter -AES enhanced -x86/64 -Unicode

Post by Saki »

I have to look, the code still has a bug, I had to remove it unfortunately.
地球上の平和
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Obfuscator / TextCrypter -AES enhanced -x86/64 -Unicode

Post by Keya »

fluent wrote: Fri Apr 23, 2021 8:38 pm Thanks for sharing!
Is it possible to tweak it so output has printable characters only?
Simply pipe the output into a base encoding, like base64. Or you could convert it to hex but that's not very efficient
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Obfuscator / TextCrypter -AES enhanced -x86/64 -Unicode

Post by Saki »

Code updated and extended.

The Shift parameter transfers the used character set for the encrypted text arbitrarily.

A test part is attached to verify proper operation.

Is is extremely fast, converts on my machine about 171,000 characters in one second.
fluent wrote: Fri Apr 23, 2021 8:38 pm Thanks for sharing!
Is it possible to tweak it so output has printable characters only?
Yes, extension for it is inserted.
Just launch the codes above.

Based on code table UCS-2 :
http://www.columbia.edu/kermit/ucs2.html
Last edited by Saki on Sun Apr 25, 2021 8:09 pm, edited 1 time in total.
地球上の平和
fluent
User
User
Posts: 68
Joined: Sun Jan 24, 2021 10:57 am

Re: Obfuscator / TextCrypter -AES -x86/64 -Unicode -Module

Post by fluent »

Cool job, thanks!
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Obfuscator / TextCrypter -AES -x86/64 -Unicode -Module

Post by Saki »

Hi @fluent
Yes, thanks, it is quite an very unusual tool.
The cool thing about it is that you can easily convert readable text to absolutelly unreadable.
The easiest way is to copy converted text lines from the debugger window.
Passwords, access data, database entries, texts in programs, everything can be encrypted this way.
In itself, something like this has been searched for years.
The protection of the encrypted data is very high.
Practically it can not be cracked, I myself do not see any conceivable method
to get the plaintext without a password, because it works AES based.

You can always leave the shift parameter as it is.
It is in fact only a pointer to a spectrum of UCS-2 characters.
It may be that users who use Asian language would like the generated output to be different.
Or simple he want a other output.
They can then change the shift parameter, whereby also negative offsets or an offset of more than $FF00 are possible.
But you have to test this, because UCS-2 does not support the complete Unicode range by far.
But be careful that you do not move into the ascii area,
because apostrophes can be created there, which serve as start and end markers for strings.
地球上の平和
Post Reply