Author: Dann Corbit
Date: 16:18:24 04/27/05
Go up one level in this thread
On April 27, 2005 at 11:57:56, Brian Kostick wrote:
>I wrote a little password masking function for Win32 console. I'd like to hide
>string literals in my executable. I know such things have been mentioned here
>before for more clandestine purposes. My question is, is there an easiest way to
>do this or should I use an encryption or lookup function?
>
>Thanks,
>Brian
/* Here's a classic: */
#include <ctype.h>
/*=============================================================*/
/* WARNING! Requires an alphabet size EVENLY divisible by 2! */
/* WARNING! Assumes that the alphabet is contiguous and that */
/* the smallest lower case letter is at MIN_LOWER_CASE and the */
/* smallest upper case letter starts at MIN_UPPER_CASE. */
/*=============================================================*/
#define ALPHABET_SIZE 26
#define HALF_ALPHABET_SIZE (ALPHABET_SIZE/2)
#define MIN_LOWER_CASE 'a'
#define MIN_UPPER_CASE 'A'
int rot13(int c)
{
int base = MIN_LOWER_CASE; /* Lower case is more common */
if (isalpha(c)) {
if (isupper(c))
base = MIN_UPPER_CASE;
c = (c - base + HALF_ALPHABET_SIZE) % ALPHABET_SIZE + base;
} return c;
}
#ifdef UNIT_TEST
void rotate(char *s)
{
int i;
for (i = 0; *s; i++) {
*s = rot13(*s);
s++;
}
}
char string[32767];
#include <stdio.h>
#include <string.h>
int main(void)
{
while (fgets(string, sizeof string, stdin)) {
char *where = strchr(string, '\n');
if (where) *where = 0;
printf("Original string: [%s]\n", string);
rotate(string);
printf("Transformed string: [%s]\n", string);
rotate(string);
printf("Transformed back: [%s]\n", string);
}
return 0;
}
/*
the quick brown fox jumped over the lazy dog's back 1234567890 times
Original string: [the quick brown fox jumped over the lazy dog's back
1234567890 times]
Transformed string: [gur dhvpx oebja sbk whzcrq bire gur ynml qbt'f onpx
1234567890 gvzrf]
Transformed back: [the quick brown fox jumped over the lazy dog's back
1234567890 times]
THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG'S BACK 1234567890 TIMES
Original string: [THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG'S BACK
1234567890 TIMES]
Transformed string: [GUR DHVPX OEBJA SBK WHZCRQ BIRE GUR YNML QBT'F ONPX
1234567890 GVZRF]
Transformed back: [THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG'S BACK
1234567890 TIMES]
*/
#endif
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.