After reading
this post , I had an idea, is it possible to make a certain text completely invisible? The method described below does not claim to be effective in terms of speed or volume of data.
In short
We convert each byte of the string into a three-digit octal number and replace each digit with one of the invisible characters.
Scala implementation
»
GitHub Link
object Main extends App { val v = Array("\u2060", "\u200B", "\u2061", "\u2062", "\u2063", "\uFEFF", "\u200C", "\u200D") def str2oct(buf: Array[Byte]): String = buf.map("%03o" format _).mkString def oct2str(string: String): String = new String(string.sliding(3,3).toArray.map(x => BigInt(x,8).toByte)) def voidEnc(char: String):String = v(char.toInt) def voidDec(char:String):String = v.indexOf(char).toString def char2void(string: String): String = str2oct(string.getBytes()).map(x=>voidEnc(x.toString)).mkString def void2char(string: String):String = oct2str(string.map(x=>voidDec(x.toString)).mkString) val void = char2void("Hello! !") println(void) val text = void2char(void) println(text) }
Let's sort this code in parts.
')
val v is an array containing most (with the exception of U + 180E) invisible Unicode characters.
def str2oct is a function that turns an array of bytes (for example,
“hello”. getBytes () ) into its octal display, for example,
150 145 154 154 157 (spaces are inserted for clarity).
def oct2str is a function that performs the inverse transform. We break the string into pieces of 3 characters, turn the triplets into the corresponding symbol and assemble the string back.
def voidEnc - replaces the octal number (for example, 7) with the corresponding character from our array of invisible characters.
def voidDec - returns the number corresponding to the invisible character.
def char2void - first we turn the string into octal triplets (
str2oct ), and then replace each number with an invisible character (
voidEnc )
def void2char - first decrypt the octal triplets, and then turn them into a string.
PS I do not recommend to publish "War and Peace" or any other long encrypted messages in the comments, because it can break the browser for many users.