package org.maachang.util;

class MCode {
    public static final void main( String[] args ) throws Exception {
        Encryption e = new Encryption() ;
        byte[] key = Encryption.convertStringByCode32Key( args[ 1 ] ) ;
        byte[] bin = FileUtil.getFile( args[ 2 ] ) ;
        if( "0".equals( args[ 0 ] ) ) {
            e.encryption( key,bin,0,bin.length ) ;
        }
        else if( "1".equals( args[ 0 ] ) ) {
            boolean flg = false ;
            int len = 0x000000ff ;
            for( int i = 0 ; i < len ; i ++ ) {
                byte[] b = new byte[ bin.length ] ;
                System.arraycopy( bin,0,b,0,bin.length ) ;
                try {
                    e.analysis( key,i,b,0,b.length ) ;
                    flg = true ;
                } catch( Exception ee ) {
                    flg = false ;
                }
                if( flg == true ) {
                    bin = b ;
                    break ;
                }
            }
        }
        FileUtil.setFile( args[ 2 ] + args[ 0 ],bin ) ;
    }
}