public class HexHarmless extends Object
Why harmless hex characters?
With the English language it is possible out of the
hex characters (0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f) to form words that might
be bad/funny/peculiar/offensive. The idea with harmless hex characters
is to replace vowels and vowel-like hex characters with consonants, the theory
being that in the English language it is near-impossible to form words
solely out of consonants.
The following replacements are done:
| ---- | ----------- | | char | replaced by | | ---- | ----------- | | 0 | g | | 1 | h | | 3 | k | | a | m | | e | t | | ---- | ----------- |thus as an example, the classic hex encoded string of
0ffaeb would become
gffmtb in harmless hex.
This docucters [2,4-9,b,c,d,f,g,h,k,m,t] as harmless hex chars.
Harmless hex exists only in the lower-case variant.
The concept of harmless hex characters exists in Google's Kubernetes
from where the character mapping in this class originates.
(source code link,
function encodeHash)
| Modifier and Type | Field and Description |
|---|---|
static char[] |
HARMLESS_HEX_CHARS
Characters allowed in harmless hex representation.
|
static String |
HARMLESS_HEX_REGEXP_CHARCLASS
Regular expression character set with the characters that are
allowed in harmless hex representation.
|
| Modifier and Type | Method and Description |
|---|---|
static char[] |
bytesToHexHarmless(byte[] bytes)
Converts a byte array to its harmless hexadecimal representation.
|
static String |
bytesToHexStrHarmless(byte[] bytes)
Converts a byte array to its harmless hexadecimal representation.
|
static char[] |
byteToHexHarmless(byte b)
Converts a single byte to its harmless hexadecimal representation.
|
static char |
convertFromHarmless(char c)
Returns classic hex char equivalent of the input harmless hex char.
|
static char[] |
convertFromHarmless(char[] chars)
Replaces harmless hex characters in the input array with their classic
hex char equivalents.
|
static char |
convertToHarmless(char c)
Returns harmless equivalent of the input hex char.
|
static char[] |
convertToHarmless(char[] chars)
Replaces classic hex characters in the input array with their harmless
equivalents.
|
static byte |
hexCharHarmlessToByte(char c1,
char c2)
Converts a harmless hex character pair into a byte.
|
static byte[] |
hexStrHarmlessToBytes(char[] chars)
Converts a character array consisting of harmless hexadecimal
characters into a byte array.
|
static byte[] |
hexStrHarmlessToBytes(CharSequence s)
Converts a character sequence (a string) consisting of harmless hexadecimal
characters into a byte array.
|
public static final String HARMLESS_HEX_REGEXP_CHARCLASS
public static final char[] HARMLESS_HEX_CHARS
public static char convertFromHarmless(char c)
c - hex charIllegalArgumentException - if input is not a lower-case harmless hex charconvertToHarmless(char)public static char convertToHarmless(char c)
c - harmless hex charIllegalArgumentException - if input is not a lower-case classic hex charconvertFromHarmless(char)public static char[] convertToHarmless(char[] chars)
chars - IllegalArgumentException - if input array contains characters
which are not lower-case classic hex char.public static char[] convertFromHarmless(char[] chars)
chars - IllegalArgumentException - if input array contains characters
which are not lower-case harmless hex char.public static char[] byteToHexHarmless(byte b)
See HexHarmless.
b - inputpublic static char[] bytesToHexHarmless(byte[] bytes)
bytes - inputpublic static String bytesToHexStrHarmless(byte[] bytes)
bytes - inputpublic static byte hexCharHarmlessToByte(char c1,
char c2)
't'
and 'k' returns the byte value 227.
The input values must be only the characters [4-9,b,c,d,f,m,t].
c1 - first character of pairc2 - second character of pairIllegalArgumentException - if either c1 or c2 is an illegal character.public static byte[] hexStrHarmlessToBytes(char[] chars)
The input must be of equal-length and consist only of lower-case harmless hex chars.
chars - inputnull if input is null.IllegalArgumentException - if input array contains characters
which are not lower-case harmless hex char.public static byte[] hexStrHarmlessToBytes(CharSequence s)
The input must be of equal-length and consist only of lower-case harmless hex chars.
s - inputnull if input is null.IllegalArgumentException - if input sequence contains characters
which are not lower-case harmless hex char.Copyright © 2022 lbruun.net. All rights reserved.