It is currently Thu Jul 18, 2019 10:16 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: [PB 4.40] AESEncoder() and Strings
PostPosted: Mon Sep 21, 2009 6:59 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3598
Location: Berlin, Germany
Hi all!

Example in the documentation of AESEncoder() wrote:
If AESEncoder(@String$, *CipheredString, Len(String$), ?Key, 128, ?InitializationVector)
Debug "Ciphered: "+PeekS(*CipheredString)

So do the data that are produced by AESEncoder() never contain Chr(0), so that it's always safe to use PeekS() like in this example?

Regards, Little John

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: [PB 4.40] AESEncoder() and Strings
PostPosted: Mon Sep 21, 2009 7:06 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8004
Location: Fort Nelson, BC, Canada
The encoded string will indeed contain zeros, you can't use peeks() on it. If you want to look at it in its raw form you'll have to think of something else.

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: [PB 4.40] AESEncoder() and Strings
PostPosted: Mon Sep 21, 2009 8:36 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3598
Location: Berlin, Germany
Hi netmaestro,

thanks for clarifying that!
I hope it will be corrected in the docs.

Regards, Little John

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: [PB 4.40] AESEncoder() and Strings
PostPosted: Mon Sep 21, 2009 9:01 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8004
Location: Fort Nelson, BC, Canada
Tiny demo to show:
Code:
;; Text encryption test...

key$ = "Four score and seven years ago, and so on and so on"

a$="You can't handle the truth! Son, we live in a world that has walls. And those walls have to be guarded by men with guns."
a$+" Who's gonna do it? You? You, Lt. Weinberg? I have a greater responsibility than you can possibly fathom."
a$+" You weep for Santiago and you curse the Marines. You have that luxury. You have the luxury of Not knowing what I know:"
a$+" that Santiago's death, while tragic, probably saved lives. and my existence, while grotesque and incomprehensible"
a$+" to you, saves lives...You don't want the truth. Because deep down, in places you don't talk about at parties,"
a$+" you want me on that wall. You need me on that wall. We use words like honor, code, loyalty...we use these words"
a$+" As the backbone to a life spent defending something. You use 'em as a punchline. I have neither the time nor the inclination"
a$+" to explain myself to a man who rises and sleeps under the blanket of the very freedom I provide, then questions the manner"
a$+" in which I provide it! I'd rather you just said thank you and went on your way. Otherwise, I suggest you pick up a weapon"
a$+" and stand a post. Either way, I don't give a damn what you think you're entitled to! "

Structure Init_Vector ; I picked an init vector size = cipher blocksize
  byte.a[32]
EndStructure

*initvector.Init_Vector = AllocateMemory(32)

RandomSeed(189470) ; for testing I'm using same init vector every time

For i=0 To 31
  *initvector\byte[i] = Random(255)
Next

*encoded = AllocateMemory(Len(a$))

AESEncoder(@a$,*encoded,Len(a$),@key$,128,*initvector)
For i=*encoded To *encoded+MemorySize(*encoded)
  charlist$+RSet(Str(PeekB(i)&$FF),3,"0")+","
Next
charlist$ = Left(charlist$,Len(charlist$)-1)

Debug "Encoded memory block contains "+Str(CountString(charlist$,"000"))+" zero bytes"

*decoded = AllocateMemory(MemorySize(*encoded))
AESDecoder(*encoded,*decoded,MemorySize(*encoded),@key$,128,*initvector)

result$ = PeekS(*decoded,MemorySize(*decoded))

MessageRequester("",result$, $80)

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: [PB 4.40] AESEncoder() and Strings
PostPosted: Mon Sep 21, 2009 10:19 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3598
Location: Berlin, Germany
netmaestro wrote:
Tiny demo to show:

Oh yes! We actually should be aware of this, when using AESEncoder().
Thanks again!

Regards, Little John

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye