Saturday, May 24, 2014

For all people with power problems using Ubuntu 14.04 try downgrading your Linux kernel to Long term supported version
either 3.10 or 3.12
PS: it worked for me and will work for most of the people as 3.12 kernel is stable

 firstly download the 3 deb files which suit ur system architecture
if for 32 bit =>i386
for 64 bit =>amd64
go for files which have generic written
http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.12.20-trusty/


Go to the downloaded folder

then run this

sudo dpkg -i linux-headers-3.12.20* linux-image-3.12.20* .deb
And then remove the 3.13 default kernel

sudo apt-get remove linux-headers-3.13.0* linux-image-3.13.*
And ur through

If possible change the URI for Kernel updates in Software Center.

Install power monitoring tools like Powertop.

sudo apt-get install powertop

In powertop go to turnables tab and toggle every row from bad to good

also install pm-utils

sudo apt-get install pm-utils

sudo pm-powersave true

this puts ur pc on power save mode

Tuesday, April 1, 2014

TO STUDY HASH FUNCTIONS IN JAVA


package hashfn;
import java.util.*;
import java.security.MessageDigest;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)throws Exception {
        Scanner sc=new Scanner(System.in);
        String s;
            System.out.println("Enter the string");
            s=sc.nextLine();
            MessageDigest md=MessageDigest.getInstance("MD5");
            byte[] databytes=new byte[1024];
            databytes=s.getBytes();
            md.update(databytes);
            byte[] mdbytes=md.digest();
            StringBuffer hexString = new StringBuffer();
for (int i=0;i<mdbytes.length;i++) {
  String hex=Integer.toHexString(0xff & mdbytes[i]);
  if(hex.length()==1) hexString.append('0');
  hexString.append(hex);
}
            System.out.println(hexString);
    }

}

TO IMPLEMENT GENERAL CAESAR CIPHER IN JAVA

import java.util.*;

public class gencaesar
{
public static void main(String[] args) throws Exception
{
String input,output;
String a,b;
Scanner sc= new Scanner(System.in);

System.out.println("Enter the message");
input=sc.nextLine();
char array[]=input.toCharArray();
int key,i=0;
System.out.println("Enter the key");
key=sc.nextInt();
//adding the key
for(i=0;i<array.length;i++)
{
array[i]+=key;
if(array[i]>=90)
{
array[i]-=26;
}
if(array[i]>=129)
{
array[i]-=64;
}

}
//printing output
System.out.println("General Caesar Cipher: \n");
for(i=0;i<array.length;i++)
{
System.out.print(array[i]);

}
System.out.println();

//decyption
for(i=0;i<array.length;i++)
{
array[i]-=key;
if(array[i]>=129)
{
array[i]-=64;
}
if(array[i]>='Z' && array[i]<='a')
{
array[i]-=26;
}

}

//printing output
System.out.println("DECRYPTED PLAIN: \n");
for(i=0;i<array.length;i++)
{
//System.out.print(array[i]);

}
System.out.println(input);

//PROGRAM IS CODED BY 6483
}
}
/*
bash-3.00$ javac gencaesar.java
Enter the message
bash-3.00$ javac gencaesar.java
bash-3.00$ java gencaesar
Enter the message
xyz
Enter the key
5
General Caesar Cipher:

cde
DECRYPTED PLAIN:

xyz

*/

TO IMPLEMENT COVERT CHANNEL USING JAVA

package covert;
/*
THREAD1:
TAKE I/P FRM USR
WHEN USR ENTERS 1 A FILE SHUD BE CREATED
WHEN HE ENTERS 0 IT SHOULD BE DESTROYED

THREAD 2 :
KEEP CHECKING FOR FILE IF EXISTS DISPLAY 1
IF NOT DISPLAY 0


*/
import java.io.File;

import java.util.*;

/**
 *
 * @author 6483
 */
public class Covert {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
 
        A a=new A();
    a.start();
    B b=new B();
    b.start();
           
    }
}

class A extends Thread
{
        public static String ar="";
   public static Scanner sc=new Scanner(System.in);
boolean flag=true;
    File file;
    public void run ()
    {
       
        try
        {
           
        while(flag)
        {
           
            System.out.println("Enter BIT : ");              
            ar=sc.nextLine();
       
      if(ar.equals("1"))
      {
          file=new File("/home/student/2011/6483/Desktop/dummy.txt");
          file.createNewFile();
          ar="";
      }
      else if(ar.equals("0"))
      {
          file.delete();
          ar="";
      }
      else if(ar.equalsIgnoreCase("exit"))
      {
         
          System.exit(0);
      }
      sleep(5000);
     
      }
        }catch(Exception e){e.printStackTrace();}
        }
}

class B extends Thread
{
    void check(File file)
    {
     
     
       if(file.exists())
            {
            System.out.println("THE INCOMING BIT IS : 1");              
            }
            else
        {
            System.out.println("THE INCOMING BIT IS : 0");                  
        }
   
    }
    public void run ()
    {
        boolean flag=true;
        try
        {
           
        while(flag)
        {
           
       
            File file=new File("/home/student/2011/6483/Desktop/dummy.txt");
     
            check(file);
            sleep(5000);
        }
        }catch(Exception e){e.printStackTrace();}
        }
}