Go to Top

Friday 29 July 2011

Utilities - 1 : How to send encrypted messages to your closest friends ?

Hi folks! Today I am going to give such a program that will enable you to send encrypted messages to your best friends and it will also help you to decrypt those and get the messages from your friends.

Just paste the java program given below into your Blue-J or any other environment and follow the steps :


import java.lang.*;
import java.io.*;
class encrypt_1
{
 static void main()throws IOException
 {
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     int a,opt=9;
     while(opt!=0)
     {
        System.out.println("Press 1 for encryption");
        System.out.println("Press 2 for decryption");
        System.out.print("\nEnter your choice : ");
        a=Integer.parseInt(br.readLine());
        System.out.print("\n");
        switch(a)
        {
            case 1:
            encrypt();
            break;
            case 2:
            decrypt();
            break;
            default:
            System.out.println("Invalid option");
        }
        System.out.println("\nPress 1 to restart");
        System.out.println("Press 0 to terminate the program");
        System.out.print("\nEnter your choice : ");
        opt=Integer.parseInt(br.readLine());
        System.out.print("\n");
    }
    System.out.println("Thank you for using this short program");
}
    static void encrypt()throws IOException
    {
        BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
        String a;
        char k;
        int i;
        System.out.print("Enter the string (Encryption process) : ");
        a=br1.readLine();
        System.out.print("\nYour encrypted data is : ");
        for(i=0;i<=a.length()-1;i++)
        {
            k=a.charAt(i);
            System.out.print((char)(k^129));
        }
        System.out.println("\n");
        System.out.println("Thank you for using this short program");
    }
     static void decrypt()throws IOException
    {
        BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));
        String a;
        char k;
        int i;
        System.out.print("Enter the encrypted data : ");
        a=br2.readLine();
        System.out.print("\nYour decrypted data is : ");
        for(i=0;i<=a.length()-1;i++)
        {
            k=a.charAt(i);
            System.out.print((char)((int)k^129));
        }
        System.out.print("\n");
}
}


Give the program to your friends whom you want to recieve your messages only , and keep one copy for yourself too !

Compile the above program and run it. Follow the directions and turn your message, for example : "Let's meet at 5:30 in the park" into "Íäõ¦ò¡ìääõ¡àõ¡´»²±¡èï¡õéä¡ñàóê" . Copy it from the display and send it to your friend. When he/she decrypts it (by copying the code and pasting it into the program) , he/she will get the message "Let's meet at 5:30 in the park" and believe me, this will surely work and protect your message from being understood by your rivals. And please please comment on my articles to prove that you are out there somewhere reading my article. By the way, this encryption is called "Simple XOR Encryption" , and its quite simple and effective too !

To print and find the sum of a given series

Question 16 : Write a program in Java to print and find the sum of the given series-

S = 1+11+111+1111+11111+......+(11111...n)



Java Program :



class series_3
{
 int n,sum=1;
 series_3(int a)
 {
     n=a;
     cal();
    }
    void cal()
    {
        int s=1;
        System.out.print("The series : 1+");
        for(int i=2;i<=n;i++)
        {
            s=(s*10)+1;
            sum=sum+s;
            if(i==n)
            {
                System.out.print(s);
                break;
            }
            System.out.print(s+"+");
        }
        System.out.print("\nSum of the series : "+sum);
    }
}

Tips & Tricks - How to make a shutdown timer in Windows XP

A shutdown timer is very helpful when you want your computer to shut down in your absence and without your little brothers and sisters interfering in this matter. Just follow the steps given below to make a useful shutdown timer in no time : 

1) Firstly, right click on any vacant space in your desktop or any folder.

2) Then, from the drop down list point to New.

3) Then, from the menu select Shortcut.

4) You'll see a new shortcut created in the folder/desktop.

5) Just then a dialog box will open. In the box enter the following : 
    
     "shutdown -s -t 3600" (Without the "" (Inverted commas))

     Note : The number here represents the number of seconds. This means that on double clicking this shortcut, the computer will automatically shutdown after 1 hour. So don't forget to convert the hours and minutes into seconds before writing them.

Oh! Was that a mistake you or someone else did to double click the above shortcut. And you can't close and abort the automatic shutdown. Not to worry. Blog to the rescue. As an antivenin neutralizes toxins, you'll need another shortcut to combat this automatic shutdown. Just follow the simple steps given below : 

1) Firstly, right click on any vacant space in your desktop or any folder.

2) Then, from the drop down list point to New.

3) Then, from the menu select Shortcut.

4) You'll see a new shortcut created in the folder/desktop.

5) Just then a dialog box will open. In the box enter the following : 
    
     "shutdown -a" (Without the "" (Inverted commas))

As you can see (if you aren't blind), all the step are the same except what you have to enter in the box. Double clicking this shortcut will result in the termination of the automatic shutdown initiated previously by you. Then give a good looking icon picture to the shortcut so as to boast about it in your friend circle.

Note : And please don't just close this site after you've had your task done. Please comment. Any type of comment will be surely appreciated.

Saturday 2 July 2011

To print and find the sum of a given series

Question 15 : Write a program in Java to print and find the sum of the given series-


S = 1+2+4+7+11+......+n


Java Program : 



public class series_1
{
 public static void main(int n)
 {
     int i,d;
     int s=1;
     d=0;
     System.out.println("The generated numbers are : ");
     for(i=0;i<=n-1;i++)
     {
         s=s+i;
         d=d+s;
         System.out.println(s);
        }
    System.out.println("\nThe sum of the generated numbers = "+d);
}
}

To print a given pattern

Question 14 : Write a program in Java to print the following pattern :

1
12
123
1234
12345

Java Program : 

public class pattern_3
{
 public static void main()
 {
     int i,j;
     for(i=1;i<=5;i++)
     {
         for(j=1;j<=i;j++)
         {
             System.out.print(j);
            }
            System.out.print("\n");
        }
    }
}

ShareThis