Saturday, April 28, 2012

Just go for it!!: Primitive chat program using XMLRPC

Just go for it!!: Primitive chat program using XMLRPC:  Primitive chat program using XMLRPC! try this!! This is a program in java to illustrate XMLRPC ...so copy this code..compile and run it...

Primitive chat program using XMLRPC

 Primitive chat program using XMLRPC! try this!!

This is a program in java to illustrate XMLRPC ...so copy this code..compile and run it!its fun!!

 

Code for PrimitiveChat.java :

import javax.swing.*;

public class PrimitiveChat {

public String printText(String str) {
    System.out.println( "Received: "+str);
    return "ok";
    }

 public static void main (String [] args) {
  String input;
  PrimitiveChat pc = new PrimitiveChat();

  do {
    input = JOptionPane.showInputDialog("Enter your message");
    if( input != null ) {
        pc.printText(input); // a local procedure call.
        }
    } while ( input != null );
  System.exit(0);
  }
}

OUTPUT:


Just go for it!!: RSA code in Java

Just go for it!!: RSA code in Java:       To encrypt and decrypt a string using RSA algorithm The following code helps the user to provide a string for encryption and decry...

RSA code in Java

      To encrypt and decrypt a string using RSA algorithm

The following code helps the user to provide a string for encryption and decryption using RSA algorithm with the help of Big Integer in java.

Source code for RSA.java:

import java.math.BigInteger; 
import java.util.Random;
import java.io.*;
 
 
public class RSA { 
     
    private BigInteger p; 
    private BigInteger q; 
    private BigInteger N; 
    private BigInteger phi; 
    private BigInteger e; 
    private BigInteger d; 
    private int bitlength = 1024; 
    private int blocksize = 256; //blocksize in byte 
     
    private Random r; 
     public RSA() { 
        r = new Random(); 
        p = BigInteger.probablePrime(bitlength, r); 
        q = BigInteger.probablePrime(bitlength, r); 
          N = p.multiply(q); 
           
        phi = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE)); 
          e = BigInteger.probablePrime(bitlength/2, r); 
         
        while (phi.gcd(e).compareTo(BigInteger.ONE) > 0 && e.compareTo(phi) < 0 ) { 
            e.add(BigInteger.ONE); 
        } 
 d = e.modInverse(phi);  
    } 
     
    public RSA(BigInteger e, BigInteger d, BigInteger N) { 
        this.e = e; 
        this.d = d; 
        this.N = N; 
    } 
     
    public static void main (String[] args) throws IOException

        RSA rsa = new RSA(); 
           DataInputStream in=new DataInputStream(System.in);  
        String teststring ;
         System.out.println("Enter the plain text:");
        teststring=in.readLine();
        System.out.println("Encrypting String: " + teststring); 
        System.out.println("String in Bytes: " + bytesToString(teststring.getBytes())); 
 
        // encrypt 
        byte[] encrypted = rsa.encrypt(teststring.getBytes());                   
        System.out.println("Encrypted String in Bytes: " + bytesToString(encrypted)); 
         
        // decrypt 
        byte[] decrypted = rsa.decrypt(encrypted);       
        System.out.println("Decrypted String in Bytes: " +  bytesToString(decrypted)); 
         
        System.out.println("Decrypted String: " + new String(decrypted)); 
         
    } 
 
   private static String bytesToString(byte[] encrypted) { 
        String test = ""; 
        for (byte b : encrypted) { 
            test += Byte.toString(b); 
        } 
        return test; 
    } 
     
     public byte[] encrypt(byte[] message) {      
        return (new BigInteger(message)).modPow(e, N).toByteArray(); 
    } 
       
    public byte[] decrypt(byte[] message) { 
        return (new BigInteger(message)).modPow(d, N).toByteArray(); 
    } 
     
}

OUTPUT:

Tuesday, April 3, 2012

Just go for it!!: Remove hyperlinks from a word file at a time!

Just go for it!!: Remove hyperlinks from a word file at a time!:                                                           TRY THIS!! Sometimes what we hate to do the most becomes a reason for the c...

Remove hyperlinks from a word file at a time!


                                                          TRY THIS!!
Sometimes what we hate to do the most becomes a reason for the change in our life. Like any other ordinary day…I thought to continue with the same positivity in my life…but however hard you try, you can never avoid the inevitable. I abhor presenting the copy-paste material for any of my write-ups but the need of the hour did not care of my abhorrence and I had to do it...anyways the positive aspect of this was that I learnt how to remove the hyperlinks at a time from the whole word document! We all refer Wikipedia frequently but if we want to copy-paste the same material..we get a document filled with many hyperlinks. So there is a simple way to remove all these. Follow this:

-First open the document where you want to edit the hyperlinks and press alt+F11 or open the Visual Basic Editor.

-Then click on Insert and then Module. A window will appear before you.


-Then copy-paste the following code on that window and then close the window.
Sub RemoveHyperlinks()
Dim oField As Field
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldHyperlink Then
oField.Unlink
End If
Next
Set oField = Nothing
End Sub


-Click on the This Document on the Project window on the left of the Visual Editor.
-Close the Visual Editor and go to the View menu in the MS Word 2007.
-Click on Macros and then select RemoveHyperlinks and click on Run.
Your hyperlinks are removed!!Try it!!
Note: This is for Microsoft word 2007