Advanced AES Crypter > Files &Strings &Termination Handling
Posted: Sat Nov 05, 2016 9:29 pm
Advanced universal AES256 OFB mode crypter for solving many problems and complicate things
With features you have never seen before on PB !
A very big problem is ever the string termination with encrypted strings
To time i have never seen before a working solution for this problem !
This coder has a answer and can encrypt any strings without termination problems !
You can simple encrypt with this little coder :
Files, Data, Ascii and Unicode Strings
No enlargement for encrypted data, all has ever exactely the same length, before and after encryption
No separately encoder and decoder needed, only one coder for encrypting and decrypting
No Base64 or HEX converting needed for string encryption
The coder can encrypt all things also in it self, without changed length or unwanted terminations
Or, as sample, you can encrypt ascii strings in a unicode application
No padding necessary
All Data lengths available from one byte upwards
Counter for blockwise crypting
Encrypted data looking alike CBC mode encrypted data
Dual OFB mode AES256 encryption
Key as simple string available
Absolutely simple to use, good nature, no crashes, no malfunctions
Very little.
Hints :
Further down you find a more enhanced code for blockwise encryption with counter and progressbar
Also a special addon for file crypting with this coder, with automaticaly file integrity check and more
On my websites you found a complete suite with DLL/SO and RSA part
http://www.nachtoptik.de
http://www.quick-aes-256.de
A alterable bare SHA3 512 bit based special crypter you found here
http://www.purebasic.fr/english/viewtop ... 27&t=68742
With features you have never seen before on PB !

