HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_Obfuscator.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Obfuscator.h
7  *
8  * COMMENTS:
9  * This is a simple class that encodes and decodes ASCII
10  * strings. It uses a simple substitution cipher, so it
11  * is by no means "secure" in the same way true encryption
12  * is, and shouldn't be relied on exclusively for protection.
13  * While it uses a fixed table generated based on a seed,
14  * it can also take in a secondary key which it uses to permute
15  * the string to be encoded. Note that to decode the string back,
16  * the same key must be passed in.
17  *
18  * Please note that it currently only supports [A-Z][a-z][0-9] and
19  * '_' characters. Any other characters will not be substituted and
20  * will remain unchanged.
21  *
22  * The result of the encoding is guaranteed to be a valid ASCII string.
23  */
24 
25 
26 #ifndef __UT_Obfuscator_h__
27 #define __UT_Obfuscator_h__
28 
29 #include "UT_API.h"
30 #include "UT_String.h"
31 
32 #define NUM_LETTERS 26
33 #define NUM_DIGITS 10
34 // +1 for underscore
35 #define TOTAL_MAP_LEN (NUM_LETTERS*2 + NUM_DIGITS + 1)
36 
37 /*****************************************************************************/
39 {
40 public:
41  UT_Obfuscator();
42  ~UT_Obfuscator();
43 
44  void encode(UT_String& str_in_out, const char* extra_key_in = NULL);
45  void decode(UT_String& str_in_out, const char* extra_key_in = NULL);
46 
47 protected:
48 
49  void reset();
50 
51  void generateMap();
52  int getIndexForChar(char chr);
53 
54  void factorInExtraKey(UT_String& str_in_out, const char* extra_key);
55  void factorOutExtraKey(UT_String& str_in_out, const char* extra_key);
56 
57 private:
58 
59  char myMap[TOTAL_MAP_LEN];
60  char myRevMap[TOTAL_MAP_LEN];
61 };
62 /*****************************************************************************/
63 #endif
#define UT_API
Definition: UT_API.h:12
#define TOTAL_MAP_LEN
Definition: UT_Obfuscator.h:35