Page 1 of 1
DES encryption anyone?
Posted: Thu Oct 30, 2008 12:45 pm
by Joakim Christiansen
I've searched the forum and internet for anything I could use, but had no luck...
Someone linked to this:
http://www.iancrt.co.uk/PureBasic/des.pb.txt
But that site is gone...
I think I need the original DES encryption, not the 3DES algorithm, but both would be nice anyway.
Posted: Thu Oct 30, 2008 12:58 pm
by graves
Re: DES encryption anyone?
Posted: Thu Oct 30, 2008 1:29 pm
by PB
> that site is gone
Stick the link into Archive.org and you can get it again (copy and paste the URL):
http://web.archive.org/web/*/http://www ... des.pb.txt
But a question: PureBasic has a DESFingerPrint() command, so why not use that?
Re: DES encryption anyone?
Posted: Thu Oct 30, 2008 4:56 pm
by Mohawk70
But a question: PureBasic has a DESFingerPrint() command, so why not use that?
Because that is a one way HASHing function. He is talking about DES (En/De)cryption.
Posted: Thu Oct 30, 2008 6:09 pm
by tinman
IIRC 3DES is just DES applied 3 times (forward/backwards/forwards) so you could use the same single length key for both parts (assuming a double length key) of the 3DES key and you'd end up with DES encrypted data.
If it uses a triple length key then just use the single length key 3 times.
Posted: Thu Oct 30, 2008 6:17 pm
by Joakim Christiansen
Actually I'm trying to handshake with a VNC client, it sends me a 16bit random string which I must encrypt with DES using the right key(password) and send back to be authenticated.
I must admit... that I did not understand how to use this:
http://web.archive.org/web/200408261109 ... des.pb.txt
At least not right away, maybe if I REALLY study it I can make it work.
Posted: Tue Mar 24, 2009 5:40 pm
by Joakim Christiansen
I was able to find some Perl, PHP and Javascript sources:
http://www.tero.co.uk/des/code.php
If no one else here want to convert it to PB I can maaaaaybe (probably not) give it a try...
But how on earth do I write something like this in PB?
Code: Select all
$lefttemp = $pc2bytes0[$left >> 28 & $masks[28]] | $pc2bytes1[($left >> 24 & $masks[24]) & 0xf]
Well, mostly I wonder about the " >> & | " part, does they work the same in PB?
And numbers like "0x1010400" and "-0x7fef7fe0" how do you write those in PB?
Posted: Tue Mar 24, 2009 6:03 pm
by idle
Joakim Christiansen wrote:
But how on earth do I write something like this in PB?
Code: Select all
$lefttemp = $pc2bytes0[$left >> 28 & $masks[28]] | $pc2bytes1[($left >> 24 & $masks[24]) & 0xf]
Well, mostly I wonder about the " >> & | " part, does they work the same in PB?
And numbers like "0x1010400" and "-0x7fef7fe0" how do you write those in PB?
yes >> & | behave the same just use brackets, something like this
Code: Select all
lefttemp = (pc2bytes0((left >> 28) & masks(28)) | pc2bytes1(((left >> 24) & masks(24)) & $f))
As for the -Hex not sure but I think you can ignore the sign.
Posted: Tue Mar 24, 2009 6:11 pm
by Pupil
What you have to watch out for is the '>>' operator. If the number is negative it'll shift in '1' into the highest bit. In other words, you'll need to identify if it's necessary to mask away those extra '1':s everywhere this operator is used.
Also '0x11' is hex and you'll only need to remove the '0x'-part and just put '$' there instead. So '0x11' translates to '$11' in PB.
Posted: Tue Mar 24, 2009 6:16 pm
by Joakim Christiansen
Thanks for the info folks
Actually I found some source code in C now (used in TightVNC). Instead of trying to convert any source code I think trying to put together a DLL from that might be better. So I might try that instead.
Posted: Fri Mar 27, 2009 10:55 pm
by harkon
Okay, I know this might not be really simple, but the crypto API in Windows can do this.
Here's the contants declares form VB
Code: Select all
Private Const ALG_CLASS_DATA_ENCRYPT = 24576
Private Const ALG_CLASS_HASH = 32768
Private Const ALG_TYPE_ANY = 0
Private Const ALG_TYPE_BLOCK = 1536
Private Const ALG_TYPE_STREAM = 2048
Private Const ALG_SID_RC2 = 2
Private Const ALG_SID_RC4 = 1
Private Const ALG_SID_MD5 = 3
Private Const ALG_SID_DES = 1
Private Const CALG_MD5 = ((ALG_CLASS_HASH Or ALG_TYPE_ANY) Or ALG_SID_MD5)
Private Const CALG_RC2 = ((ALG_CLASS_DATA_ENCRYPT Or ALG_TYPE_BLOCK) Or ALG_SID_RC2)
Private Const CALG_RC4 = ((ALG_CLASS_DATA_ENCRYPT Or ALG_TYPE_STREAM) Or ALG_SID_RC4)
Private Const CALG_DES = (ALG_CLASS_DATA_ENCRYPT Or ALG_TYPE_BLOCK Or ALG_SID_DES)
There are of course other algorithms available, but this was a quick cut and paste job. Sorry about this being in VB but it's the reference material I have available. You can find a VB example at
http://allapi.mentalis.org/apilist/79AD ... 7E60B.html
It does show an RSA example in this, you might be able to make this work with DES.
Sorry I can't be of more help.
Re: DES encryption anyone?
Posted: Tue Jun 03, 2014 6:06 am
by coco2
*epic bump*
I have one now... I noticed your post before I made it to check it wasn't already done
http://www.purebasic.fr/english/viewtop ... 41#p445741
Re: DES encryption anyone?
Posted: Tue Jun 03, 2014 3:11 pm
by harkon
Thank you for doing this. I have no immediate need, but as I am doing more and more is Linux, I have the need to get off of the Windows API. Anything that does that for me is a plus. It's been added to my code repository. Great work.
Re: DES encryption anyone?
Posted: Tue Jun 03, 2014 11:05 pm
by coco2
Its the same reason I developed it, I like cross platform and linux in particular. My full PB TLS 1.2 module is about 20% done, so it'll be some time before I can release it.