A very big problem is ever the string termination with encrypted strings
To time i have never seen before a working solution for this problem !
This coder has a answer and can encrypt any strings without termination problems !
You can simple encrypt with this little coder :
Files, Data, Ascii and Unicode Strings
No enlargement for encrypted data, all has ever exactely the same length, before and after encryption
No separately encoder and decoder needed, only one coder for encrypting and decrypting
No Base64 or HEX converting needed for string encryption
The coder can encrypt all things also in it self, without changed length or unwanted terminations
Or, as sample, you can encrypt ascii strings in a unicode application
No padding necessary
All Data lengths available from one byte upwards
Counter for blockwise crypting
Encrypted data looking alike CBC mode encrypted data
Dual OFB mode AES256 encryption
Key as simple string available
Absolutely simple to use, good nature, no crashes, no malfunctions
Very little.
Hints :
Further down you find a more enhanced code for blockwise encryption with counter and progressbar
Also a special addon for file crypting with this coder, with automaticaly file integrity check and more
On my websites you found a complete suite with DLL/SO and RSA part
http://www.nachtoptik.de
http://www.quick-aes-256.de
A alterable bare SHA3 512 bit based special crypter you found here
http://www.purebasic.fr/english/viewtop ... 27&t=68742
Code: Select all
DeclareModule QAES_smart_universal_coder
Declare QAES_smart_universal_coder(mode, *buffer_in.word, *buffer_out.word, bytes.q, key$, counter_key.q=0, counter_aes.q=0)
UseSHA3Fingerprint()
EndDeclareModule
Module QAES_smart_universal_coder
EnableExplicit
; QAES AES256 OFB mode one or two stage special coder for all things - binarys - strings - text files
; This coder can handle automatic string termination for PB strings in compiler mode ASCII and UNICODE
; The coder works with all data lengths
; With mode ASCII you can encrypt mixed data, string and binary - This ignore the encryption from zero bytes
; The coder go ever forward, a extra decoder is unnecessary !
; You cipher a file blockwise, set ever the current block number (consecutive) with a counter - Important !
; Author Werner Albus - www.nachtoptik.de - www.quick-aes-256.de
; No warranty whatsoever - Use at your own risk
; counter_key.q : You cipher a file blockwise, set ever the current block number with this counter (consecutive numbering)
; counter_aes.q : This counter 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 personalize the coder, nobody can brute force a password from a unknown personalized 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 are 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
Procedure QAES_smart_universal_coder(mode, *buffer_in.word, *buffer_out.word, bytes.q, key$, counter_key.q=0, counter_aes.q=0)
If Not bytes.q Or key$="" : ProcedureReturn 0 : EndIf
#Salt$="t8690352cj2p1ch7fgw34u&=)?=)/%&§/&)=?(otmq09745$%()=)&%" ; Salt, you can change
Protected.q i, swap_, rounds.q=bytes>>4
Protected ii, iii, bytes_minus_x, stepp=SizeOf(character)<<1
Protected *register_asc.ascii, *register.word, *buffer_in_quad.quad, *buffer_out_quad.quad
Protected rest=bytes%16, bytes_minus_1=bytes-1
Protected *buffer_in_asc.ascii, *buffer_out_asc.ascii
Protected hash$=#Salt$+key$+Str(counter_key)+ReverseString(#Salt$)
Static fixed_key_string${64}
Static Dim register.q(3)
fixed_key_string$=Fingerprint(@hash$, StringByteLength(hash$), #PB_Cipher_SHA3, 256) ; Create a key
For ii = 0 To 31 : PokeA(@register(0)+ii, Val("$"+PeekS(@fixed_key_string$+iii, 2))) : iii+stepp : Next
register(1)+counter_aes
Macro go_1 ; One stage
register(0)+1
If Not AESEncoder(@register(0), @register(0), 32, @register(0), 256, 0, #PB_Cipher_ECB) : ProcedureReturn 0 : EndIf
swap_=register(0) : register(0)=register(3) : register(3)=swap_ ; Never use here
swap_=register(1) : register(1)=register(2) : register(2)=swap_ ; the PB swap function !
; register(2)+1 ; Activate for two stage crypting
; If Not AESEncoder(@register(0), @register(0), 32, @register(0), 256, 0, #PB_Cipher_ECB) : ProcedureReturn 0 : 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 : *register_asc=@register(0)
go_1
For ii=0 To bytes_minus_1
*buffer_out_asc\a=*buffer_in_asc\a ! *register_asc\a : *buffer_in_asc+1 : *buffer_out_asc+1 : *register_asc+1
Next
ProcedureReturn 1
EndIf
While i<rounds ; =>16 bytes
go_1
*buffer_out_quad\q=*buffer_in_quad\q ! register(0) : *buffer_in_quad+8 : *buffer_out_quad+8
*buffer_out_quad\q=*buffer_in_quad\q ! register(1) : *buffer_in_quad+8 : *buffer_out_quad+8 : i+1
Wend
If rest
*buffer_out_asc=*buffer_out_quad : *buffer_in_asc=*buffer_in_quad : *register_asc=@register(0)
go_1
For ii=0 To rest-1
*buffer_out_asc\a=*buffer_in_asc\a ! *register_asc\a : *buffer_in_asc+1 : *buffer_out_asc+1 : *register_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 : *register_asc=@register(0)
For ii=0 To 15
If *buffer_in_asc\a And *buffer_in_asc\a ! *register_asc\a
*buffer_out_asc\a=*buffer_in_asc\a ! *register_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 : *register_asc+1 : i+1
Next ii
ForEver
Else ; mode=2
bytes_minus_x=bytes-3
Repeat
go_1 : *register.word=@register(0)
For ii=0 To 15 Step 2
If *buffer_in\w And *buffer_in\w ! *register\w
*buffer_out\w=*buffer_in\w ! *register\w
Else
*buffer_out\w=*buffer_in\w
EndIf
If i>bytes_minus_x : Break 2 : EndIf
*buffer_in+2 : *buffer_out+2 : *register+2 : i+2
Next ii
ForEver
EndIf
ProcedureReturn 1
EndProcedure
EndModule
UseModule QAES_smart_universal_coder
; ============== AES256 OFB mode special coder - For files, binarys, text and strings =================
;; counter_key.q : You cipher a file blockwise, set ever the current block number (consecutive numbering) - This is important !
;; : You can set the counter as quad, positive and negative
;; key$ : You can use any strings as key
;; @string$ : Set the adress to the source data
;; @string_result$ : Set the adress to the destination data - Hint : It can also are 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
;
; ; A sample : QAES_smart_universal_coder(mode_ascii_or_unicode, *source_data, *destination_data, length_of_data, key$, counter)
;
; counter_key=123456
; string$="The quick brown fox jumps over the lazy dog"
; string$="A"+RSet("Z", 50, "x") ; Demo text string to encryption - For unicode, the length from 1 char = 2 bytes !
; key$="This is a simple key"
; ; mode=2 ; UNICODE
; mode=SizeOf(character)
;
; ; Encoding
; QAES_smart_universal_coder(mode, @string$, @string$, StringByteLength(string$), key$, counter)
; Debug "QAES smart universal coder : Encoded : "+string$
; ShowMemoryViewer(@string$,StringByteLength(string$))
; Debug ""
; ; Decoding
; QAES_smart_universal_coder(mode, @string$, @string$, StringByteLength(string$), key$, counter)
; Debug "QAES smart text coder : Decoded : "+string$
;-----------------------------------
mode=SizeOf(character)
path$ = OpenFileRequester("Select a file to encrypting or decrypting !", "", "*.*", 0)
file=OpenFile(#PB_Any, path$)
If file
*buffer=AllocateMemory(Lof(file))
ReadData(file, *buffer, MemorySize(*buffer))
QAES_smart_universal_coder(mode, *buffer, *buffer, MemorySize(*buffer), "Your key")
FileSeek(file, 0) : WriteData(file, *buffer, MemorySize(*buffer)) : CloseFile(file)
EndIf