Encrypt/Decrypt

Just starting out? Need help? Post your questions and find answers here.
SoFlawLess_
New User
New User
Posts: 5
Joined: Wed Jul 25, 2012 3:50 am

Encrypt/Decrypt

Post by SoFlawLess_ »

How would I encrypt/decrypt my buffer:

Code: Select all

      lBuf = AllocateMemory(sfsize)
      ReadData(#Source_File, lBuf, sfsize)
      CloseFile(#Source_File)
I've tried this but I'm not sure how to use it:
http://www.purebasic.fr/english/viewtopic.php?p=282549

:shock:
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Encrypt/Decrypt

Post by luis »

I suppose something like this (not tested):

XOrCrypt(lBuf, sfsize, "key of whatever length") ;encrypt

XOrCrypt(lBuf, sfsize, "key of whatever length") ;decrypt



The important point is: to any encryption/decryption routine you probably have to pass the address of your data ( lBuf ) and its length ( sfsize ) in a form or another.


EDIT:
Oh I'm sorry, I've put a "@" in front of lBuf that wasn't needed. Removed. :oops:
Force of habit when using a var that it isn't a pointer. Better use a pointer (*lBuf) like suggested by Warmonger. After all AllocateNemory return an address.
The address is a number so you can store it in an int like you did, but it's usually better to store it in a pointer, that is better suited to cope with further memory addressing operations.
Last edited by luis on Fri Jul 27, 2012 10:57 am, edited 1 time in total.
"Have you tried turning it off and on again ?"
Warmonger
Enthusiast
Enthusiast
Posts: 156
Joined: Wed Apr 20, 2011 4:24 pm

Re: Encrypt/Decrypt

Post by Warmonger »

Maybe something like this.

Code: Select all

;Get Length Of File
Length = Lof(#Source_File)
If Length
  ;Copy File Data Into Buffer
  *lBuf = AllocateMemory(Length)
  ReadData(#Source_File, *lBuf, Length)
  CloseFile(#Source_File)
  ;Encrypt Buffer Data
  XOrCrypt(*lBuf, Length, "1337")
Else
  MessageRequester("Error", "No data to read", #MB_ICONERROR)
EndIf
Its Not A Bug, Its An Undocumented Feature!
Relax Its All Just Ones And Zeros
There Is No Place Like 127.0.0.1 Except ::1
I do things TO my computer, not WITH my computer... I am a nerd.
Post Reply