public static void leetConvert ( LeetLevel level , SecureCharArray message ) throws Exception { // pre-allocate an array that is 4 times the size of the message. I don't // see anything in the leet-table that is larger than 3 characters, but I'm // using 4-characters to calcualte the size just in case. This is to avoid // a bunch of array resizes. SecureCharArray ret = new SecureCharArray ( message . size ( ) * 4 ) ; char [ ] messageBytes = message . getData ( ) ; // Reference to message's data char [ ] retBytes = ret . getData ( ) ; // Reference to ret's data int currentRetByte = 0 ; // Index of current ret byte if ( level . compareTo ( LeetLevel . LEVEL1 ) >= 0 && level . compareTo ( LeetLevel . LEVEL9 ) <= 0 ) { for ( char messageByte : messageBytes ) { char b = Character . toLowerCase ( messageByte ) ; if ( b >= ' ' && b <= ' ' ) { for ( int j = 0 ; j < LEVELS [ level . getLevel ( ) - 1 ] [ b - ' ' ] . length ( ) ; j ++ ) retBytes [ currentRetByte ++ ] = LEVELS [ level . getLevel ( ) - 1 ] [ - ' ' ] . charAt ( j ) ; } else { retBytes [ currentRetByte ++ ] = b ; } } } // Resize the array to the length that we actually filled it, then replace // the original message and erase the buffer we built up. ret . resize ( currentRetByte , true ) ; message . replace ( ret ) ; ret . erase ( ) ; }
Converts a SecureCharArray into a new SecureCharArray with any applicable characters converted to leet - speak .