473,729 Members | 2,086 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

encrypting with preprocessor

Hi,

I want to build a encryption macro set, that can crypt:

char secret[] = CRYPT("KungFu") ;

to anything unreadable, and then have a function:
char* DECRYPT(char* str)
{
...
}

I think it would be suffictient to encrypt a maximum of 16 characters.
Simple XOR would suffice, too. Any ideas of how that can be done?

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%c gl%ssic%ccom%c" , "ma", 58, 'g', 64, "ba", 46, 10);}

_______________ _______________ __________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Jul 13 '06 #1
25 7978
Gernot Frisch wrote:
Hi,

I want to build a encryption macro set, that can crypt:

char secret[] = CRYPT("KungFu") ;

to anything unreadable, and then have a function:
char* DECRYPT(char* str)
{
...
}

I think it would be suffictient to encrypt a maximum of 16 characters.
Simple XOR would suffice, too. Any ideas of how that can be done?
Yes, but it is a bit long to explain and needs a lot of macros (about
200-400 macros) to do it as far as you accept to write:

char secret[] = CRYPT(K,u,n,g,F ,u);

instead of a string as a parameters, then CRYPT could output a crypted
string of octal codes for example.

I know this is not an answer, but doing this with macros really require
a "package" of macros to manipulate list of token (e.g. map, cat, merge,
etc...) plus a set of arithmetic and logic operations. I have a such
package so I can provide it on request but it hasn't any documentation.

a+, ld.
Jul 13 '06 #2

"Laurent Deniau" <la************ @cern.chschrieb im Newsbeitrag
news:e9******** **@sunnews.cern .ch...
Gernot Frisch wrote:
>Hi,

I want to build a encryption macro set, that can crypt:

char secret[] = CRYPT("KungFu") ;

to anything unreadable, and then have a function:
char* DECRYPT(char* str)
{
...
}

I think it would be suffictient to encrypt a maximum of 16
characters. Simple XOR would suffice, too. Any ideas of how that
can be done?

Yes, but it is a bit long to explain and needs a lot of macros
(about 200-400 macros) to do it as far as you accept to write:

char secret[] = CRYPT(K,u,n,g,F ,u);

instead of a string as a parameters, then CRYPT could output a
crypted string of octal codes for example.

I know this is not an answer, but doing this with macros really
require a "package" of macros to manipulate list of token (e.g. map,
cat, merge, etc...) plus a set of arithmetic and logic operations. I
have a such package so I can provide it on request but it hasn't any
documentation.
can you give a grief explaination on how to make it?
Jul 13 '06 #3
Gernot Frisch said:
Hi,

I want to build a encryption macro set, that can crypt:

char secret[] = CRYPT("KungFu") ;

to anything unreadable, and then have a function:
char* DECRYPT(char* str)
{
...
}

I think it would be suffictient to encrypt a maximum of 16 characters.
Simple XOR would suffice, too. Any ideas of how that can be done?
#define CRYPT(x) my_encryption_r outine(x)

I don't think you can do this without calling a function, although I would
be very interested in seeing a counter-example.

My reasoning is as follows: you'd need to do this in a single expression
that doesn't involve a compound statement (because compound statements are
not mere expressions, so they don't yield a value, which wouldn't be so bad
if they played nice with comma operators - but they don't). A function gets
around these problems nicely, but I don't see any other way to do it. In
C99 you could use an inline function, I suppose.

<OT>
If you happen to be using gcc, I think you can use a GNU extension which
allows compound statements in macros to yield results. A gcc newsgroup
would be a good place to ask about this.
</OT>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 13 '06 #4
#define CRYPT(x) my_encryption_r outine(x)
That way the string itself could be found&searched for in the binary.
That's what I want to prevent.
Jul 13 '06 #5
Gernot Frisch wrote:
"Laurent Deniau" <la************ @cern.chschrieb im Newsbeitrag
news:e9******** **@sunnews.cern .ch...
>>Gernot Frisch wrote:
>>>Hi,

I want to build a encryption macro set, that can crypt:

char secret[] = CRYPT("KungFu") ;

to anything unreadable, and then have a function:
char* DECRYPT(char* str)
{
...
}

I think it would be suffictient to encrypt a maximum of 16
characters . Simple XOR would suffice, too. Any ideas of how that
can be done?

Yes, but it is a bit long to explain and needs a lot of macros
(about 200-400 macros) to do it as far as you accept to write:

char secret[] = CRYPT(K,u,n,g,F ,u);

instead of a string as a parameters, then CRYPT could output a
crypted string of octal codes for example.

I know this is not an answer, but doing this with macros really
require a "package" of macros to manipulate list of token (e.g. map,
cat, merge, etc...) plus a set of arithmetic and logic operations. I
have a such package so I can provide it on request but it hasn't any
documentation .


can you give a grief explaination on how to make it?
- convert K,u,n,g,F,u to the list (6,(K,u,n,g,F,u ))
- create a list of macros, say CODE_, ending with the letters (26*2 + 1
macros) which expand to value/code
- apply concat(CODE_,to k) to the list
- optionally apply some transformation/crypt algo to the list elements
- apply a convertion from value to octal code
- concat the element of the list into a single token
- stringify the result.

As I said, doing this requires somehow 200-300 stupid and repetitive
macros to handle set of values and about 20 smart macros to transform
the list.

a+, ld.
Jul 13 '06 #6
Richard Heathfield wrote:
Gernot Frisch said:
>Hi,

I want to build a encryption macro set, that can crypt:

char secret[] = CRYPT("KungFu") ;
(fx:snip)
#define CRYPT(x) my_encryption_r outine(x)

I don't think you can do this without calling a function, although I would
be very interested in seeing a counter-example.
Doesn't that not-work in the OPs example? Possible uses of `sizeof (secret)`
may preclude transforming it to `char *secret = CRYPT("KungFu") ;`.

--
Chris "seeker" Dollin
"We did not have time to find out everything we wanted to know." /A Clash of Cymbals/

Jul 13 '06 #7
Chris Dollin said:
Richard Heathfield wrote:
>Gernot Frisch said:
>>Hi,

I want to build a encryption macro set, that can crypt:

char secret[] = CRYPT("KungFu") ;

(fx:snip)
>#define CRYPT(x) my_encryption_r outine(x)

I don't think you can do this without calling a function, although I
would be very interested in seeing a counter-example.

Doesn't that not-work in the OPs example?
Oh yes, of course you're right. And in any case, it now transpires that his
reason for wanting the macro is that he doesn't want the string literal to
appear in the binary. I wish he'd said so at the outset.

Now that I know this, I suggest he simply pre-computes the encryption via a
separate program that he does not release. Let the output of the separate
program be, for example:

{
0x34, 0x29, 0xF3, 0xA2, 0x77, 0x21
};

(or whatever), and be saved as secret1.enc. He can then do this:

char secret[] =
#include "secret1.en c"

Problem solved, without any gerharsterly macros.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 13 '06 #8
Richard Heathfield wrote:
Chris Dollin said:
>Richard Heathfield wrote:
>>Gernot Frisch said:

Hi,

I want to build a encryption macro set, that can crypt:

char secret[] = CRYPT("KungFu") ;

(fx:snip)
>>#define CRYPT(x) my_encryption_r outine(x)

I don't think you can do this without calling a function, although I
would be very interested in seeing a counter-example.

Doesn't that not-work in the OPs example?

Oh yes, of course you're right. And in any case, it now transpires that his
reason for wanting the macro is that he doesn't want the string literal to
appear in the binary. I wish he'd said so at the outset.

Now that I know this, I suggest he simply pre-computes the encryption via a
separate program that he does not release. Let the output of the separate
program be, for example:

{
0x34, 0x29, 0xF3, 0xA2, 0x77, 0x21
};

(or whatever), and be saved as secret1.enc. He can then do this:

char secret[] =
#include "secret1.en c"

Problem solved, without any gerharsterly macros.
A similar approach would be to write

char secret[] = CRYPTOF_KungFu;

where CRYPTOF_KungFu is a macro which gets #defined somehow: in a single
#included "cryptic.h" file or even as -D options to his compiler commands
if his implementation has such.

Of course suitable conventions and seddery and such allow the extraction
of any number of such CRYPTOF uses in the code, so long as the crypted
things can appear in macro names.

--
Chris "what do you mean, 'overkill'?" Dollin
"Life is full of mysteries. Consider this one of them." Sinclair, /Babylon 5/

Jul 13 '06 #9
>Now that I know this, I suggest he simply pre-computes the
encryption via a
separate program that he does not release. Let the output of the
separate
program be, for example:

{
0x34, 0x29, 0xF3, 0xA2, 0x77, 0x21
};

(or whatever), and be saved as secret1.enc. He can then do this:

char secret[] =
#include "secret1.en c"

Problem solved, without any gerharsterly macros.

A similar approach would be to write

char secret[] = CRYPTOF_KungFu;

where CRYPTOF_KungFu is a macro which gets #defined somehow: in a
single
#included "cryptic.h" file or even as -D options to his compiler
commands
if his implementation has such.

Of course suitable conventions and seddery and such allow the
extraction
of any number of such CRYPTOF uses in the code, so long as the
crypted
things can appear in macro names.
That's exaclty what I don't want - using an external program. I just
want to write my source code and have the precompiler mess with it.
Jul 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2090
by: Dayne | last post by:
Guys, I am writing a database application(vb.net , sql server) and is presently storing the connection settings in a xml file...not very secure though. What is a safer method in a dynamic environment? Dayne
205
10670
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
24
40234
by: Nudge | last post by:
I have an array, and an unrolled loop which looks like this: do_something(A); do_something(A); .... do_something(A); I thought: why should I type so much? I should write a macro. So I was looking to write something along the lines of:
16
4499
by: Trying_Harder | last post by:
Is it possible to redefine a macro with global scope after undefining it in a function? If yes, could someone explain how? /If/ my question above isn't very clear you can refer to the following example. eg cosider 2 files sample.c and sample.h sample.h
13
2132
by: Chris Croughton | last post by:
Is the following code standard-compliant, and if so what should it do? And where in the standard defines the behaviour? #include <stdio.h> #define DEF defined XXX int main(void) { int defined = 2;
9
3657
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot seem to find a justification for the behaviour. Could someone point me to the appropriate section, or else confirm the behaviour as a bug? For a particular project, I am using the C preprocessor phase only. I am not using the standalone program 'cpp' because proper functioning of my project...
32
2793
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input the same file ? If not then how much variation is allowed ? Is it just a bit more or less white space here and there or could could there be larger differences ? If the output is not deterministic then is it possible that the output of the...
2
2274
by: SeeSharp Bint | last post by:
Visual Studio 2005, dotnet, c#. Microsoft SQL Server. Windows XP forms application. Temporarily, for my database application, I have been storing the various elements of database connection items like datasource,password,userid as plain strings in the registry. I'd now like to make these secure against people reading them. I thought of encrypting/decrypting each string when i write to the registry but I wouldnt know where to find a...
31
2923
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes statements that the compiler does not process. The good people in the alt.comp.lang.learn.c-c++ newsgroup insist that the preprocessor is just one of many passes. The preprocessor processes a grammer unique to the preprocessor and only that grammer. ...
0
8928
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8766
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9428
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9291
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8160
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6026
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.