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();}
        }
}

Thursday, January 9, 2014

TO IMPLEMENT BINARY SEARCH ALGORITHM IN C

int BinarySearch(int *array, int number_of_elements, int key)
{
        int low = 0, high = number_of_elements-1, mid;
        while(low <= high)
        {
                mid = (low + high)/2;
                if(array[mid] < key)
{
                       low = mid + 1;
               }
               else if(array[mid] == key)
               {
                       return mid;
                }
                else if(array[mid] > key)
                {
high = mid-1;
               }
       }
       return -1;
}
int main()
{
int number_of_elements;
        scanf("%d",&number_of_elements);
        int array[number_of_elements];
        int iter;
        for(iter = 1;iter < number_of_elements;iter++)
        {
if(array[iter] < array[iter - 1])
                {
                        printf("Given input is
not sorted\n");
return 0;
                }
        }
        int key;
        scanf("%d",&key);
        /* Calling this functions searches for the key and returns its index. It returns -1          if key is not found.*/
        int index;
index = BinarySearch(array,number_of_elements,key);
        if(index==-1)
        {
                printf("Element not found\n");
      }
       else
       {
               printf("Element is at index %d\n",index);
        }
return 0;
}

TO IMPLEMENT PASCALS TRIANGLE USING C

#include<stdio.h>
long fact(int);
int main(){
    int line,i,j;
    printf("Enter the no. of lines: ");
    scanf("%d",&line);
    for(i=0;i<line;i++){
         for(j=0;j<line-i-1;j++)
             printf(" ");
for(j=0;j<=i;j++)
             printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
         printf("\n");
}
    return 0;
}
long fact(int num){
    long f=1;
    int i=1;
    while(i<=num){
f=f*i;
i++;
  }
  return f;
}

Output:
Enter the no. of lines:3
1
1 1
1 2 1

Wednesday, December 4, 2013

TO FIND FACTORIAL OF A NUMBER IN C

//TO FIND FACTORIAL OF A NUMBER IN C
# include<stdio.h>
int main()
{
int fac,n;
int factorial(int);
printf("Enter any number:");
scanf("%d",&n);
fac=factorial(n);
printf("Factorial=%d",fac);
return 0;
}

int factorial(int x)
{
int f;
if(x==1)
return 1;
else
f=x*factorial(x-1);
return f;
}

Thursday, November 7, 2013

PROGRAM TO IMPLEMENT MATRIX MULTIPLICATION

;program to implement matrix multiplication
MOV SI,1000
       MOV BP,1020
       MOV DI,1050
L2:  MOV CX,00
L1:  MOV AL,[SI]
       MOV BL,[BP]
       MUL BL
       ADD CX,AX
       ADD BP,03
       INC SI
       CMP BP,1029
       JB L1
       SUB SI,03
       SUB BP,08
       ADD DI,02
       CMP BP,1023
       JB L2
      ADD SI,03
      SUB BP,03
      CMP DI,1051
       JB L2
HLT

Thursday, October 31, 2013

FACADE DESIGN PATTERN IN JAVA

/*
FACADE DESIGN PATTERN IN JAVA
*/
class Client
{
public static void main(String args[]){

OrderFacade orderFacade = new OrderFacade();

orderFacade.placeOrder("OR123456");

System.out.println("Order processing completed");
}

}

 class OrderFacade {
private Payment pymt = new Payment();
private Inventory inventry = new Inventory();

public void placeOrder(String orderId) {

String step1 = inventry.checkInventory(orderId);

String step2 = pymt.deductPayment(orderId);

System.out.println("Following steps completed:" + step1+ " & " + step2);

}

}
 class Payment {
public String deductPayment(String orderID)
{
System.out.println("TOKEN "+orderID+" recieved\nProcessing payment...\n");
return "Payment deducted successfully";

}
}

class Inventory {
public String checkInventory(String OrderId)
{
System.out.println("TOKEN "+OrderId+" recieved\nProcessing Inventory...\n");
return "Inventory checked";
}
}






/*
OUTPUT:
TOKEN OR123456 recieved
Processing Inventory...

TOKEN OR123456 recieved
Processing payment...

Following steps completed:Inventory checked & Payment deducted successfully
Order processing completed
*/

OBSERVER DESIGN PATTERN IN JAVA

/*
OBSERVER DESIGN PATTERN IN JAVA
*/
import java.util.*;
class subject
{

person p1,p2;

subject()
{
p1=new person();
p2=new person();
}
void notify(boolean a)
{
if(a)
{
p2.state=p1.state="changed";

System.out.println(p1);
System.out.println(p2);
}
else
{
System.out.println(p1);
System.out.println(p2);
}

}
public static void main(String[] args)
{
boolean executed=false;
String choice;
subject s=new subject();
Scanner sc=new Scanner(System.in);
while(!executed)
{
System.out.println("SHOULD WE CHANGE STATE ?  Y/N");
choice=sc.nextLine();
if(choice.equals("Y") || choice.equals("y"))
{
s.notify(true);
executed=true;
}
else
s.notify(false);
}
}
}
class person
{//person is the observer;
String state;
person()
{
state="unchanged";
}
public String toString()
{
return state;
}

}

/*
OUTPUT
SHOULD WE CHANGE STATE ?  Y/N
n
unchanged
unchanged
SHOULD WE CHANGE STATE ?  Y/N
n
unchanged
unchanged
SHOULD WE CHANGE STATE ?  Y/N
n
unchanged
unchanged
SHOULD WE CHANGE STATE ?  Y/N
n
unchanged
unchanged
SHOULD WE CHANGE STATE ?  Y/N
y
changed
changed
*/

Wednesday, October 30, 2013

HOW TO RUN 8086 ON WINDOWS

TOPIC : HOW TO RUN 8086 ON WINDOWS

REQUIREMENTS : TASM ,Debugger to assemble link and create object and exe files for your program as well as to debug it. 
here is download link: 
http://dl.dropboxusercontent.com/u/25051673/tasm5.zip
http://dl.dropboxusercontent.com/u/25051673/afdebug.zip

STEPS:
1.Extract these files in this folder
and now open the command prompt and change the directory to this folder.


2.copy the program and paste it in the notepad/Editplus.
save it in the bin folder with extension .asm


3.Now type tasm followed by the program name with .asm extension

tasm filename.asm

press enter this will show your errors. correct all these errors then proceed to the next step.


4.now type tlink followed by the program name with extension .obj


tlink filename.obj

press enter


5.now type the td followed by the program name with extension .exe


td filename.exe

6.then your program appears in different screen.
press F7 key until you reach the starting address of the program.  


To open the dump window press ctrl+g


6.then a dialog box will appear. enter the starting address of the program which is typed in the program. for ex 2000h.
then press enter. and close the dialog box.


8.now continue pressing F7. when the program terminates it shows a dialog box. and the result will be seemed in the dump window

VIDEO LINK: http://www.youtube.com/watch?v=oUmCi2He84o

16 BIT ADDITION WITH CARRY


;16 BIT ADDITION WITH CARRY

.model small
.data
num1 dw 0FFFFH
num2 dw 0DDDDH
sum dw ?
carry db ?
.code
START:
MOV AX,@data
MOV DS,AX
MOV AX,0000H
MOV AX,num1
MOV BX,num2
ADD AX,BX
MOV DL,00H
ADC DL,00H
MOV sum,AX
MOV carry,DL
MOV AX,4C00H
INT 21H
END START

;da:0000 CD 21 FF FF(num1) DD DD(num2) DC DD(sum)
;01(carry)

8-bit addition register adddressing mode with carry


;Aim - 8-bit addition register adddressing mode with carry

.8086
.model small
.data
num1 db 05h
num2 db 0eh
sum db ?
carry db ?
.code

start:
mov ax , @data
mov ds , ax
mov ax , 0000h
mov al, num1
mov bl , num2
add al , bl
mov dl , 00
adc dl , 00
mov carry , dl
mov ax , 4c00h
int 21h
end start

;Result
;DS:0001 05(NUM1)
;DS:0002 0E(NUM2)
;0005 01
;SUM 23
;CARRY 00

Aim - 8-bit addition register adddressing mode without carry

;Aim - 8-bit addition register adddressing mode without carry

.8086
.model small
.code

start:
mov ax , 1200h
mov ds , ax
mov ax , 0000h
mov al , 05h
mov bl , 04h
add al , bl
mov ax , 4c00h
int 21h
end start
; Result
;0000+0012=0012

16-bit Subtraction register adddressing mode with carry

; Aim - 16-bit Subtraction register adddressing mode with carry

 .8086
 .model small
 .data
 num1 dw 0aaaah      ;Load aaaah to Num1
 num2 db 0ffffh                       ;Load ffffh to Num2
 ans dw ?
 carry db ?
 .code
 Start:
 mov ax , @data                       ;Copying the address of the data to AX.
 mov ds , ax
 mov ax , 0000h
 mov ax , num1                        ;Copies Num1 to AX.
 mov bx , num2
 sub cx , dx                          ;Subtracts DX from CX.

 mov ah , 00h
 mov ans,cx

 lahf                                 ;Loads all the flags to AH.
 AND ah,01h

 mov borrow , ah
 mov ax , 4c00h
 int 21h
 end start

 ;Result
 ;DS:0000 0AAAA(NUM1)
 ;DS:0000 0FFFF(NUM2)
 ;ds:00008 0AAAB(ans)
 ;ds:00008 01 (borrow)

8-bit Subtraction register adddressing mode with borrow

;8-bit Subtraction register adddressing mode with borrow

 .8086
 .model small
 .data
 num1 db 0ah
 num2 db 0Fh
 ans db ?
 carry db ?
 .code
 Start:
 mov ax , @data                 ; Copying the address of the data to AX.
 mov ds , ax
 mov ax , 0000h
 mov al , num1                  ; Copies Num1 to AL.
 mov bl , num2
 sub al , bl                    ;Subtracts BL fron AL.

 mov ah , 00h
 mov ans,al

 lahf                           ;Loads all the flags to AH.
 AND ah,01h

 mov carry , ah
 mov ax , 4c00h
 int 21h
 end start

 ;Result
 ;DS:0000 0A(NUM1)
 ;DS:0000 0F(NUM2)
 ;ds:00008 0FA(ans)
 ;ds:00008 01 (ans)

To move a block of 10 databytes from source to destination

; To move a block of 10 databytes from source to destination
.8086
.model small
.data
src1 db 10h, 20h ,30h, 40h, 50h, 60h, 70h, 80h, 90h, 0ah
Des1 db 0ah dup(0)
.code
START:
mov ax , @data
mov ds , ax
mov es , ax
lea si , src1
lea di , des1
mov cx , 000ah
rep movsb
mov ax,4c00h
int 21h
end start
;output
(000a)

To calculate the power of a number

;Aim:- To calculate the power

.8086
.model small
.data
msg1 db 13,10, "enter the number-:$"
msg2 db 13,10, "enter the power-:$"
msg3 db 13,10, "the answer-:$"
.code
START:
MOV AX,@data
MOV DS,AX
LEA DX,msg1 ;loads the offset of MSG1 in dx
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
MOV BL,AL

LEA DX,msg2 ;loads the offset of MSG2 in dx
MOV AH,09H ;Display s string
INT 21H ;Whose offset is in dx
MOV AH,01H
INT 21H
MOV CL,AL
SUB CL,30H ;Subtract bl from ASCII 30H
SUB BL,30H
MOV AH,00H
MOV AL,01H ;Take input from keyboard


BACK:MUL BL
DEC CL
JNZ BACK
MOV BL,AL

LEA DX,msg3 ;loads the offset of MSG3 in dx
MOV AH,09H
INT 21H
MOV DL,BL
ADD DL,30H
MOV AH,02H
INT 21H
MOV AX,4C00H
INT 21H
END START

;Output
;Enter the number:3
;Enter the power:2
;the answer is-:9

to find no of ones and zeroz

;title:to find no of ones and zeroz
.model small
.data
a db 05H
num db ? ;stores input no
.code
start:
mov ax,@data
mov ds,ax
mov dx,0000H
mov cx,0000H
mov bx,08H ;storing 8 in bx counter
mov al,num
back:ror ax,1 ;rotate al by 1
jnc abc ;jump if carry
inc dx ;increment dx
abc:inc cx
dec bx
jnz back ;jump if zero
mov ax,4c00h
int 21h
end start

;output
;input nos 0000 0101
no of 0s:Cx:6
no of 1s:Dx:2

16-bit multiplication direct addressing mode

;16-bit multiplication direct addressing mode

.model small
.data
num1 dw 1234h
num2 dw 0100h
product dw ?
.code
start:
mov ax,@data
mov ds,ax
mov ax,num1
mov bx,num2
mul bx
;multiplies data in bx with ax
;stores msb in dx and lsb in ax
mov product,ax
mov ax,4c00h
int 21h
end start

;Output
;AX=1234
;BX=0100
;AFTER MULTILICATION
;AX=3400