QAES AES256 XEX & KFB & SHA3 crypter for string,binary,text

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

QAES AES256 XEX & KFB & SHA3 crypter for string,binary,text

Post by Saki »

Enhanced QAES AES256 XEX & KFB multi mode special crypter for strings, binary, text, images

Inclusive SHA3 256 based additional usable post crypter

To time :

; Available KFB crypt modes (crypt_mode)
; 0 = XEX Preset - same 1
; 1 = XEX dual mode with double XOR
; 2 = XDX dual mode with double XOR
; 3 = E mode
; 4 = D mode
; 5 = EE dual mode
; 6 = DD dual mode
; 7 = ED dual mode
; 8 = DE dual mode
; 9 = EDE triple mode
; 10 = DED triple mode
; 11 = DDE triple mode
; 12 = EED triple mode
; 13 = DEE triple mode
; 14 = EDD triple mode
; 15 = DDD triple mode
; 16 = EEE triple mode
; 17 = E mode - Compatible to older versions

; Set the crypt_mode values negative for using with SHA3 based post coder
; As sample -10 = with SHA3 based post coder

This is a very enhanced new version of the QAES KFB coder in the forum.
Some features from the old coder are compatible, but you must look self for replacing.

Use at your own risk - No warranty whats ever.

viewtopic.php?f=12&t=71493

The dual and triple crypt modes extends the key length from 256 bits to 512 bits
XEX mode with additional double XOR.

Discrediting attacks on AES are primarily not possible even with quantum computers.
But who knows what the future will bring.
Should an institution ever succeed in cracking AES, it would be a golden hole for them.
The XEX mode and the additional SHA3 mode crypter implemented here was designed to counteract this.

Best Regards Saki

Code: Select all

DeclareModule QAES_smart_universal_coder_XEX
  Declare QAES_smart_universal_coder_XEX(mode, *buffer_in.word, *buffer_out.word, bytes.q, key$, counter_key.q=0, counter_aes.q=0, crypt_mode=0)
  
  Declare.s QAES_Salter(salter_$) ; You can set a embedded salt 
  
  Declare QAES_get_crypt_mode() ; Get the used crypt mode
  
  ; Use ever key stretching - This impeded key brute force quite substantial
  ; You can, but you must not set a window and a progressbar for the key stretching progress
  Declare.s QAES_Key_stretching(window_ID, progressbar_ID, key$, salt$, key_stretching_loops)
  
  UseSHA3Fingerprint()
EndDeclareModule

