Rabbit Escape  2017-01-14_18:33:47_+0000__(tag:_v0.10.1)
Static Public Member Functions | Private Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
rabbitescape.engine.util.MegaCoder Class Reference

Static Public Member Functions

static String encode (String input)
 
static String decode (String input)
 

Private Member Functions

 MegaCoder ()
 

Static Private Member Functions

static char[] getSortedUniqueChars (char[] charArray)
 
static char[] replaceUsingCharacterList (char[] charsListKey, char[] input)
 
static char[] exchangeCharacters (char[] chars, char a, char b)
 
static char[] shuffle (char[] input, int key)
 
static char[] copyArray (char[] input)
 

Static Private Attributes

static final char[] COMMON_CHARACTERS
 

Detailed Description

Obfuscate strings like a champion.

Swaps characters within the string around, swaps well-known characters with each other, and transposes the string by exchanging characters with other characters.

The MegaCoder is licensed here for use as part of rabbit-escape, but is also declared public domain, so that it may be used, without attribution, by anyone who needs obfuscation slightly more powerful than rot13, but less portable than base64. (For clarity, the MegaCoder is this single file).

The MegaCoder shuffle algorithm:

Input: An array of length l, A integer key k
i = 0
while at least two array entries remain unswapped:
  if array entry i has not been swapped:
    j = (floor(length / 2) + 3i + k) mod l
    while array entry j has already been swapped:
      j = (j + 1) mod l
    swap entries i and j in the array
  i = i + 1
Output: The modified array

The MegaCoder replace algorithm:

Input: An key array k of length l, An array of characters x
for i in [0, floor(l / 2)]:
  a = entry i in k; b = entry (l - 1 - i) in k
  replace all instances of a with b, and b with a, in the array x
Output: The modified array x

The MegaCoder uniquify algorithm:

Input: An array of characters x
Output: The set of characters in x sorted by value

The MegaCoder encode algorithm:

Input: An array of characters x of length l
k1 = uniquify(x)
x = replace(k1, x)
k2 = shuffle(C, l) where C is the array of ASCII characters from space (0x20) to tilde (0x7e)
x = replace(k2, x)
x = shuffle(x, 0)
Output: The modified array x

The MegaCoder decode algorithm:

Input: An array of characters x of length l
x = shuffle(x, 0)
k2 = shuffle(C, l) where C is the array of ASCII characters from space (0x20) to tilde (0x7e)
x = replace(k2, x)
k1 = uniquify(x)
x = replace(k1, x)
Output: The modified array x
Author
tttppp

Constructor & Destructor Documentation

rabbitescape.engine.util.MegaCoder.MegaCoder ( )
private

Private constructor for util class.

Member Function Documentation

static char [] rabbitescape.engine.util.MegaCoder.copyArray ( char[]  input)
staticprivate
static String rabbitescape.engine.util.MegaCoder.decode ( String  input)
static

Decode a string using the MegaCoder obfuscation routine.

Parameters
inputThe ciphertext to decode.
Returns
The plaintext.
static String rabbitescape.engine.util.MegaCoder.encode ( String  input)
static

Encode a string using the MegaCoder obfuscation routine.

Parameters
inputThe plaintext to encode.
Returns
The obfuscated ciphertext.
static char [] rabbitescape.engine.util.MegaCoder.exchangeCharacters ( char[]  chars,
char  a,
char  b 
)
staticprivate

Swap two characters with each other in a given characters list.

Parameters
charsThe list of characters to search through.
aA character.
bAnother character.
Returns
The input, but with all occurrences of a and b exchanged.
static char [] rabbitescape.engine.util.MegaCoder.getSortedUniqueChars ( char[]  charArray)
staticprivate

Create a new character array containing every character that appears in a given array once. The new array will be sorted by natural order.

Parameters
charArrayThe character array to process.
Returns
An array containing the sorted set of characters in the input.
static char [] rabbitescape.engine.util.MegaCoder.replaceUsingCharacterList ( char[]  charsListKey,
char[]  input 
)
staticprivate

Replace characters in a string using a key.

Parameters
charsListKeyA list of distinct characters. The first will be swapped with the last, and so on. If there is an odd number of characters then the middle character will not be swapped at all.
inputThe string to replace the characters in.
static char [] rabbitescape.engine.util.MegaCoder.shuffle ( char[]  input,
int  key 
)
staticprivate

Shuffle the characters in the given string.

Parameters
inputThe string to be shuffled.
keyA value that changes the shuffling algorithm.
Returns
The string with letters swapped around a bit.

Member Data Documentation

final char [] rabbitescape.engine.util.MegaCoder.COMMON_CHARACTERS
staticprivate
Initial value:
= new char[] {
' ', '!', '"', '#', '$', '%', '&',
'\'', '(', ')', '*', '+', ',',
'-', '.', '/', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', ':',
';', '<', '=', '>', '?', '@', 'A',
'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z', '[', '\\',
']', '^', '_', '`', 'a', 'b', 'c',
'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', '{', '|', '}', '~' }

A list of common ASCII characters that can be swapped with each other.


The documentation for this class was generated from the following file: