DES encryption anyone?

Everything else that doesn't fall into one of the other PB categories.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

DES encryption anyone?

Post 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... :cry:

I think I need the original DES encryption, not the 3DES algorithm, but both would be nice anyway.
I like logic, hence I dislike humans but love computers.
User avatar
graves
Enthusiast
Enthusiast
Posts: 160
Joined: Wed Oct 03, 2007 2:38 pm
Location: To the deal with a pepper

Post by graves »

PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: DES encryption anyone?

Post 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?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Mohawk70
Enthusiast
Enthusiast
Posts: 404
Joined: Thu May 11, 2006 1:04 am
Location: Florida, USA

Re: DES encryption anyone?

Post 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.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post 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.
I like logic, hence I dislike humans but love computers.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post 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?
I like logic, hence I dislike humans but love computers.
User avatar
idle
Always Here
Always Here
Posts: 6238
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post 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.

Code: Select all

$1010400 $7fef7fe0

 
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post 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.
I like logic, hence I dislike humans but love computers.
harkon
Enthusiast
Enthusiast
Posts: 217
Joined: Wed Nov 23, 2005 5:48 pm

Post 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.
Missed it by that much!!
HK
coco2
Enthusiast
Enthusiast
Posts: 488
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: DES encryption anyone?

Post 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
harkon
Enthusiast
Enthusiast
Posts: 217
Joined: Wed Nov 23, 2005 5:48 pm

Re: DES encryption anyone?

Post by harkon »

coco2 wrote:*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
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.
Missed it by that much!!
HK
coco2
Enthusiast
Enthusiast
Posts: 488
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: DES encryption anyone?

Post 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.
Post Reply