[SOLVED] How to convert this Perl decryption to C++?

Contribute code to SolydXK and make it even better.
Deleted User 2764

[SOLVED] How to convert this Perl decryption to C++?

Postby Deleted User 2764 » 15 Jan 2015 02:15

I'm working on something that was written in perl and I'm wanting to convert it to C++. The perl code is:

Code: Select all

    my $cipher = Crypt::CBC->new( -key => $salt_key, -cipher => 'DES' -header => 'none');
    return $cipher->decrypt_hex($enc_text);
Now I need to do the same thing in C++. I didn't include all of the code as basically it's not needed for the example. The example above basically sets a salt key, sets the CBC cipher to DES, no headers and then decrypts it assuming the string to decrypt ($enc_text) contained hexidecimal numbers/letters.

Anyone any good at this can tell me how to do it?

I'm trying to use the libgcrypt20 library for this.

User avatar
Arjen Balfoort
Site Admin
Posts: 9253
Joined: 26 Jan 2013 19:36
Location: Netherlands
Contact:

Re: How to convert this Perl decryption to C++?

Postby Arjen Balfoort » 15 Jan 2015 07:52

I'm sorry, I don't speak perl...nor C++ for that matter :?


SolydXK needs you!
Development | Testing | Translations

Deleted User 2764

Re: How to convert this Perl decryption to C++?

Postby Deleted User 2764 » 15 Jan 2015 14:49

No problem. At least someone saw the message. :) I'm very good with perl. The problem is, I forgot my C++ (and I had completed at least 2 books and 1 online course which I got 100% on the final exam on that language)! Go figure! :oops:

The problem here is learning that gcrypt library. I have the .pdf manual but as with any manual or man page I read, I could spend a month reading it and still not know what they heck they are talking about!

If anyone out there knows the answer, or knows of where I can ask the question (any Linux programming forums out there?) please do post here.

mhwelsh
Posts: 253
Joined: 15 Apr 2013 18:48

Re: How to convert this Perl decryption to C++?

Postby mhwelsh » 16 Jan 2015 12:04

Join the crowd, we are all born with a hole in the brain as you get older the hole gets bigger!

If you don't use it you will lose it.

I also sympathise with the reading filter - if it is more than two sentences the filter shuts off.

It is annoying because most of the authors are using a format which has evolved to be foolproof, they are very conscientious, but they are clever and assume that the reader is equally clever and not the fool who is reading it.


martin welsh

Deleted User 2764

Re: How to convert this Perl decryption to C++?

Postby Deleted User 2764 » 16 Jan 2015 14:58

Being that I've written my own share of technical documents (my web site has a few as well), I know it's not easy to write something that everyone will understand. One thing I try to do is at least provide working sample code (not pseudo code) so people can at least cut and paste, and adapt in a hurry. Thing is, that's not even easy to do in some cases.

Good thing I work in Eclipse, though. It at least points me to the bugs and gives me a clue as to what I'm doing wrong.

I've given up the C code thing for the moment as I think this is above and beyond me. I've found a way to compile the perl code but now a new problem is in now to get the output into another script. Why am I hiding the code? So nobody can hack in and find out how to decode and breach some stuff that is encoded. But there has to be a better approach than the one I'm taking right now in the first place.

Deleted User 2764

Re: How to convert this Perl decryption to C++?

Postby Deleted User 2764 » 02 Jul 2015 15:17

For anyone lurking or still might be able to answer, I've posted this question on Stack Overflow along with some C (not C++) code I've written up using Eclipse (it's generic C). I got it to encrypt but it won't decrypt the encrypted item.

http://stackoverflow.com/questions/3118 ... -linux-gcc

Of course if you're just authenticating, you wouldn't need to decrypt, just encrypt the input password, encrypt that, then compare that encrypted input to the stored encrypted password. But what I need to do is also reconstruct accounts where you have to know the password to recreate the account in the event that there is a server change or account was removed and then someone wants to reactivate it, for example (ie. for proftpd, etc.), thus the need for decryption.

Deleted User 2764

Re: How to convert this Perl decryption to C++?

Postby Deleted User 2764 » 02 Jul 2015 19:34

The answer was just posted to Stack Overflow. Solved the problem - partially. Now to get it into the format like it is in the perl version. I think I can figure that out the rest of the way.

Marking this solved.

User avatar
Arjen Balfoort
Site Admin
Posts: 9253
Joined: 26 Jan 2013 19:36
Location: Netherlands
Contact:

Re: [SOLVED] How to convert this Perl decryption to C++?

Postby Arjen Balfoort » 03 Jul 2015 04:16

Wow, and you actually understood what he was writing about?
That's way over my head.


SolydXK needs you!
Development | Testing | Translations

Deleted User 2764

Re: [SOLVED] How to convert this Perl decryption to C++?

Postby Deleted User 2764 » 03 Jul 2015 11:47

Yeah, I understood enough to know what went wrong. I forgot that you don't want to make an array and not define the size of it in C. C is very picky. It's like making a fixed array of say, the size of 3 in Python and then trying to fill it with 4 or 5 items. Python at least tells you that you are trying to put too much in the array. C will not. It will just put garbage in the array. C is hard to debug because of all that. I didn't use C++ (I think there are more descriptive error messages in that). I figured what I'm doing was simple enough for the command line and thus used plain C. I haven't used C or C++ in *ages* so I kinda forgot things!

Also, the function was a little complicated to understand but I got the gist of it. The hardest part was figuring how to get the data in because it's complicated how it goes in. I found code on the web that did that but I still had trouble getting it to work. Luckily the only problem was the array thing.

I'm very good with perl. I need to get better with Python (which I'm doing that by playing around with Python and QT4 on my off time when I can as part of working on the DDM) and I want to get good at C/C++

You know the saying "use it or lose it"! :) So I will need to do more projects with these languages!


Return to “Code”

Who is online

Users browsing this forum: No registered users and 1 guest