Jetzt habe ich diesen Code nochmal aufgegriffen und etwas abgeändert und wollte mal wissen, warum das so nicht funktioniert und was ich machen muss, damit alles so klappt wie ich das will.
Hier mal der veränderte Code:
Code: Alles auswählen
Procedure.s EnAES(String$, Key$)
Protected *CipheredString
While Len(String$) < 16
String$+Chr(10)
Wend
*CipheredString = AllocateMemory(StringByteLength(String$))
*Key = AllocateMemory(StringByteLength(Key$))
PokeS(*Key, Key$)
If AESEncoder(@String$, *CipheredString, StringByteLength(String$), *Key, 256, ?Init)
For n = 0 To Len(String$)-1
Output$ + Str(PeekC(*CipheredString+n*SizeOf(Character))) + " "
Next
EndIf
FreeMemory(*CipheredString)
ProcedureReturn Output$
EndProcedure
Procedure.s DeAES(String$, Key$)
Protected *Buffer = AllocateMemory(CountString(String$," ")*SizeOf(Character))
Protected *DecipheredString = AllocateMemory(CountString(String$," ")*SizeOf(Character))
For n = 0 To CountString(String$," ")-1
PokeC(*Buffer+n, Val(StringField(String$, n+1, " ")))
Next
*Key = AllocateMemory(StringByteLength(Key$))
PokeS(*Key, Key$)
If AESDecoder(*Buffer, *DecipheredString, MemorySize(*Buffer), *Key, 256, ?Init)
Output$ = RTrim(PeekS(*DecipheredString, CountString(String$," ")), Chr(10))
EndIf
FreeMemory(*DecipheredString)
FreeMemory(*Buffer)
ProcedureReturn Output$
EndProcedure
String$ = "Teststring"
Key$ = "variabler Schlüssel"
AES$ = EnAES(String$, Key$)
Plain$ = DeAES(AES$, Key$)
Debug String$
Debug AES$
Debug Plain$
DataSection
Init:
Data.b $3d, $af, $ba, $42, $9d, $9e, $b4, $30, $b4, $22, $da, $80, $2c, $9f, $ac, $41
EndDataSection
Edit:
Hier nochmal der Original-Code von STARGÅTE zum Verglich:
Code: Alles auswählen
Procedure.s EnAES(String$)
Protected *CipheredString
While Len(String$) < 16
String$+Chr(10)
Wend
*CipheredString = AllocateMemory(StringByteLength(String$))
If AESEncoder(@String$, *CipheredString, StringByteLength(String$), ?Key, 256, ?Init)
For n = 0 To Len(String$)-1
Output$ + Str(PeekC(*CipheredString+n*SizeOf(Character))) + " "
Next
EndIf
FreeMemory(*CipheredString)
ProcedureReturn Output$
EndProcedure
Procedure.s DeAES(String$)
Protected *Buffer = AllocateMemory(CountString(String$," ")*SizeOf(Character))
Protected *DecipheredString = AllocateMemory(CountString(String$," ")*SizeOf(Character))
For n = 0 To CountString(String$," ")-1
PokeC(*Buffer+n, Val(StringField(String$, n+1, " ")))
Next
If AESDecoder(*Buffer, *DecipheredString, MemorySize(*Buffer), ?Key, 256, ?Init)
Output$ = RTrim(PeekS(*DecipheredString, CountString(String$," ")), Chr(10))
EndIf
FreeMemory(*DecipheredString)
FreeMemory(*Buffer)
ProcedureReturn Output$
EndProcedure
String$ = "Kleines Problem mit manchen Texten. Woran könnte das liegen!? Würde mich gerne interessieren."
Debug EnAES(String$)
Debug DeAES(EnAES(String$))
DataSection
Key:
Data.b $06, $a9, $21, $40, $36, $b8, $a1, $5b, $51, $2e, $03, $d5, $34, $12, $00, $06
Init:
Data.b $3d, $af, $ba, $42, $9d, $9e, $b4, $30, $b4, $22, $da, $80, $2c, $9f, $ac, $41
EndDataSection