Module QAES_smart_universal_coder_XEX
  EnableExplicit
  
  ; QAES AES256 KFB and XEX special multi mode coder for all things - binarys - strings - text files
  ; With optional SHA3 256 based post coder
  
  ; The XEX mode extends the key length from 256 bit to 512 bit and offers double AES encryption with additional double XOR
  ; The KFB dual and triple mode extends the key length also from 256 bit to 512 bit and offers double or triple AES encryption
  
  ; The SHA3 based post coder enhance the encryption with a SHA3 256 bit based encryption
  ; SHA3 is a one-way function, there is no way to decrypt this construction without the known password and counter
  ; Note that this function slows down the coder considerably
  
  ; This coder can handle automatic string termination for any strings - In compiler mode ASCII and UNICODE !
  ; The coder works with all data lengths, also <16 bytes
  
  ; mode=0 - Mode BINARY, you can encrypt binary data, don't use this for on demand string encryption, it break the string termination!
  ; mode=1 - Mode ASCII, you can encrypt mixed data, string and binary - This ignore the encryption of zero bytes, recommended for mixed datea with ASCII strings.
  ; mode=2 - Mode UNICODE, you can encrypt mixed data, ascii strings, unicode strings and binary - This ignore the encryption of zero bytes.
  ; The coder go always forward, an extra decoder isn't necessary, just use exactly the same calling convention for encrypting and decrypting!
  ; You cipher a file blockwise, always set the current block number (consecutive) with the counter - Important, then the result look similar to CBC mode encryption!
  
  ; Author (C) W. Albus - www.nachtoptik.de - Authorized enhanced by Saki
  ; No warranty whatsever - Use at your own risk
  ; It's nice you set a hint in your software for using QAES contents
  ; PureBasic
  
  ; counter_key.q : You cipher a file blockwise, always set the current block number with this counter (consecutive numbering).
  ; counter_aes.q : This counter will be automatically used by the coder, but you can change the startpoint, this chance same the counter_key the encryption absolutely
  ;               : The counter_aes you can use as sample for setting a randomized startpoint for using with the file coder addon protection function
  ;               : With used counters and salt you can personalise the coder, nobody can brute force a password from a unknown personalised coder
  ;               : You can set the counter as quad, positive and negative
  ; key$          : You can use any strings as key
  ; *buffer_in    : Set the adress to the source data
  ; *buffer_out   : Set the adress to the destination data - Hint : It can also use the same place as the plain data.
  ; mode          : Set mode=0 for binary files - Set mode=1 for ASCII strings - Set mode=2 for UNICODE strings
  
  ; Available KFB crypt modes (crypt_mode)
  ; 0  = XEX Preset - same 1
  ; 1  = XEX dual mode with double XOR
  ; 2  = XDX dual mode with double XOR
  ; 3  = E   mode
  ; 4  = D   mode
  ; 5  = EE  dual mode
  ; 6  = DD  dual mode
  ; 7  = ED  dual mode
  ; 8  = DE  dual mode
  ; 9  = EDE triple mode
  ; 10 = DED triple mode
  ; 11 = DDE triple mode
  ; 12 = EED triple mode
  ; 13 = DEE triple mode
  ; 14 = EDD triple mode
  ; 15 = DDD triple mode
  ; 16 = EEE triple mode
  ; 17 = E   mode - Compatible to older versions
  ; TODO Adjust the min and max available crypt mode value
  
  ; Set the crypt_mode values negative for using with SHA3 based post coder
  ; As sample -10 = with SHA3 based post coder
  
  Global QAES_get_crypt_mode, salter$
  
  Procedure QAES_smart_universal_coder_XEX(mode, *buffer_in.word, *buffer_out.word, bytes.q, key$, counter_key.q=0, counter_aes.q=0, crypt_mode=0)
    If Not bytes.q Or key$="" : ProcedureReturn 0  : EndIf
    
    ; TODO : You can modify this salt to personalise the coder
    #Salt$="t8690352cj2p1ch7fgw34u&=)?=)/%&§/&)=?(otmq09745$%()=)&%"
    
    Protected.q i, result, rounds.q=bytes>>4
    Protected ii, iii, bytes_minus_x, stepp=SizeOf(character)<<1
    Protected *registers_a_asc.ascii, *registers_a.word, *buffer_in_quad.quad, *buffer_out_quad.quad
    Protected remaining=bytes%16, bytes_minus_1=bytes-1
    Protected *buffer_in_asc.ascii, *buffer_out_asc.ascii
    Protected hash$=#Salt$+key$+salter$+Str(counter_key)+ReverseString(#Salt$)
    Static fixed_key_string${128} ; For KFB mono you need only {64]
    Static Dim registers_a.q(3)
    Static Dim registers_b.q(3) ; Only needed for XEX mode
    
    ; crypt_mode=2 ; TODO : So you can also simple preset the crypt mode for testing
    
    If Not crypt_mode : crypt_mode=1 : EndIf
    
    If crypt_mode<-17 Or crypt_mode>17 : crypt_mode=1 : EndIf ; TODO Define Fuse & Lines 104 - 188
    
    QAES_get_crypt_mode=crypt_mode
    
    If crypt_mode<0 : crypt_mode=Abs(crypt_mode) : Protected post_crypter=1 : EndIf
    
    If crypt_mode=3 Or crypt_mode=4 Or crypt_mode=17 ; TODO define mono crypters - Mono key 256 Bit
      fixed_key_string$=Fingerprint(@hash$, StringByteLength(hash$), #PB_Cipher_SHA3, 256) ; Create a key
      If fixed_key_string$="" : ProcedureReturn 0 : EndIf
      For ii = 0 To 31 : PokeA(@registers_a(0)+ii, Val("$"+PeekS(@fixed_key_string$+iii, 2))) : iii+stepp : Next
      registers_a(1)+counter_aes
    Else
      ; Dual key 512 Bit
      fixed_key_string$=Fingerprint(@hash$, StringByteLength(hash$), #PB_Cipher_SHA3, 512) ; Create a key
      For ii = 0 To 31 : PokeA(@registers_b(0)+ii, Val("$"+PeekS(@fixed_key_string$+iii, 2))) : iii+stepp : Next
      For ii = 0 To 31 : PokeA(@registers_a(0)+ii, Val("$"+PeekS(@fixed_key_string$+iii, 2))) : iii+stepp : Next
      registers_b.q(1)+counter_key.q
      registers_a.q(2)+counter_aes.q
    EndIf
    
    Macro crypter_x_mode(a, b)
      Swap registers_b(0), registers_b(3) : Swap registers_b(1), registers_b(2) ; Add more diffusion
      result=Bool(AES#a(@registers_b(0), @registers_b(0), 32, @registers_a(0), 256, 0, #PB_Cipher_ECB))
      registers_a(0) ! registers_b(0) : registers_a(1) ! registers_b(1) : registers_a(2) ! registers_b(2) : registers_a(3) ! registers_b(3)
      Swap registers_a(0), registers_a(3) : Swap registers_a(1), registers_a(2) ; Add more diffusion
      result+Bool(AES#b(@registers_a(0), @registers_a(0), 32, @registers_b(0), 256, 0, #PB_Cipher_ECB))
      registers_a(0) ! registers_b(0) : registers_a(1) ! registers_b(1) : registers_a(2) ! registers_b(2) : registers_a(3) ! registers_b(3)
      If result<2 : ProcedureReturn 0 : EndIf
    EndMacro
    
    Macro crypter_mono(a)
      If Not AES#a(@registers_a(0), @registers_a(0), 32, @registers_a(0), 256, 0, #PB_Cipher_ECB) : ProcedureReturn 0 : EndIf
      Swap registers_a(0), registers_a(3) : Swap registers_a(1), registers_a(2) ; Add more diffusion
    EndMacro
    
    Macro crypter_dual(a, b)
      result=Bool(AES#a(@registers_b(0), @registers_b(0), 16, @registers_a(0), 256, 0, #PB_Cipher_ECB))
      Swap registers_a(0), registers_a(3) : Swap registers_a(1), registers_a(2) ; Add more diffusion
      result+Bool(AES#b(@registers_a(0), @registers_a(0), 32, @registers_b(0), 256, 0, #PB_Cipher_ECB))
      If result<2 : ProcedureReturn 0 : EndIf
    EndMacro
    
    Macro crypter_triple(a, b, c)
      result=Bool(AES#a(@registers_a(0), @registers_a(0), 16, @registers_b(0), 256, 0, #PB_Cipher_ECB))
      Swap registers_a(0), registers_a(3) : Swap registers_a(1), registers_a(2) ; Add more diffusion
      result+Bool(AES#b(@registers_b(0), @registers_b(0), 32, @registers_a(0), 256, 0, #PB_Cipher_ECB))
      Swap registers_a(0), registers_a(3) : Swap registers_a(1), registers_a(2) ; Add more diffusion
      result+Bool(AES#c(@registers_a(0), @registers_a(0), 16, @registers_b(0), 256, 0, #PB_Cipher_ECB))
      If result<3 : ProcedureReturn 0 : EndIf
    EndMacro
    
    Macro go_1 ; Crypter
      Select crypt_mode
        Case 1; XEX
          crypter_x_mode(Encoder, Encoder)
        Case 2; XDX
          crypter_x_mode(Decoder, Decoder) 
        Case 3 ; E
          crypter_mono(Encoder)
        Case 4 ; D
          crypter_mono(Decoder)
        Case 5 ; EE
          crypter_dual(Encoder, Encoder)
        Case 6 ; DD
          crypter_dual(Decoder, Decoder)
        Case 7 ; ED
          crypter_dual(Encoder, Decoder)
        Case 8 ; DE
          crypter_dual(Decoder, Encoder)
        Case 9 ; EDE
          crypter_triple(Encoder, Decoder, Encoder)
        Case 10 ; DED
          crypter_triple(Decoder, Encoder, Decoder)
        Case 11 ; DDE
          crypter_triple(Decoder, Decoder, Encoder)
        Case 12 ; EED
          crypter_triple(Encoder, Encoder, Decoder)
        Case 13 ; DEE
          crypter_triple(Decoder, Encoder, Encoder)
        Case 14 ; EDD
          crypter_triple(Encoder, Decoder, Decoder)
        Case 15 ; DDD
          crypter_triple(Decoder, Decoder, Decoder)
        Case 16 ; EEE
          crypter_triple(Encoder, Encoder, Encoder)
        Case 17 ; E Compatible to older versions
          If Not AESEncoder(@registers_a(0), @registers_a(0), 32, @registers_a(0), 256, 0, #PB_Cipher_ECB) : ProcedureReturn 0 : EndIf
      EndSelect
      
      If post_crypter
        If crypt_mode=3 Or crypt_mode=4 Or crypt_mode=17 ; TODO mono crypters
          fixed_key_string$=Fingerprint(@registers_a(0), 32, #PB_Cipher_SHA3, 256)
        Else
          fixed_key_string$=Fingerprint(@registers_b(0), 32, #PB_Cipher_SHA3, 256)
        EndIf 
        iii=0
        If fixed_key_string$="" : ProcedureReturn 0 : EndIf
        For ii = 0 To 31 : PokeA(@registers_b(0)+ii, Val("$"+PeekS(@fixed_key_string$+iii, 2))) : iii+stepp : Next
        registers_a(0) ! registers_b(0) : registers_a(1) ! registers_b(1) : registers_a(2) ! registers_b(2) : registers_a(3) ! registers_b(3)
      EndIf
    EndMacro
    
    If Not mode ; Binary mode
      *buffer_in_quad.quad=*buffer_in.word : *buffer_out_quad.quad=*buffer_out.word
      If bytes<16 ; Less 16 bytes
        *buffer_out_asc=*buffer_out_quad : *buffer_in_asc=*buffer_in_quad : *registers_a_asc=@registers_a(0)
        go_1
        For ii=0 To bytes_minus_1
          *buffer_out_asc\a=*buffer_in_asc\a ! *registers_a_asc\a : *buffer_in_asc+1 : *buffer_out_asc+1 : *registers_a_asc+1
        Next
        ProcedureReturn 1
      EndIf
      While i<rounds ; =>16 bytes
        go_1
        *buffer_out_quad\q=*buffer_in_quad\q ! registers_a(0) : *buffer_in_quad+8 : *buffer_out_quad+8
        *buffer_out_quad\q=*buffer_in_quad\q ! registers_a(1) : *buffer_in_quad+8 : *buffer_out_quad+8 : i+1
      Wend
      If remaining
        *buffer_out_asc=*buffer_out_quad : *buffer_in_asc=*buffer_in_quad : *registers_a_asc=@registers_a(0)
        go_1
        For ii=0 To remaining-1
          *buffer_out_asc\a=*buffer_in_asc\a ! *registers_a_asc\a : *buffer_in_asc+1 : *buffer_out_asc+1 : *registers_a_asc+1
        Next
      EndIf
    ElseIf mode=1
      bytes_minus_x=bytes-2
      *buffer_in_asc=*buffer_in : *buffer_out_asc=*buffer_out
      Repeat
        go_1 : *registers_a_asc=@registers_a(0)
        For ii=0 To 15
          If *buffer_in_asc\a And *buffer_in_asc\a ! *registers_a_asc\a
            *buffer_out_asc\a=*buffer_in_asc\a ! *registers_a_asc\a
          Else
            *buffer_out_asc\a=*buffer_in_asc\a
          EndIf
          If i>bytes_minus_x : Break 2 : EndIf
          *buffer_in_asc+1 : *buffer_out_asc+1 : *registers_a_asc+1 : i+1
        Next ii
      ForEver
    Else ; mode=2
      bytes_minus_x=bytes-3
      Repeat
        go_1 : *registers_a.word=@registers_a(0)
        For ii=0 To 15 Step 2
          If *buffer_in\w And *buffer_in\w ! *registers_a\w
            *buffer_out\w=*buffer_in\w ! *registers_a\w
          Else
            *buffer_out\w=*buffer_in\w
          EndIf
          If i>bytes_minus_x : Break 2 : EndIf
          *buffer_in+2 : *buffer_out+2 : *registers_a+2 : i+2
        Next ii
      ForEver
    EndIf
    ProcedureReturn 1
  EndProcedure
  
  Procedure.s QAES_Salter(salter_$)
    salter$=salter_$
    ProcedureReturn salter$
  EndProcedure
  
  Procedure QAES_get_crypt_mode()
    ProcedureReturn QAES_get_crypt_mode
  EndProcedure
  
  Procedure.s QAES_Key_stretching(window_ID, progressbar_ID, key$, salt$, key_stretching_loops)
    Protected get_time.q , i
    get_time=ElapsedMilliseconds()
    For i=1 To key_stretching_loops ; Iterations
      key$=ReverseString(salt$)+key$+salt$+ReverseString(key$)
      key$=Fingerprint(@key$, StringByteLength(key$), #PB_Cipher_SHA3, 512)
      If IsWindow(window_ID) And IsGadget(progressbar_ID)
        If ElapsedMilliseconds()>get_time+100
          SetGadgetState(progressbar_ID, 100*i/key_stretching_loops)
          get_time.q=ElapsedMilliseconds()
        EndIf
      EndIf
    Next i
    key$=ReverseString(key$)+salt$+key$+ReverseString(key$)
    key$=Fingerprint(@key$, StringByteLength(key$), #PB_Cipher_SHA3, 512) ; Finalize
    If IsGadget(progressbar_ID)
      SetGadgetState(progressbar_ID, 100)
    EndIf
    Delay(100)
    ProcedureReturn key$
  EndProcedure
  
EndModule
UseModule QAES_smart_universal_coder_XEX

; = File coder addon for the universal AES256 based QAES_smart_universal_coder_XEX =

DeclareModule QAES_easy_file_coder
  UseModule QAES_smart_universal_coder_XEX
  
  ; File Crypter
  Declare.s QAES_easy_file_coder(mode,
                                 window_ID,
                                 progressbar_ID,
                                 path_1$,
                                 key_1$,
                                 file_extender$,
                                 counter_key.q,
                                 crypt_mode)
  
  ; File protector
  Declare.s QAES_easy_file_protector(mode,
                                     window_ID,
                                     progressbar_ID,
                                     path_1$,
                                     key_1$,
                                     counter_key.q,
                                     crypt_mode)
  
  Declare QAES_get_cryptextender_length()
  Declare QAES_Adjust_FaceLength(EnlargeFileLengthBytes_=128, RandomizeFileLengthBytes_=256)
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Linux
    Declare FixWriteData(file, *adress, length) ; Workaround for Linux PB 560
  CompilerEndIf
EndDeclareModule

Module QAES_easy_file_coder
  ; Smart file crypting addon or the QAES_smart_universal_coder_XEX
  ; Its nice you set a hint in your software for using QAES contents
  ; PureBasic
  
  ; This addon can protect or encrypt and decrypt files using the QAES_smart_universal_coder_XEX module
  ; The encrypted files do not have visible headers or extenders
  ; Works with all file lengths
  ; No separate decrypter necessary
  ; With integrated full automatic working crypt randomized counter
  ; With full automatic file integrity check
  ; Can full automatic check whether a file is encrypted
  ; Various files with the same content are encrypted ever completely differently
  ; Author W.Albus (C) - www.nachtoptik.de - Authorized enhanced by Saki
  ; No warranty whatsever - Use at your own risk
  
  EnableExplicit
  
  ; This is a part from GFX_Wizzard_BF
  Procedure MessageRequester_simple_BF(title_line$="",
                                       text$="",
                                       flags.a=#PB_MessageRequester_Yes,
                                       text_button_yes$="Yes",
                                       text_button_no$="No",
                                       text_button_cancel$="Cancel",
                                       text_width=470,
                                       text_height=165,
                                       buttons_width=150,
                                       buttons_height=35)
    
    Protected text_flag=#PB_Text_Center ; You can change
    
    flags << 5 : flags >> 5
    
    If text_width<120 : text_width=120 : EndIf
    If text_height<20 : text_height=20 : EndIf
    
    text_width+(1-text_width%2)
    Protected window_ID, button_yes_ID, button_no_ID, button_cancel_ID, text_ID, result, window_event
    
    window_ID=OpenWindow(#PB_Any, 0, 0, text_width+20, buttons_height+30+text_height, " "+title_line$, #PB_Window_Tool|#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
    If IsWindow(window_ID)
      StickyWindow(window_ID, #True)
      text_ID=TextGadget(#PB_Any, 10, 10, text_width, text_height, text$, text_flag)
      
      button_yes_ID=ButtonGadget(#PB_Any, 10, WindowHeight(window_ID)-buttons_height-10, buttons_width, buttons_height, " "+text_button_yes$, #PB_Button_MultiLine)
      button_no_ID=ButtonGadget(#PB_Any, 20+buttons_width, WindowHeight(window_ID)-buttons_height-10, buttons_width, buttons_height, " "+text_button_no$, #PB_Button_MultiLine)
      button_cancel_ID=ButtonGadget(#PB_Any, 30+buttons_width*2, WindowHeight(window_ID)-buttons_height-10, buttons_width, buttons_height, " "+text_button_cancel$, #PB_Button_MultiLine)
      
      If Not text_ID Or Not button_yes_ID Or Not button_no_ID Or Not button_cancel_ID
        ProcedureReturn 0
      EndIf
      
      If flags=#PB_MessageRequester_Yes : HideGadget(button_no_ID, 1) : HideGadget(button_cancel_ID, 1)
      ElseIf flags=#PB_MessageRequester_YesNo : HideGadget(button_cancel_ID, 1)
      EndIf
      
      Repeat
        window_event=WaitWindowEvent()
        If window_event=#PB_Event_Gadget
          Select EventGadget()
            Case button_yes_ID
              result=#PB_MessageRequester_Yes
            Case button_no_ID
              result=#PB_MessageRequester_No
            Case button_cancel_ID
              result=#PB_MessageRequester_Cancel
          EndSelect
        EndIf
        If window_event=#PB_Event_CloseWindow
          End
        EndIf
      Until result
      Delay(150)
      CloseWindow(window_ID)
      ProcedureReturn result
    EndIf
  EndProcedure
  
  Global get_cryptextender_length
  
  Global EnlargeFileLengthBytes=128   ; You can change
  Global RandomizeFileLengthBytes=256 ; This feature change full automatic and randomized the length from any encrypted files
  
  Procedure QAES_get_cryptextender_length() ; Length from the added crypt extender - Usable after crypter calls
    ProcedureReturn get_cryptextender_length
  EndProcedure
  
  Procedure QAES_Adjust_FaceLength(EnlargeFileLengthBytes_=128, RandomizeFileLengthBytes_=256) ; Adjust the face length from the crypt extender
    EnlargeFileLengthBytes=EnlargeFileLengthBytes_                                             ; This disguises the original file length
    RandomizeFileLengthBytes=RandomizeFileLengthBytes_
    If EnlargeFileLengthBytes<1 : EnlargeFileLengthBytes=1 : EndIf
    If RandomizeFileLengthBytes<1 : RandomizeFileLengthBytes=1 : EndIf
    ProcedureReturn 1
  EndProcedure
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Linux
    Procedure FixWriteData(file, *adress, length) ; Workaround for Linux PB560
      Protected write_data_pointer=Loc(file)
      Protected writen_data=WriteData(file, *adress, length)
      FileSeek(file, write_data_pointer+writen_data)
      ProcedureReturn writen_data
    EndProcedure
    Macro WriteData(File, Buffer, Size)
      FixWriteData(File, Buffer, Size)
    EndMacro
  CompilerEndIf
  
  Procedure.s QAES_smart_file_coder(mode,
                                    window_ID,
                                    progressbar_ID,
                                    path_1$,
                                    key_1$,
                                    file_extender$="",
                                    use_protection_mode.q=0,
                                    counter_key.q=0,
                                    crypt_mode=0)
    
    ; mode=0 - Full automatic mode with file selectors
    ; mode=1 - Encrypt or add a file protection
    ; mode=2 - Decrypt or remove a file protection
    ; mode=3 - Check the file integrity
    ; mode=4 - Check if a file is already encrypted or protected
    
    ; use_protection_mode <> 0 activate the file protection mode and set this value as key sensitive counter
    ; This protect a file, but dont encrypt the file
    ; The function give back also the counter value, you can use for numbering or other, same GadgetData()
    
    ; If not window_ID or not progressbar_ID, you get not a progressbar
    ; A empty key (Password) open automatically a string selector
    
    #HashLength=256 ; (224, 256, 384, 512) You can use all available hash lengths divisible by 2 and also different hashes
    
    #Salt$="59#ö#3:_,.45ß$/($(/=)?=JjB$§/(&=$?=)((/&)%WE/()T&%z#'" ; Salt - You can change
    
    #Hints="QUICK-AES-256 (QAES) AES256 KFB & XEX & SHA3 crypter"+#CRLF$+
           "No warranty whatever - Use at your own risk"+#CRLF$+#CRLF$
    
    restart:
    Protected cryptextender_length=24+#HashLength>>3 ; 8+8+8+#HashLength>>3
    Protected path$="", hash$, key$, message$, method_0$, method__0$, method___0$
    Protected method_1$, method__1$, method___1$, hash_1$="", key_2$, hash_2$=""
    Protected file, readed, writen=0, check_integrity=0, file_broken=0, block_size, window_event, result
    Protected progressbar_state, encrypted_file_found=0, hash_bytes, i, blocks, remaining, block_counter=0
    Protected file_size.q, fake_length.q, get_fake_length.q, get_counter.q, counter.q, counter_0.q, get_magic.q, magic.q, timer.q
    Protected crypt_random.c, set_fake_length.q, set_fake_length_1.q, counter_1.q=345645758512426756724 ; Preset startpoint counter 1 - You can change
    Protected Dim hash.q(#HashLength>>3-1)
    Protected *buffer, *fake_content
    
    If counter_key
      Protected counter_key$=Str(counter_key)
    EndIf
    
    If use_protection_mode
      Protected protection_counter$=Str(use_protection_mode)
      counter=use_protection_mode
      magic.q=275390641757985374251 ; Preset protected marker - You can change
      method_0$=" protected " : method__0$=" protect "
      method_1$=" unprotected " : method__1$=" unprotect "
    Else
      If OpenCryptRandom() : crypt_random=1 : CryptRandomData(@counter, 8) : Else : crypt_random=0 : RandomData(@counter, 8) : EndIf
      
      If Not counter
        If Not mode
          MessageRequester("ERROR", "Can not create counter")
        Else
          ProcedureReturn "ERROR ##01QF - Can not create counter !"
        EndIf
        ProcedureReturn ""
      EndIf
      magic.q=415628580943792148170 ; Preset crypt marker - You can change
      method_0$=" encrypted " : method__0$=" encrypt " : : method___0$=" crypting "
      method_1$=" decrypted " : : method__1$=" decrypt "
    EndIf
    
    If *buffer : FreeMemory(*buffer) : *buffer=0 : EndIf
    
    If mode Or path_1$<>"" : path$=path_1$ : path_1$="" : EndIf
    
    If IsWindow(window_ID) : progressbar_state=1 : EndIf
    
    If IsGadget(progressbar_ID)
      SetGadgetState(progressbar_ID, 0) : progressbar_state+1
    EndIf
    
    If Len(Fingerprint(@magic, 8, #PB_Cipher_SHA3, #HashLength))<>#HashLength>>2 ; Test Fingerprint
      If Not mode
        MessageRequester("ERROR", "Fingerprint fails")
      Else
        ProcedureReturn "ERROR ##02QF - Fingerprint fails !"
      EndIf
      ProcedureReturn ""
    EndIf
    
    If key_1$=""
      key_1$=InputRequester("", "Set firstly a password !", "")
      If key_1$="" : ProcedureReturn "" : EndIf
    EndIf
    
    key$=ReverseString(#Salt$)+key_1$+#Salt$+counter_key$+ReverseString(key_1$)+protection_counter$
    
    key_2$=key_1$ : key_1$=""
    
    key$=Fingerprint(@key$, StringByteLength(key$), #PB_Cipher_SHA3, 512)
    
    If Not QAES_smart_universal_coder_XEX(0, @magic, @magic, 8, #Salt$+ReverseString(key$)+Str(magic)+key$, 0, 0, crypt_mode)
      MessageRequester("Fatal ERROR", "QAES coder reports zero")
      ProcedureReturn ""
    EndIf
    
    If Not mode And path$=""
      select_again:
      path$=OpenFileRequester("Select a file to"+method___0$, "", "*.*", 0)
      If path$="" : ProcedureReturn "" : EndIf
    EndIf
    
    file_size=FileSize(path$)
    If file_size<0
      If Not mode
        MessageRequester("ERROR", "File not found")
        Goto select_again
      Else
        ProcedureReturn "ERROR ##03QF - File not found !"
      EndIf
    ElseIf Not file_size
      If Not mode
        MessageRequester("ERROR", "This is a zero length file"+#CRLF$+#CRLF$+"Can not"+method__0$+"files without a content")
        Goto select_again
      Else
        ProcedureReturn "ERROR ##04QF - This is a zero length file - Can not"+method__0$+"files without a content !"
      EndIf
    EndIf
    
    file=OpenFile(#PB_Any, path$)
    If file
      block_size=4096<<2 : FileBuffersSize(file, block_size ) : *buffer=AllocateMemory(block_size)
      If file_size<cryptextender_length+1
        If mode>1
          CloseFile(file)
          ProcedureReturn "ERROR ##05QF - This is not a"+method_0$+" file !"
        Else
          Goto encrypt_1
        EndIf
      EndIf
      FileSeek(file, file_size-cryptextender_length)
      ReadData(file, @get_fake_length, 8)
      ReadData(file, @get_counter, 8)
      ReadData(file, @get_magic, 8)
      ReadData(file, @hash(0), #HashLength>>3)
      FileSeek(file, 0)
      QAES_smart_universal_coder_XEX(0, @get_fake_length, @get_fake_length, 8, key$+ReverseString(key$), 0, 0, crypt_mode)        ; QAES crypter - Try decrypt fake length
      QAES_smart_universal_coder_XEX(0, @get_counter, @get_counter, 8, ReverseString(key$)+key$+#salt$, 0, 0, crypt_mode)         ; QAES crypter - Try decrypt counter
      QAES_smart_universal_coder_XEX(0, @hash(0), @hash(0), #HashLength>>3, key$+ReverseString(key$), get_counter, 0, crypt_mode) ; QAES crypter - Try decrypt hash
      QAES_smart_universal_coder_XEX(0, @get_magic, @get_magic, 8, ReverseString(key$)+key$, get_counter, 0, crypt_mode)          ; QAES crypter - Try decrypt magic
      
      If get_magic=magic
        cryptextender_length+get_fake_length
        get_cryptextender_length=cryptextender_length
        If mode=1
          CloseFile(file)
          ProcedureReturn "HINT ##06QF - This is a valid"+method_0$+"file !"
        ElseIf mode=3
          check_integrity=1
        ElseIf mode=4
          CloseFile(file)
          ProcedureReturn "ALLok ##07QF - File checked - This is a valid"+method_0$+"file !"
        ElseIf Not mode
          result=MessageRequester_simple_BF("HINT", #HINTS+"This is a valid"+method_0$+"file !"+#CRLF$+#CRLF$+
                                                    "Want to"+method__1$+"the file now ? - Select 'Yes'"+#CRLF$+#CRLF$+
                                                    "Just want to check the integrity of the file ? - Select 'Integrity check'"+#CRLF$+#CRLF$+
                                                    "Want to select another file ? - Select 'Another file'", #PB_MessageRequester_YesNoCancel, "Yes", "Another file", "Integrity check")
          If result=#PB_MessageRequester_Cancel
            key_1$=key_2$
            check_integrity=1
          ElseIf result=#PB_MessageRequester_No
            key_1$=key_2$
            CloseFile(file)
            Goto restart
          EndIf
        EndIf
        encrypted_file_found=1 : counter_0=get_counter
        For i = 0 To #HashLength>>3-1 : hash_2$+RSet(Hex(PeekA(@hash(0)+i)), 2, "0") : Next i : hash_2$=LCase(hash_2$)
      Else
        get_cryptextender_length=0
        If mode>1
          CloseFile(file)
          ProcedureReturn "HINT ##08QF - File checked - This is not a valid"+method_0$+"file - Or your key is wrong !"
        EndIf
        encrypt_1:
        If Not mode       
          message$="This file looks not valid"+method_0$+"!"+#CRLF$+#CRLF$+
                   "It is also possible that your password is wrong"+#CRLF$+
                   "Or it is possible that it is a corrupted"+method_0$+"file"+#CRLF$+#CRLF$+
                   "Want to"+method__0$+"this file now with your password ? - Select Yes"+#CRLF$+
                   "Want to select another file ? - Select Another File"+#CRLF$+
                   "Want you change your passwort ? - Select Cancel"
          result=MessageRequester_simple_BF("HINT", #HINTS+message$+#CRLF$+#CRLF$+"To change your password - Select 'Cancel'", #PB_MessageRequester_YesNoCancel, "Yes", "Another file", "Cancel")
          
          If result=#PB_MessageRequester_No
            key_1$=key_2$
            CloseFile(file) : Goto restart
          ElseIf result=#PB_MessageRequester_Cancel
            CloseFile(file) : key$="" : Goto restart
          EndIf
        EndIf
        QAES_smart_universal_coder_XEX(0, @magic, @magic, 8, ReverseString(key$)+key$, counter, 0, crypt_mode) ; QAES crypter - Encrypt magic
        counter_0=counter
      EndIf
      
    Else
      If Not mode
        MessageRequester("ERROR", "Can not open file")
        Goto select_again
      Else
        ProcedureReturn "ERROR ##09QF - Can not open file !"
      EndIf
    EndIf
    
    If progressbar_state=2
      SetGadgetState(progressbar_ID, 0)
    EndIf
    
    blocks=(file_size-cryptextender_length)/block_size
    
    remaining=file_size-(block_size*blocks)
    
    If encrypted_file_found
      remaining-cryptextender_length
    EndIf
    
    timer=ElapsedMilliseconds()
    Repeat
      readed=ReadData(file, *buffer, block_size)
      
      If encrypted_file_found
        hash_bytes=readed-cryptextender_length
        If readed=block_size : hash_bytes=readed : EndIf
        If hash_bytes>0
          block_counter+1
          If blocks
            If block_counter>blocks : hash_bytes=remaining : EndIf
          Else
            hash_bytes=file_size-cryptextender_length
          EndIf
          hash$=Fingerprint(*buffer, hash_bytes, #PB_Cipher_SHA3, #HashLength)
          hash$+key$+hash_1$+Str(counter_0)
          hash$=Fingerprint(@hash$, StringByteLength(hash$), #PB_Cipher_SHA3, #HashLength)
          hash_1$=hash$
        EndIf
      EndIf
      
      If Not check_integrity And Not use_protection_mode
        QAES_smart_universal_coder_XEX(0, *buffer, *buffer, block_size, key$, counter_0, counter_1, crypt_mode) ; QAES crypter
      EndIf
      
      If Not encrypted_file_found
        If readed>0
          hash$=Fingerprint(*buffer, readed, #PB_Cipher_SHA3, #HashLength)
          hash$+key$+hash_1$+Str(counter_0)
          hash$=Fingerprint(@hash$, StringByteLength(hash$), #PB_Cipher_SHA3, #HashLength)
          hash_1$=hash$
        EndIf
      EndIf
      
      If check_integrity
        writen+readed
      Else
        FileSeek(file, -readed, #PB_Relative) : writen+WriteData(file, *buffer, readed)
      EndIf
      
      If progressbar_state
        window_event=WindowEvent()
      EndIf
      If progressbar_state=2 And ElapsedMilliseconds()>timer+30
        SetGadgetState(progressbar_ID, 100*writen/file_size)
        timer=ElapsedMilliseconds()
      EndIf
      counter_0+1 : counter_1+1
    Until Not readed
    
    If progressbar_state=2
      SetGadgetState(progressbar_ID, 100)
    EndIf
    
    hash$+key$+#Salt$ ; Finishing fingerprint
    hash$=LCase(Fingerprint(@hash$, StringByteLength(hash$), #PB_Cipher_SHA3, #HashLength))
    
    If encrypted_file_found And hash$<>hash_2$
      If check_integrity
        CloseFile(file) : FreeMemory(*buffer) : *buffer=0
        If Not mode
          If MessageRequester_simple_BF("WARNING", "File hash broken !"+#CRLF$+#CRLF$+
                                                   "Want to use the file crypter again ? - Select 'Yes'",
                                        #PB_MessageRequester_YesNo, "Yes")=#PB_MessageRequester_No
            ProcedureReturn ""
          EndIf
          Goto restart
        Else
          ProcedureReturn "WARNING ##10QF - File hash broken ! - Used counter =>"+Str(get_counter)
        EndIf
        
      Else
        file_broken=1
      EndIf
    EndIf
    
    If check_integrity
      CloseFile(file) : FreeMemory(*buffer) : *buffer=0
      If Not mode
        SetClipboardText(GetFilePart(path$)+#CRLF$+hash_2$)
        If MessageRequester_simple_BF("Hint", #HINTS+"All OK !"+#CRLF$+#CRLF$+"File integrity succesfully checked !"+#CRLF$+#CRLF$+
                                              "I put now the file hash and name in your clipboard"+#CRLF$+#CRLF$+
                                              "Want to use the file crypter again ? - Select 'Yes'",
                                      #PB_MessageRequester_YesNo, "Yes")=#PB_MessageRequester_Yes
          Goto restart
        EndIf
      Else
        ProcedureReturn "ALLok ##11QF - File integrity succesfully checked ! - Used counter =>"+Str(get_counter)+" - File hash ==>"+hash_2$
      EndIf
      ProcedureReturn ""
    EndIf
    
    If use_protection_mode
      Protected old_RandomizeFileLengthBytes=RandomizeFileLengthBytes
      Protected old_EnlargeFileLengthBytes=EnlargeFileLengthBytes
      RandomizeFileLengthBytes=0
      EnlargeFileLengthBytes=8
    EndIf
    
    If OpenCryptRandom()
      set_fake_length.q=CryptRandom(RandomizeFileLengthBytes)+EnlargeFileLengthBytes
      Dim fake_content.a(set_fake_length-1)
      CryptRandomData(@fake_content(0), set_fake_length)
    Else
      set_fake_length.q=Random(RandomizeFileLengthBytes)+EnlargeFileLengthBytes
      Dim fake_content.a(set_fake_length-1)
      RandomData(@fake_content(0), set_fake_length)
    EndIf
    
    If use_protection_mode
      RandomizeFileLengthBytes=old_RandomizeFileLengthBytes
      EnlargeFileLengthBytes=old_EnlargeFileLengthBytes
    EndIf
    
    set_fake_length_1=set_fake_length
    
    get_cryptextender_length=cryptextender_length+set_fake_length
    
    If Not encrypted_file_found
      For i=0 To #HashLength>>3-1 : PokeA(@hash(0)+i, Val("$"+PeekS(@hash$+i*SizeOf(character)<<1, 2))) : Next i
      QAES_smart_universal_coder_XEX(0, @set_fake_length_1, @set_fake_length_1, 8, key$+ReverseString(key$), 0, 0, crypt_mode) ; QAES crypter - Crypt fake length
      QAES_smart_universal_coder_XEX(0, @hash(0), @hash(0), #HashLength>>3, key$+ReverseString(key$), counter, 0, crypt_mode)  ; QAES crypter - Crypt hash
      QAES_smart_universal_coder_XEX(0, @counter, @counter, 8, ReverseString(key$)+key$+#salt$, 0, 0, crypt_mode)              ; QAES crypter - Crypt counter
      
      writen+WriteData(file, @fake_content(0), set_fake_length)
      writen+WriteData(file, @set_fake_length_1, 8)
      writen+WriteData(file, @counter, 8)
      writen+WriteData(file, @magic, 8)
      writen+WriteData(file, @hash(0), #HashLength>>3)
      If writen<>file_size+cryptextender_length+set_fake_length
        CloseFile(file)
        If Not mode
          MessageRequester("ERROR", "Writen fails"+#CRLF$+#CRLF$+"Writen Bytes : "+Str(writen))
        Else
          ProcedureReturn "ERROR ##12QF - Writen fails - Writen Bytes : "+Str(writen)+" !"
        EndIf
        ProcedureReturn ""
      EndIf
    EndIf
    
    If encrypted_file_found
      FileSeek(file, -cryptextender_length, #PB_Relative)
      TruncateFile(file)
      If Lof(file)<>file_size-cryptextender_length
        CloseFile(file) : FreeMemory(*buffer)
        If Not mode
          MessageRequester("ERROR", "Truncate file fails")
        Else
          ProcedureReturn "ERROR ##13QF - Truncate file fails !"
        EndIf
        ProcedureReturn ""
      EndIf
    EndIf
    
    CloseFile(file)
    
    If file_extender$<>""
      If encrypted_file_found And Right(path$, Len(file_extender$))=file_extender$
        RenameFile(path$, Left(path$, Len(path$)-Len(file_extender$)))
      Else
        If Not encrypted_file_found
          RenameFile(path$, path$+file_extender$)
        EndIf
      EndIf
    EndIf
    
    If file_broken
      If Not mode
        message$="WARNING - File"+method_1$+"but file hash broken !"
      Else
        message$="WARNING ##14QF - File"+method_1$+"but file hash broken !"
      EndIf
    Else
      If encrypted_file_found
        If Not mode
          message$="All OK - File"+method_1$+"!"+#CRLF$+#CRLF$+
                   "I put now the file hash and name in your clipboard"+#CRLF$+#CRLF$
          SetClipboardText(GetFilePart(path$)+#CRLF$+hash_2$)
        Else
          message$="ALLok ##15QF - File"+method_1$+" ! - Used counter =>"+Str(get_counter)+" - File hash ==>"+hash_2$
        EndIf
      Else
        If Not mode
          message$="ALL OK - File "+method_0$+#CRLF$+#CRLF$+
                   "I put now the file hash and name in your clipboard"+#CRLF$+#CRLF$
          SetClipboardText(GetFilePart(path$)+#CRLF$+hash$)
        Else
          message$="ALLok ##16QF - File"+method_0$+" ! - File hash ==>"+hash$
        EndIf
      EndIf
    EndIf
    
    If Not mode
      If MessageRequester_simple_BF("HINT", #HINTS+message$+#CRLF$+#CRLF$+
                                            "Want to use the file crypter again ?",
                                    #PB_MessageRequester_YesNo, "Yes")=#PB_MessageRequester_Yes
        key_1$=key_2$
        Goto restart
      EndIf
    EndIf
    
    FreeMemory(*buffer)
    ProcedureReturn message$
    
  EndProcedure
  
  Procedure.s QAES_easy_file_coder(mode,
                                   window_ID,
                                   progressbar_ID,
                                   path_1$,
                                   key_1$,
                                   file_extender$,
                                   counter_key.q,
                                   crypt_mode)
    
    ProcedureReturn QAES_smart_file_coder(mode,
                                          window_ID,
                                          progressbar_ID,
                                          path_1$,
                                          key_1$,
                                          file_extender$,
                                          0, ; use_protection_mode.q
                                          counter_key.q,
                                          crypt_mode)   
  EndProcedure 
  
  Procedure.s QAES_easy_file_protector(mode,
                                       window_ID,
                                       progressbar_ID,
                                       path_1$,
                                       key_1$,
                                       counter_key.q,
                                       crypt_mode)
    
    ProcedureReturn QAES_smart_file_coder(mode,
                                          window_ID,
                                          progressbar_ID,
                                          path_1$,
                                          key_1$,
                                          "",
                                          1, ; use_protection_mode.q
                                          counter_key.q,
                                          crypt_mode)   
  EndProcedure 
  
  
EndModule
UseModule QAES_easy_file_coder

; Use demos
EnableExplicit

; String to file crypter module
; Addon for the QAES_smart_universal_coder_XEX
; Autor - W.Albus www.nachtoptik.de - Enhanced by Saki
; Purebasic x86 / x64
DeclareModule QAES_StringToFileCrypter
  UseModule QAES_smart_universal_coder_XEX
  UseModule QAES_easy_file_coder
  Declare QAES_create_encrypted_string_file(crypt_mode, string$, destination_path$, key$, add_protection=1, counter_key.q=0) ; protection=0 disable the protection - This create very small files
  Declare.s QAES_read_encrypted_string_file(crypt_mode, destination_path$, key$, counter_aes.q=0)
  Declare.s QAES_get_string_protection_state() ; Get the String file protection state - Usable after string crypter calls
EndDeclareModule

Module QAES_StringToFileCrypter
  EnableExplicit
  
  Global get_string_protection_state$
  
  Procedure QAES_create_encrypted_string_file(crypt_mode, string$, destination_path$, key$, add_protection=1, counter.q=0)
    ; Create a encrypted string file
    Protected file=CreateFile(#PB_Any, destination_path$)
    If file
      Protected counter_.q
      If OpenCryptRandom()
        CryptRandomData(@counter_, 8)
      Else
        RandomData(@counter_, 8)
      EndIf
      Protected *buffer=Ascii(string$)
      If Not *buffer : ProcedureReturn 0 : EndIf
      If Not QAES_smart_universal_coder_XEX(0, *buffer, *buffer, MemorySize(*buffer), key$, counter_, counter.q, crypt_mode)
        FreeMemory(*buffer) : ProcedureReturn 0
      EndIf
      If WriteData(file, *buffer, MemorySize(*buffer))<>MemorySize(*buffer)
        FreeMemory(*buffer) : ProcedureReturn 0
      EndIf
      FileSeek(file, Lof(file))
      If WriteQuad(file, counter_)<>8 : FreeMemory(*buffer) : ProcedureReturn 0 : EndIf
      CloseFile(file)
      FreeMemory(*buffer)
    Else
      ProcedureReturn 0
    EndIf
    If add_protection>0
      get_string_protection_state$=QAES_easy_file_protector(1, 0, 0, destination_path$, key$, counter, crypt_mode) ; Protect a file
    EndIf
    ProcedureReturn 1
  EndProcedure
  
  Procedure.s QAES_read_encrypted_string_file(crypt_mode, destination_path$, key$, counter.q=0)
    ; Read a encrypted string file
    get_string_protection_state$=QAES_easy_file_protector(3, 0, 0, destination_path$, key$, counter, crypt_mode) ; Check the file protection
    Protected file=ReadFile(#PB_Any, destination_path$)
    If Not file : ProcedureReturn "" : EndIf
    Protected *buffer=AllocateMemory(Lof(file))
    If Not *buffer : ProcedureReturn "" : EndIf
    If file
      Protected counter_.q
      If Left(get_string_protection_state$, 5)="ALLok" Or Left(get_string_protection_state$, 7)="WARNING"
        FileSeek(file, Lof(file)-8-QAES_get_cryptextender_length())
      Else
        FileSeek(file, Lof(file)-8)
      EndIf
      counter_=ReadQuad(file)
      FileSeek(file, 0)
      If Left(get_string_protection_state$, 5)="ALLok" Or Left(get_string_protection_state$, 7)="WARNING"
        If ReadData(file, *buffer, Lof(file)-8-QAES_get_cryptextender_length())<>Lof(file)-8-QAES_get_cryptextender_length() : FreeMemory(*buffer) : EndIf
      Else
        If ReadData(file, *buffer, Lof(file)-8)<>Lof(file)-8 : FreeMemory(*buffer) : EndIf
      EndIf
      FileSeek(file, 0)
      If Not QAES_smart_universal_coder_XEX(0, *buffer, *buffer, MemorySize(*buffer), key$, counter_, counter.q, crypt_mode)
        FreeMemory(*buffer) : ProcedureReturn ""
      EndIf
      Protected string$=PeekS(*buffer , -1, #PB_Ascii )
      CloseFile(file)
    Else
      ProcedureReturn ""
    EndIf
    If *buffer : FreeMemory(*buffer) : EndIf
    ProcedureReturn string$
  EndProcedure
  
  Procedure.s QAES_get_string_protection_state()
    ProcedureReturn get_string_protection_state$
  EndProcedure
  
EndModule
UseModule QAES_StringToFileCrypter

DeclareModule QAES_smart_image_coder
  UseModule QAES_smart_universal_coder_XEX
  Declare QAES_LoadImage_Encrypt_and_Save(source_path_image$, destination_path_image$, key$, counter_aes.q, crypt_mode=0)
  Declare QAES_LoadImage_and_Decrypt(destination_path_image$, key$, counter_aes.q=0, crypt_mode=0)
EndDeclareModule

Module QAES_smart_image_coder
  ; Image in place encrypting addon for the QAES_smart_universal_coder_XEX
  ; Author Werner Albus - www.nachtoptik.de
  ; Its nice you set a hint in your software for using QAES contents
  ; PureBasic
  Procedure QAES_LoadImage_Encrypt_and_Save(source_path_image$, destination_path_image$, key$, counter_aes.q, crypt_mode=0)
    
    Protected file=ReadFile(#PB_Any, source_path_image$)
    If Not file : ProcedureReturn -21 : EndIf
    Protected counter.q
    If OpenCryptRandom()
      CryptRandomData(@counter, 8)
    Else
      RandomData(@counter, 8)
    EndIf
    Protected length=Lof(file)
    Protected *buffer=AllocateMemory(length+8)
    If Not *buffer : CloseFile(file) : ProcedureReturn -9 : EndIf
    If Not ReadData(file, *buffer, length)
      FreeMemory(*buffer) : CloseFile(file) : ProcedureReturn -21
    EndIf
    CloseFile(file)
    PokeQ(*buffer+length, counter)
    If Not QAES_smart_universal_coder_XEX(0, *buffer, *buffer, length, key$, counter, counter_aes, crypt_mode)
      FreeMemory(*buffer) : ProcedureReturn -9
    EndIf
    file=OpenFile(#PB_Any, destination_path_image$)
    If Not file : FreeMemory(*buffer) : ProcedureReturn -22
    EndIf
    If WriteData(file, *buffer, length+8)<>length+8
      FreeMemory(*buffer) : CloseFile(file) : ProcedureReturn -22
    EndIf
    CloseFile(file)
    If *buffer : FreeMemory(*buffer) : EndIf
    ProcedureReturn 1
  EndProcedure
  
  Procedure QAES_LoadImage_and_Decrypt(destination_path_image$, key$, counter_aes.q=0, crypt_mode=0)
    Protected file=ReadFile(#PB_Any, destination_path_image$)
    If Not file : ProcedureReturn -21 : EndIf
    Protected length=Lof(file)
    Protected *buffer=AllocateMemory(length)
    If Not *buffer : CloseFile(file) : ProcedureReturn -9 : EndIf
    FileSeek(file, length-8)
    Protected counter.q=ReadQuad(file)
    FileSeek(file, 0)
    If ReadData(file, *buffer, length)<>length
      FreeMemory(*buffer) : CloseFile(file) : ProcedureReturn -21
    EndIf
    CloseFile(file)
    If Not QAES_smart_universal_coder_XEX(0, *buffer, *buffer, length, key$, counter, counter_aes, crypt_mode)
      FreeMemory(*buffer) : CloseFile(file) : ProcedureReturn -9
    EndIf
    Protected image_ID=CatchImage(#PB_Any, *buffer, length)
    If Not image_ID : FreeMemory(*buffer) : ProcedureReturn -6 : EndIf
    ProcedureReturn image_ID
  EndProcedure
EndModule

CompilerIf #PB_Compiler_IsMainFile
  UseModule QAES_smart_image_coder
  
  Define mode, key_stretching_loops, window_ID, progressbar_ID , key$, salt$, path_0$, path_1$
  
  window_ID=OpenWindow(#PB_Any, 0, 0, 280, 50, "",  #PB_Window_ScreenCentered|#PB_Window_BorderLess)
  progressbar_ID=ProgressBarGadget(#PB_Any, 10, 10, 260, 30, 0, 100, #PB_ProgressBar_Smooth)
  
  ; Available KFB crypt modes (crypt_mode)
  ; 0  = XEX Preset - same 1
  ; 1  = XEX dual mode with double XOR
  ; 2  = XDX dual mode with double XOR
  ; 3  = E   mode
  ; 4  = D   mode
  ; 5  = EE  dual mode
  ; 6  = DD  dual mode
  ; 7  = ED  dual mode
  ; 8  = DE  dual mode
  ; 9  = EDE triple mode
  ; 10 = DED triple mode
  ; 11 = DDE triple mode
  ; 12 = EED triple mode
  ; 13 = DEE triple mode
  ; 14 = EDD triple mode
  ; 15 = DDD triple mode
  ; 16 = EEE triple mode
  ; 17 = E   mode - Compatible to older versions
  
  ; Set the crypt_mode values negative for using with SHA3 based post coder
  ; As sample -10 = with SHA3 based post coder
  
  Define crypt_mode=0
  
  #cryptfile_extender$=" [encrypted]" ; You can change how ever you want
  
  #automatic_mode=1 ; TODO
  
  ; QAES_Salter("qtf756$") ; You can set a salt for the crypter
  
  If #automatic_mode
    Define counter=0 ; The counter works same a salt - But internal included in the crypter
    key$=""          ; This open a integrated string selector
    Define path$=""  ; This open a integrated file requester
    
    #file_protection_without_encrypting=0 ; TODO Select file protection without encrypting or file crypting, with requesters
    
    If #file_protection_without_encrypting
      ; For automatic file protection with requesters and without encrypting a file use it so
      QAES_easy_file_protector(mode, window_ID, progressbar_ID, path$, key$, counter, crypt_mode)
    Else
      ; For automatic file crypting with requesters use it so
      QAES_easy_file_coder(mode, window_ID, progressbar_ID, path$, key$, #cryptfile_extender$, 0, crypt_mode)
    EndIf
  EndIf
  
  #Full_self_check_manual_modes=0 ; TODO
  
  If #Full_self_check_manual_modes
    ; Manual modes
    key_stretching_loops=1e4 ; Key stretching loops
    
    ; Use ever key stretching - This impeded key brute force quite substantial
    ; You can, but you must not set a window and a progressbar for the key stretching progress
    salt$="41a219&$()(/=/(&(605nnufDTUKKLÖNM65w32ß0c9ß87/=)(" ; Salt - You can change
    key$=QAES_Key_stretching(window_ID, progressbar_ID, key$, salt$, key_stretching_loops)
    
    path_0$=GetTemporaryDirectory()+"TestPic_1.jpg" ; Create a little picture for test
    path_1$=path_0$+#cryptfile_extender$
    DeleteFile(path_1$) ; Remove artifacts
    UseJPEGImageEncoder()
    SaveImage(CreateImage(#PB_Any, 10, 10), path_0$, #PB_ImagePlugin_JPEG)
    Define counter=0
    Debug "###### File crypter ###"
    Debug QAES_easy_file_coder(1, window_ID, progressbar_ID, path_0$, key$, #cryptfile_extender$, counter, crypt_mode) ; Encrypt a file
    Debug QAES_easy_file_coder(4, window_ID, progressbar_ID, path_1$, key$, #cryptfile_extender$, counter, crypt_mode) ; Check if the file is already valid encrypted
    Debug "Crypt extender length : "+QAES_get_cryptextender_length()                                                   ; Length from the added crypt extender
    Debug QAES_easy_file_coder(3, window_ID, progressbar_ID, path_1$, key$, #cryptfile_extender$, counter, crypt_mode) ; Check the file integrity
    Debug QAES_easy_file_coder(2, window_ID, progressbar_ID, path_1$, key$, #cryptfile_extender$, counter, crypt_mode) ; Decrypt a file
    Debug ""
    
    Debug "###### File protection without encrypt a file ###"
    ; File format = Data + 8 Bytes counter + Crypt extender
    SaveImage(CreateImage(#PB_Any, 10, 10), path_0$, #PB_ImagePlugin_JPEG)
    Debug QAES_easy_file_protector(1, window_ID, progressbar_ID, path_0$, key$, 0, crypt_mode) ; Protect a file
    Debug QAES_easy_file_protector(4, window_ID, progressbar_ID, path_0$, key$, 0, crypt_mode) ; Check if the file is already valid encrypted
    Debug QAES_easy_file_protector(3, window_ID, progressbar_ID, path_0$, key$, 0, crypt_mode) ; Check the file protection - Also for encrypted files
    Debug "Crypt extender length : "+QAES_get_cryptextender_length()                           ; Length from the added crypt extender
    Debug QAES_easy_file_protector(2, window_ID, progressbar_ID, path_0$, key$, 0, crypt_mode) ; Remove the file protection
    Debug ""
    
    Debug "###### In place image crypter with file creating ###"
    DeleteFile(path_0$+#cryptfile_extender$) ; Remove artifacts
    UseJPEGImageEncoder()
    Debug "State - create, encrypt and save a image : "+QAES_LoadImage_Encrypt_and_Save(path_0$, path_0$+#cryptfile_extender$, key$, 0, crypt_mode)
    UseJPEGImageDecoder()
    Debug "Load and decrypt a image - Resulted Image ID : "+QAES_LoadImage_and_Decrypt(path_0$+#cryptfile_extender$, key$, 0, crypt_mode)
    Debug ""
    
    Debug "###### In place string and CSV crypter with file creating ###"
    Define destination_path$=GetTemporaryDirectory()+"/Testfile"
    DeleteFile(destination_path$) ; Remove artifacts
    Define string$="The quick brown fox jumps over the lazy dog ßÄÖÜäöü 0123456789"
    Define crypt_mode=8 ; Used crypt mode
    Define counter=10
    Define add_protection=1 ; protection=0 disable the protection - this create very small files - Enabled is preset, you must not set this parameter
    QAES_Adjust_FaceLength(1, 1) ; Adjust the lengt from a faked content - This disguises the original file length -Here for sample we reduce it - Without parameters set it to default 128, 256
    QAES_create_encrypted_string_file(crypt_mode, string$, destination_path$, key$, add_protection, counter)
    Debug "Used crypt mode : "+QAES_get_crypt_mode(); Get the used crypt mode
    QAES_Adjust_FaceLength()                        ; Set back to default
    Debug QAES_get_string_protection_state()        ; Get the String file protection state - Usable after string crypter calls
                                                    ; Read a encrypted string file
    Debug QAES_read_encrypted_string_file(crypt_mode, destination_path$, key$, counter)
    Debug QAES_get_string_protection_state() ; Get the String file protection state - Usable after string crypter calls
    Debug ""
    
    ; String crypting - In place crypting - With string termination protection
    ; Hint : Created pseudo control characters in the encrypted string can temporarily change the font size or other in the debugger window
    Debug "###### In place string crypter ###"
    Define string_source$="Hello World, this is the QAES_smart_universal_coder_XEX"
    Debug "Plain string : "+string_source$ ; Plain string
                                           ; Encrypt string
    QAES_smart_universal_coder_XEX(SizeOf(character), @string_source$, @string_source$, StringByteLength(string_source$), key$)
    Debug "Encrypted string : "+string_source$ ; Encrypted string
                                               ; Decrypt string
    QAES_smart_universal_coder_XEX(SizeOf(character), @string_source$, @string_source$, StringByteLength(string_source$), key$)
    Debug "Decrypted string : "+string_source$ ; Decrypted string
  EndIf
CompilerEndIf
Last edited by Saki on Mon Sep 28, 2020 6:12 pm, edited 40 times in total.
地球上の平和
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: QAES AES256 XEX & KFB mode crypter for string, binary, t

Post by Saki »

Hi,
A few small basic demo codes for easy use with strings and files.

Best Regards Saki

; Sample : In place String crypting with this crypter 8) - Add the Module

Code: Select all

UseModule QAES_smart_universal_coder_XEX
EnableExplicit
; Sample for in place string crypting
Define string$="The quick brown fox jumps over the lazy dog 0123456789"
QAES_smart_universal_coder_XEX(SizeOf(character), @string$, @string$, StringByteLength(string$), "Your key") ; QAES crypter - String mode - XEX mode
Debug string$ ; Encrypted
QAES_smart_universal_coder_XEX(SizeOf(character), @string$, @string$, StringByteLength(string$), "Your key") ; QAES crypter - String mode - XEX mode
Debug string$ ; Decrypted
; Sample : In place file crypting with this crypter - Add the Module

Code: Select all

UseModule QAES_smart_universal_coder_XEX
EnableExplicit

CompilerIf #PB_Compiler_Debugger : MessageRequester("Debugger", "Please deactivate firstly the debugger !") : End : CompilerEndIf

;- Crypt a file in it self
Define file, file_size, readed, writen, *buffer
Define path$=OpenFileRequester("Select a file to encrypting or decrypting !", "", "*.*", 0)
If path$="" : End : EndIf

file=OpenFile(#PB_Any, path$)

If file
  file_size=Lof(file) : *buffer=AllocateMemory(file_size)
  readed=ReadData(file, *buffer, file_size)
  If readed<>file_size : MessageRequester("ERROR", "Reading fails"+#LFCR$+#LFCR$+"Readed Bytes : "+Str(readed)) : EndIf
  ; QAES_smart_universal_coder_XEX(0, *buffer, *buffer, file_size, "Your key", 0, 0, 1) ; QAES crypter - Binary mode - KFB mode
  QAES_smart_universal_coder_XEX(0, *buffer, *buffer, file_size, "Your key") ; QAES crypter - Binary mode - XEX mode
  FileSeek(file, 0)
  writen=WriteData(file, *buffer, readed)
  CloseFile(file) : FreeMemory(*buffer)
  If writen<>file_size : MessageRequester("ERROR", "Writen fails"+#LFCR$+#LFCR$+"Coded Bytes : "+Str(writen)) : EndIf
  #crypt_extender$=" [encrypted]"
  If Right(path$, Len(#crypt_extender$))=#crypt_extender$
    RenameFile(path$, Left(path$, Len(path$)-Len(#crypt_extender$)))
  Else
    RenameFile(path$, path$+#crypt_extender$)
  EndIf
EndIf
; Sample : Blockwise in place file crypting with this crypter - Add the Module

Code: Select all

UseModule QAES_smart_universal_coder_XEX

EnableExplicit

CompilerIf #PB_Compiler_Debugger : MessageRequester("Debugger", "Please deactivate firstly the debugger !") : End : CompilerEndIf

;- Crypt a file blockwise in it self ----------------------------------
Define file, file_size, readed, writen, block_size, *buffer

Define mode=0    ; Binary mode
Define counter=0 ; You can set a counter how ever you want, also negative

Define path$=OpenFileRequester("Select a file to encrypting or decrypting !", "", "*.*", 0)
If path$="" : End : EndIf
OpenWindow(1, 0, 0, 300, 50, "QAES crypter works - please wait", #PB_Window_ScreenCentered)
ProgressBarGadget(1, 10, 10, 280, 30, 0, 100, #PB_ProgressBar_Smooth)
file=OpenFile(#PB_Any, path$)

Define timer=ElapsedMilliseconds()
If file
  file_size=Lof(file) : block_size=4096*4 : FileBuffersSize(file, block_size ) : *buffer=AllocateMemory(block_size)
  Repeat
    readed=ReadData(file, *buffer, block_size)
    QAES_smart_universal_coder_XEX(mode, *buffer, *buffer, block_size, "Your key", counter, 0, 1) ; QAES crypter - Binary mode - KFB mode
    FileSeek(file, -readed, #PB_Relative) : writen+WriteData(file, *buffer, readed)
    While WindowEvent() : Wend
    If ElapsedMilliseconds()>timer+30
      SetGadgetState(1, 100*writen/file_size)
      timer=ElapsedMilliseconds()
    EndIf
    counter+1
  Until Not readed
  CloseFile(file) : FreeMemory(*buffer)
  If writen<>file_size : MessageRequester("ERROR", "Writen fails"+#LFCR$+#LFCR$+"Coded Bytes : "+Str(writen)) : EndIf
  #crypt_extender$=" [encrypted]"
  If Right(path$, Len(#crypt_extender$))=#crypt_extender$
    RenameFile(path$, Left(path$, Len(path$)-Len(#crypt_extender$)))
  Else
    RenameFile(path$, path$+#crypt_extender$)
  EndIf
EndIf
File Protection can also be applied to any encrypted or unencrypted file.

It is already integrated in the FileCrypter addon.

Example Result :
#### File protection without encrypt a file ###
ALLok ##16QF - File protected ! - File hash ==>851039acf9350805f70315b74df68e20e155bc9de0259baff9e5719e1906b665
ALLok ##11QF - File integrity succesfully checked ! - Used counter =>10 - File hash ==>851039acf9350805f70315b74df68e20e155bc9de0259baff9e5719e1906b665
ALLok ##15QF - File unprotected ! - Used counter =>10 - File hash ==>851039acf9350805f70315b74df68e20e155bc9de0259baff9e5719e1906b665
[/code]
Last edited by Saki on Tue Sep 22, 2020 7:41 pm, edited 5 times in total.
地球上の平和
User avatar
blueb
Addict
Addict
Posts: 1041
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: QAES AES256 XEX & KFB mode crypter for string, binary, t

Post by blueb »

Your second sample (; Sample : In place file crypting with this crypter) does not work correctly.

I created a simple 3 line text file using Notepad.

Here's the sample text file contents...

Code: Select all

A CSS file is a cascading style sheet (CSS) file used to format the contents of a webpage. It contains customized, global properties for how to display HTML elements. CSS files can define the size, color, font, line spacing, indentation, borders, and location of HTML elements.

CSS files are used to create a similar look and feel across websites. They also are used to reduce the amount of work and HTML code generated by consolidating display properties into a single file.

CSS files are stored in a plain text format, which means you can open and edit them with any text editor.

After encryption, I open the file in Wordpad and I can see the original text (as well as the encryption characters).

When I 'decrypted' this same file, I see the original text and more encryption characters.
- It was too lonely at the top.

System : PB 6.10 Beta 9 (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: QAES AES256 XEX & KFB mode crypter for string, binary, t

Post by Saki »

Many thanks for the hint blueb.

I have forgot to reset the file pointer to zero after reading the file.
So the encrypted file is added to the end from the non encrypted.
It becomes longer and longer, looks funny but is good for nothing.

If you notice anything else, please write a short note.
I change it now.

Best Regards Saki
地球上の平和
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: QAES AES256 XEX & KFB mode crypter for string, binary, t

Post by Demivec »

The code for the modules in your first posting contains example code also which should be enclosed in CompilerIf #PB_Compiler_IsMainFile/Endif, unless you wish it to be broken up into the separate modules for usage.

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
  UseModule QAES_smart_image_coder
  
  Define mode, key_stretching_loops, window_ID, progressbar_ID , key$, salt$, path_0$, path_1$
  
  ; mode=0 - Full automatic mode with file selectors
  ; mode=1 - Encrypt
  ; mode=2 - Decrypt
  ; mode=3 - Check the file integrity
  ; mode=4 - Check if a file is already encrypted
  ; If not window_ID or not progressbar_ID, you get not a progressbar
  ; A empty key (Password) open automatically a string selector
  
  window_ID=OpenWindow(#PB_Any, 0, 0, 280, 50, "",  #PB_Window_ScreenCentered|#PB_Window_BorderLess)
  progressbar_ID=ProgressBarGadget(#PB_Any, 10, 10, 260, 30, 0, 100, #PB_ProgressBar_Smooth)
  
  #cryptfile_extender$=" [encrypted]" ; You can change how ever you want
  
  key$="This is a test key" ; If you do not pass a key for automatic mode, a key requester opens
  
  salt$="41a219&$()(/=/(&(605nnufDTUKKLÖNM65w32ß0c9ß87/=)(" ; Salt - You can change
  
  key_stretching_loops=1e5 ; Key stretching loops
  
  ; Use ever key stretching - This impeded key brute force quite substantial
  ; You can, but you must not set a window and a progressbar for the key stretching progress
  key_stretching(window_ID, progressbar_ID, key$, salt$, key_stretching_loops)
  
  ; Automatic file crypting with requesters - Activate only this one line :
  QAES_smart_file_coder(0, window_ID, progressbar_ID, "", key$, #cryptfile_extender$)
  
  ; Manual modes
  path_0$=GetTemporaryDirectory()+"TestPic_1.jpg" ; Create a little picture for test
  path_1$=path_0$+#cryptfile_extender$
  DeleteFile(path_1$) ; Remove artifacts
  UseJPEGImageEncoder()
  SaveImage(CreateImage(#PB_Any, 10, 10), path_0$, #PB_ImagePlugin_JPEG)
  Debug "###### File crypter ###"
  Debug QAES_smart_file_coder(1, window_ID, progressbar_ID, path_0$, key$, #cryptfile_extender$) ; Encrypt a file
  Debug QAES_smart_file_coder(4, window_ID, progressbar_ID, path_1$, key$, #cryptfile_extender$) ; Check if the file is already valid encrypted
  Debug QAES_smart_file_coder(3, window_ID, progressbar_ID, path_1$, key$, #cryptfile_extender$) ; Check the file integrity
  Debug QAES_smart_file_coder(2, window_ID, progressbar_ID, path_1$, key$, #cryptfile_extender$) ; Decrypt a file
  Debug ""
  
  Debug "###### File protection without encrypt a file ###"
  SaveImage(CreateImage(#PB_Any, 10, 10), path_0$, #PB_ImagePlugin_JPEG)
  Debug QAES_smart_file_coder(1, window_ID, progressbar_ID, path_0$, key$, "", 10) ; Protect a file
  Debug QAES_smart_file_coder(3, window_ID, progressbar_ID, path_0$, key$, "", 10) ; Check the file protection - Also for encrypted files
  Debug QAES_smart_file_coder(2, window_ID, progressbar_ID, path_0$, key$, "", 10) ; Remove the file protection
  Debug ""
  
  Debug "###### In place image crypter with file creating ###"
  DeleteFile(path_0$+#cryptfile_extender$) ; Remove artifacts
  UseJPEGImageEncoder()
  Debug "State - create, encrypt and save a image : "+LoadImage_Encrypt_and_Save(path_0$, path_0$+#cryptfile_extender$, key$)
  UseJPEGImageDecoder()
  Debug "Load and decrypt a image - Resulted Image ID : "+LoadImage_and_Decrypt(path_0$+#cryptfile_extender$, key$)
  Debug ""
  
  Debug "###### In place string and CSV crypter with file creating ###"
  Define destination_path$=GetTemporaryDirectory()+"/Testfile"
  DeleteFile(destination_path$) ; Remove artifacts
  Define string$="The quick brown fox jumps over the lazy dog 0123456789"
  ; Create a encrypted string file -----------------
  create_encrypted_string_file(string$, destination_path$, key$)
  ; Read a encrypted string file ----------------
  Debug read_encrypted_string_file(destination_path$, key$)
  Debug ""
  
  ; String crypting - In place crypting - With string termination protection
  ; Hint : Created pseudo control characters in the encrypted string can temporarily change the font size or other in the debugger window
  Debug "###### In place string crypter ###"
  Define string_source$="Hello World, this is the QAES_smart_universal_coder_XEX"
  Debug "Plain string : "+string_source$ ; Plain string
                                         ; Encrypt string
  QAES_smart_universal_coder_XEX(SizeOf(character), @string_source$, @string_source$, StringByteLength(string_source$), key$)
  Debug "Encrypted string : "+string_source$ ; Encrypted string
                                             ; Decrypt string
  QAES_smart_universal_coder_XEX(SizeOf(character), @string_source$, @string_source$, StringByteLength(string_source$), key$)
  Debug "Decrypted string : "+string_source$ ; Decrypted string
CompilerEndIf
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: QAES AES256 XEX & KFB mode crypter for string, binary, t

Post by Saki »

Hi,
yes, you're right, is better.
I've already changed it.
地球上の平和
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: QAES AES256 XEX & KFB mode crypter for string, binary, t

Post by Caronte3D »

Thanks Saki :wink:

Is there a way to decode a string encrypted with this module but from php or another server side language?
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: QAES AES256 XEX & KFB mode crypter for string, binary, t

Post by Saki »

Hi, you can't do that with this Crypter.
With PHP I think it should be AES128 , CFB or other Mode.
I can create crypters similar the PB solution for CBC, i think.
Last edited by Saki on Wed Sep 16, 2020 9:07 pm, edited 1 time in total.
地球上の平和
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: QAES AES256 XEX & KFB mode crypter for string, binary, t

Post by Caronte3D »

I need CBC because the code uses initialization vector.
The code is from: phpaes.com
I ask you for future.use :wink:
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: QAES AES256 XEX & KFB mode crypter for string, binary, t

Post by Saki »

This is exactly what PB shows in the manual,
You only have to look how the key is passed and if the text is passed as hex and the text format.
It should not be difficult.
I can certainly help you, but I need to know exactly what you need.
If there is only the slightest difference it will not work.
But we will probably do that with PN.
地球上の平和
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: QAES AES256 XEX & KFB mode crypter for string, binary, t

Post by Caronte3D »

I don't need it for now, I'm just collecting information for future use.
Thanks Saki! :wink:
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: QAES AES256 XEX & KFB & SHA3 crypter for string,binary,t

Post by Saki »

The Crypter is now again revised and extended.

A SHA3 based Crypt mode has been added, which extends the XEX mode again.

You can indeed use cryptographic hashes to encrypt and decrypt data, but this is little known.

Based on a SHA3 256 bit hash, a post encryption is realized which uses an AES XEX mode encrypted key.

There is no way I can crack it, but it is probably something for people who are looking for the final kick or who suffer from anxiety.

The String to file Crypter can now optionally create files with protection against changes.

And a few more little things.

These new functions must not be integrated into thirt party encryption modules.
I want to prevent the functions from working incorrectly there.
Otherwise the use of this crypter is free, but without guarantee and at your own risk.

Best Regards Saki
Last edited by Saki on Tue Sep 22, 2020 8:09 pm, edited 1 time in total.
地球上の平和
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: QAES AES256 XEX & KFB & SHA3 crypter for string,binary,t

Post by Saki »

The Crypter is again strongly extended and optimized.

KFB Dual mode added.
Fake length abilities enhanced.
And more details.

If I notice anything else, I will add or change it.
Otherwise everything is ready now.
Other minor changes are only noted in the version number at the top of the thread.

This new code is directly usable as stand alone crypter, compile only and you can use

More hints :
You can set a counter for file protection.
This counter is key dependent, but it is not necessary and will be returned as it was passed.
It can also be used to number protected files.
This way, for example, the completeness can be ensured.
If, for example, there are to be 10 files, they can be numbered consecutively.
This works similar to how GadgetData would work for files.

Therefore, the file protect mode is used to manage files that can be viewed and used.

Image
Last edited by Saki on Fri Sep 25, 2020 7:48 am, edited 2 times in total.
地球上の平和
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: QAES AES256 XEX & KFB & SHA3 crypter for string,binary,t

Post by Saki »

Last extensions and optimisations.
There are now 34 different Crypt modes available.
New function for creating a embedded salt added.

The counters of the crypter work also similar to a salt,
they are deeply embedded in the crypter itself.
Bruteforce the password becomes impossible with an unknown used counter or salt.
地球上の平和
Post Reply