4.40b4 AES
Posted: Sun Oct 11, 2009 6:32 pm
Hi everybody!
I played around with this new AES feature and found some strange effects:
So, did I miss something?
I played around with this new AES feature and found some strange effects:
Code: Select all
; AES Demo Unicode
;
String$ = "to short"
; Is it a bug or a feature? if this string is shorter than 16 characters, nothing will happen. So you have to fill it up.
Debug "Original-String: " + String$ + " Length: " + Str(Len(String$))
If Len(String$) < 16: String$ + Space(16 - Len(String$)): Debug "String filled with Space to: " + Str(Len(String$)) + " characters": EndIf
BufferLen.l = StringByteLength(String$) ; This is the main problem for deciphering. You need to know the byte length of the original string!
*CipheredString = AllocateMemory(BufferLen)
If AESEncoder(@String$, *CipheredString, BufferLen, ?Key, 128, 0, #PB_Cipher_ECB)
String$ = PeekS(*CipheredString)
Debug "Ciphered: " + String$
EndIf
FreeMemory(*CipheredString)
If String$
*DecipheredString = AllocateMemory(BufferLen)
AESDecoder(@String$, *DecipheredString, BufferLen, ?Key, 128, 0, #PB_Cipher_ECB)
String$ = Trim(PeekS(*DecipheredString, BufferLen / SizeOf(Character)))
Debug "Deciphered: "+ String$ + " Length: " + Str(Len(String$))
FreeMemory(*DecipheredString)
EndIf
DataSection
Key:
Data.b $06, $A9, $21, $40, $36, $B8, $A1, $5B, $51, $2E, $03, $D5, $34, $12, $00, $06
EndDataSection