public static byte [ ] fold ( byte [ ] bytes , int size ) { byte [ ] r = new byte [ size ] ; for ( int i = Math . max ( bytes . length , size ) - 1 ; i >= 0 ; i -- ) { r [ i % r . length ] ^= bytes [ i % bytes . length ] ; } return r ; }
Given a byte array that contains arbitrary number of bytes digests or expands those bits into the specified number of bytes without loss of entropy .