md5 code harmony

A selection of programming language textbooks ... 
 RosetteCode offers source codes overs 40 programming languages.


how to a slightly shorter quick sort?

i found a simple article about quicksort in python and ruby. So, it was bestly compressed in whole part.


in python:
q=lambda s:s if len(s)<2 else q([x for x in s[1:]if x<s[0]])+[s[0]]+q([x for x in s[1:]if x>=s[0]])
(source: this link)

in ruby:
def q(s);t=s.dup;t.size<=1 ? t :(p=t[i=t.size/2];t.delete_at(i);x,y=[],[];t.each{|e|e<p ? x<<e : y<<e};n=q(x);m=q(y);n+[p]+m)end

(source: this link)

An animation of the quicksort algorithm sortin...Image via Wikipedia

a few business card




bloooog word clouds

KSoap in Blackberry

in blackberry, you can use ksoap api to connect .net web service. :)


public boolean LoginProcess(String userStr, String passStr) {
        boolean status = false;
        // new Thread(new Runnable() {
        // public void run() {
        String serviceUrl = getHTTPAdd();
        String serviceNamespace = "http://tempuri.org/";
        String soapAction = "http://tempuri.org/SecureLogin";
        SoapObject  rpc = new SoapObject(serviceNamespace, "SecureLogin");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.bodyOut  = rpc;
        envelope.dotNet  = true;
        envelope.encodingStyle = SoapSerializationEnvelope.XSD;
        rpc.addProperty("customerid", userStr);
        rpc.addProperty("password", passStr);
        String payHelpString = ";interface=wifi";
        HttpTransport ht = new HttpTransport(serviceUrl + payHelpString);
        ht.debug = true;
        String result;
        try {
            ht.call(soapAction, envelope);
            result = (envelope.getResponse()).toString();
            resultOfWebCall = result;
            userParseData = toStringStr(parseSXml(result));
            checkVal = parseSXml(result)[1];
            userStrVal = parseSXml(result)[2]; // :)
            userStrAccVall = userStr;
            System.out.println("|||||||||||| |||||||||||| checkVal: " + checkVal);
            if (checkVal.compareTo("OK") == 0) {
                status = true;
            }
        } catch (Exception ex) {
            result = ex.toString();
            System.out.println(">>> inline error: "+result);
        }
        return status;
    }

Sms Encryption - Decryption

A few years ago, i tried to do a mobile sms cryption applicatio with bouncycastle.


public byte[] smsEncodedMessage ( byte[] smsEncContent , byte[] smsEncPKey ) throws Exception {
        try {
            cipherEngine = new PaddedBufferedBlockCipher ( createEngine () );
            cipherEngine.init ( true , new KeyParameter ( smsEncPKey ) );
            cipherText = new byte[ cipherEngine.getOutputSize ( smsEncContent.length ) ];
            cipherTextLength = cipherEngine.processBytes ( smsEncContent , 0 , smsEncContent.length , cipherText , 0 );
            cipherEngine.doFinal ( cipherText , cipherTextLength );
            out = new ByteArrayOutputStream ();
            dout = new DataOutputStream ( out );
            dout.writeShort ( cipherText.length );
            out.write ( cipherText );
        } catch ( Exception e ) {
            main.errorMessage ( "<ERROR BLOCK - inLine < 1 > >: " + e.getMessage () );
        }

        return out.toByteArray ();
    }

    public String smsDecodedMessage ( byte smsDecContent[] , byte[] smsDecPKey ) throws Exception {
        try {
            in = new ByteArrayInputStream ( smsDecContent );
            din = new DataInputStream ( in );
            cipherTextLength = din.readShort ();
            cipherText = new byte[ cipherTextLength ];
            in.read ( cipherText , 0 , cipherTextLength );
            cipherEngine = new PaddedBufferedBlockCipher ( createEngine () );
            cipherEngine.init ( false , new KeyParameter ( smsDecPKey ) );
            plainText = new byte[ cipherEngine.getOutputSize ( cipherTextLength ) ];
            size = cipherEngine.processBytes ( cipherText , 0 , cipherTextLength , plainText , 0 );
            cipherEngine.doFinal ( plainText , size );
            resultText = ( new String ( plainText ) ).trim ();
        } catch ( Exception e ) {
            main.errorMessage ( "<ERROR BLOCK - inLine < 2 > >: " + e.getMessage () );
        }
        return resultText;
    }