Thursday, September 11, 2014

Display Image from Mysql database to JSP page in table

main jsp file where to display image
 <th width="207" scope="col"><table width="200" height="208" border="1">
      <tr>
          <th scope="col">
       <img src="LoadImage.jsp" width=200 height=200></th>
      </tr>

LoadImage.jsp:
<%--
    Document   : LoadImage.jsp
    Created on : Sep 11, 2014, 6:35:41 PM
    Author     : JK
--%>

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="javax.servlet.http.HttpSession"%>
<%@ page language="java"%>
<%@ page session="true"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
         
            String ATMV=(String)session.getAttribute("ATMV");
         
         
        try
        {
   
            Class.forName("com.mysql.jdbc.Driver");
   
            java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/jk","root","JK786@$");
   
            Statement st=con.createStatement();
         
            PreparedStatement pre1 = con.prepareStatement("select ImageWithSignature from atm where ATMNO='"+ATMV+"'");
            ResultSet rs1=pre1.executeQuery();
            while(rs1.next())

            {
                byte[] bytearray1 = new byte[4096];
         
                int size1=0;
       
                InputStream sImage1;
         
                sImage1 = rs1.getBinaryStream(1);
         
                response.reset();
         
                response.setContentType("image/jpeg");
         
                response.addHeader("Content-Disposition","filename=logo.jpg");
         
                while((size1=sImage1.read(bytearray1))!= -1 )
             {
             
                 response.getOutputStream().write(bytearray1,0,size1);
           
             }
         
                response.flushBuffer();
       
                sImage1.close();
         
                rs1.close();
        }

            pre1.close();

            con.close();

         
         
         
        }
        catch(Exception e)
        {
            out.print("Exception"+e);
     
        }
         
         
         
         
        %>
     
    </body>
</html>

Tuesday, September 9, 2014

Encryption and Decryption using AES and MYSQL

<%--
    Document   : test
    Created on : Sep 10, 2014, 11:08:50 AM
    Author     : JK
--%>

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%


           try{
   
           
            Class.forName("com.mysql.jdbc.Driver");
   
            java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/jk","user","password");
     //insert ur db and password
            Statement st=con.createStatement();
           
            String key="nopqrstuvwxyz6789FGHIJKLMNOPQRSTUVWXYZ";
            //you can define your own key
            String Query="insert into pass values(AES_ENCRYPT(1234,'"+key+"'),AES_ENCRYPT(3545,'"+key+"'))";
   
            int o=st.executeUpdate(Query);
           
            if(o==0)
            {
                out.print("Not Executed");
            }
            else
            {
                out.print("  Executed");
           
            }
            String s="";
            String s2="";
            String Query2="select AES_DECRYPT(Verification,'"+key+"'),AES_DECRYPT(PIN,'"+key+"') from pass";//retriving decrypted values
            ResultSet rs=st.executeQuery(Query2);
            while(rs.next())
            {
           
                Blob l=rs.getBlob(1);
               
                byte[] bdata = l.getBytes(1, (int) l.length());
                 s = new String(bdata);
             
                 Blob l2=rs.getBlob(2);
               
                byte[] bdata2 = l2.getBytes(1, (int) l2.length());
                 s2 = new String(bdata2);
               
             
            }
           
             out.print(s);
             out.print(s2);
           
           }
           catch(Exception e)
           {
               out.print("Exception"+e);
         
           }
 
            %>
    </body>
</html>

Monday, September 8, 2014

Overlap Data Transfer (NASM 64 bit)

Overlap Data Transfer:
%macro print 2   
mov rax,1
mov rdi,1                   
mov rsi,%1
mov rdx,%2                                                             
syscall
%endmacro

%macro read 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2                                                             
syscall
%endmacro


SECTION .data
msg : db "The destination data::",0xA
len : equ $-msg

msg1 : db "The Source data::",0xA
len1 : equ $-msg1

msg3 : db "Successfully Moved::",0xA
len3 : equ $-msg3


msg4 : db "Enter the six chracters::",0xA
len4 : equ $-msg4


msg5 : db "Enter the chracter::",0xA
len5 : equ $-msg5

msg6 : db "--------------------------->>"
len6 : equ $-msg6

msg7 : db "Enter the offset (between 1 to 5):"
len7: equ $-msg7

menu : db 0xA,"1)Display source",0xA,"2)Display Destination",0xA,"3)Move data ",0xA,"4)Exit",0xA
lmenu : equ $-menu


SECTION .bss
characters: resq 30
count: resb 1
count1: resb 1
count2: resb 1
choice: resb 2
address: resb 16
number: resb 2


SECTION .text
print msg4,len4
mov byte[count],8
mov rbx,characters
acceptI:
    print msg5,len5
    read rbx,8
    add rbx,8
    dec byte[count]
jnz acceptI

;print msg7,len7
;read number,2

;mov al,[number]

menuprint:
        print menu,lmenu
        read choice,2

       
cmp byte[choice],31h
je DisplaySource
cmp byte[choice],32h
je DisplayDest
cmp byte[choice],33h
je MoveRegister
cmp byte[choice],34h
je Exit

DisplaySource:
print msg1,len1
mov byte[count],8

       
mov rbx,characters


       
displayI:
       
        call convert_Result
        print address,16
        ;mov [address],rdx   
        print msg6,len6       
        print rbx,8
       
        ;call convert_Result       
        add rbx,8
        dec byte[count]
jnz displayI
jmp menuprint

DisplayDest:
print msg,len
mov byte[count],8

mov rbx,characters

displayI2:
        call convert_Result
        print address,16
       
        print msg6,len6   
        print rbx,8
        add rbx,8
        dec byte[count]
jnz displayI2

jmp menuprint

MoveRegister:
       
    mov esi,characters+4
    mov edi,characters+7
    mov byte[count],05

next1:
    mov al,[esi]
    mov [edi],al
    dec esi
    dec edi
    dec byte[count]
jnz next1
   
;jmp DisplayDest

jmp menuprint

Exit:
mov rax,60
mov rdi,00
syscall

convert_Result:
        mov rsi,address
        mov rcx,10h
        loopx:
            rol rbx,04
            mov al,bl
            and al,0Fh
            cmp al,09h
            jbe loopx1
            add al,07h
        loopx1:
            add al,30h
            mov [rsi],al
            inc rsi
        loop loopx
;print address,8
RET       

String Operations with NASM

 String Operations with NASM :


%macro print 2   
mov rax,1
mov rdi,1                   
mov rsi,%1
mov rdx,%2                                                             
syscall
%endmacro

%macro read 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2                                                             
syscall
%endmacro

SECTION .data

msg: db"Enter the string::",0xA
len: equ $-msg

menu: db 0xA,"1.Length of the string",0xA,"2.Reverse of the string",0xA,"3.Check Pallindrome",0xA,"4.Find substring",0xA,"5.Exit",0xA
menulen: equ $-menu
                           
msg1: db"Length of the string is::",0xA
len1: equ $-msg1

msg2: db"Reverse of the string::",0xA
len2: equ $-msg2

msg3: db 0xA,"String is pallindrome.",0xA
len3: equ $-msg3

msg4: db 0xA,"String is not pallindrome.",0xA
len4: equ $-msg4

msg5: db"Original String is::",0xA
len5: equ $-msg5

msg6: db"Enter the second string::",0xA
len6: equ $-msg6

msg7: db"String you entered::",0xA
len7: equ $-msg7

msg8: db"Number of occurances in substring::",0xA
len8: equ $-msg8


SECTION .bss

string: resb 50
string_o: resb 50
rstring: resb 50
lengths: resb 2
choice: resb 2
count: resb 1
count1: resb 1
count2: resb 1
count3: resb 2
count4: resb 1
count5: resb 1
count6: resb 1
count7:resb 1


SECTION .text

global main:
main:

print msg,len
read string,50
dec eax
mov byte[count],al
mov byte[count1],al
mov byte[count2],al
mov byte[count5],al
mov byte[count7],al

cmp eax,09h
jbe l1
add eax,07h
l1:
add eax,30h

mov [lengths],eax


menuprint:
print menu,menulen
read choice,2

cmp byte[choice],31h
je Length
cmp byte[choice],32h
je Reverse
cmp byte[choice],33h
je Pallindrome
cmp byte[choice],34h
je Substring
cmp byte[choice],35h
je Exit

Length:
call calculateLength
jmp menuprint

Reverse:
call calculateReverse
jmp menuprint

Pallindrome:
call calculateReverse
call calculatePallindrome
jmp menuprint

Substring:
call checkOcuurances
jmp menuprint

Exit:
mov rax,60
mov rdi,00
syscall

calculateLength:
            print msg1,len1
            print lengths,2
RET

calculateReverse:
            inc byte[count1]
            mov esi,string
            mov edi,rstring

            loopx:
                inc esi
                dec byte[count]
            jnz loopx
       
            loopx2:
                mov al,[esi]
                mov [edi],al
                dec esi
                inc edi
                dec byte[count1]
            jnz loopx2
            print msg2,len2
            print rstring,50           


RET

calculatePallindrome:
    mov esi,string
    mov edi,rstring
    inc edi
 compare1:   
    mov al,[esi]
    mov bl,[edi]
    cmp al,bl
    jne out
    increament:
            inc esi
            inc edi
            dec byte[count2]
            ;cmp byte[count2],01
    jnz compare1
    print msg3,len3   
    jmp r       
out:
    print msg4,len4               

r:RET
checkOcuurances:
        mov byte[count3],00h
        print msg6,len6
        read string_o,50
        dec eax
        mov byte[count4],al
        mov byte[count6],al
       

        print msg5,len5
        print string,50
        print msg7,len7
        print string_o,50

        mov esi,string
        mov edi,string_o

        compare:
            mov al,[esi]
            mov ah,[edi]
            cmp al,ah
            je incsidi
            jmp incsi
       
        incsidi:
            inc esi
            inc edi
            dec byte[count7]
            dec byte[count6]
        jnz compare
       
            inc byte[count3]
           
            mov edi,string_o
            jmp compare
        incsi:
            inc esi
            ;mov edi,string_o
            dec byte[count7]
        jnz compare
        print msg8,len8
        cmp byte[count3],09h
        jbe loopp
        add byte[count3],07h
        loopp:
        add byte[count3],30h
        print count3,1       


           

RET

Get the factorial of given Number NASM

Get the factorial of given Number NASM(64 bit Linux):
%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2                                                             
syscall
%endmacro
%macro read 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2                                                             
syscall
%endmacro

SECTION .data
msg: db "Enter the number for the factorial::",0xA
len: equ $-msg

msg1: db "The factorial of the given number is::",0xA
len1: equ $-msg1

SECTION .bss
number : resb 10
result : resb 4
temp : resb 4

SECTION .text
global _start:
_start:

print msg,len
read number,4

convert:
        mov bx,00
        mov esi,number
        mov ecx,4
        loop1:
            rol bx,04
            mov al,[esi]
            cmp al,39h
            jbe loop2
            sub al,07h
        loop2:
            sub al,30h
            add bx,ax
            inc esi
           
        loop loop1
;call convert_hex_ascii   
Factorial:
    mov eax,ebx
    mov ecx,eax
   
    fact:
        dec ecx
        mul ecx
        cmp ecx,0001
    jne fact
        mov ebx,eax
        call convert_hex_ascii       
   
mov rax,60
mov rdi,0
syscall               
                   
convert_hex_ascii:
                mov ecx,8
                mov esi,result
                loop3:
                    rol ebx,04
                    mov ax,bx
                    and ax,0Fh
                    cmp ax,09h
                    jbe loop4
                    add ax,07h
                loop4:
                    add ax,30h
                    mov [esi],ax
                    inc esi
                loop loop3
        print msg1,len1
    print result,8

RET                   
   



Calculate perimeter of rectangle and square with NASM

Calculate perimeter of rectangle and square with NASM(64 bit Linux):

%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
;macro for printing
%macro read 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro
;macro for accepting

SECTION .data

msg: db"Enter length of the square::",0xA
len: equ $-msg

msg1: db"Enter base of the rectangle::",0xA
len1: equ $-msg1

msg2: db"Enter the height of the rectangle::",0xA
len2: equ $-msg2

msg3: db"The perimeter of the square is:: ",0xA
len3: equ $-msg3

msg4: db"The perimeter of the Rectangle is:: ",0xA
len4: equ $-msg4

menu: db 0xA,"1.Calculate Square Perimeter",0xA,"2.Calculate Rectangle Perimeter",0xA,"3.Exit",0xA
menulen: equ $-menu

SECTION .bss
choice: resb 2    ;for choice of menu
leng: resb 2    ;for length of the square
base: resb 4    ;for base of the rectangle
height : resb 2    ;for height of the rectangle
peri : resb 4    ;for permeter of square
perirect : resb 4
res1 :resb 4

res2: resb 4
resl: resb 1
resm: resb 1
count: resb 1
tempnum: resb 1


SECTION .text

global _start:
_start:

menuprint:

print menu,menulen        ; accepting choice
read choice,2

cmp byte[choice],31h
je PerimeterofSquare

cmp byte[choice],32h
je PerimeterofRectangle

cmp byte[choice],33h
je EXIT


PerimeterofSquare:
        print msg,len
        read leng,10     ; reading the number
           
            convert_lengths:    ;converting from ascii to hex
            mov bl,00
            mov esi,leng
            mov ecx,2       
            loop1:   
                rol bl,04
                mov al,[esi]
                cmp al,39h
                jbe loop2
                sub al,07h
            loop2:
                sub al,30h
                add bl,al
                inc esi
            loop loop1
    mov byte[resl],00            ; initializing all variables
    mov byte[resm],00
    mov byte[tempnum],00
    mov [tempnum],bl
    mov al,[tempnum]
    mov byte[count],4
    addp:
        add[resl],al            ;successive addition of the number for 4 times caz
        adc byte[resm],00        ; perimeter of the square=4*length
        dec byte[count]
        jnz addp

    mov bl,[resl]
    mov bh,[resm]                               
    mov [peri],bx
    convert_result:                ;converting the result into the hex   
            mov esi,peri
            mov ecx,4
            loop3:
                rol bx,04
                mov al,bl
                and al,0Fh
                cmp al,09h
                jbe loop4
                add al,07h
            loop4:
                add al,30h
                mov [esi],al
                inc esi
            loop loop3       
    print msg3,len3
    print peri,4
jmp menuprint

PerimeterofRectangle:
           
            print msg1,len1
            read base,10        ;accepting the base
               
                mov ecx,2    ;converting ascii to hex
                mov esi,base
                mov bl,00
            loop5:
                rol bl,04
                mov al,byte[esi]
                cmp al,39h
                jbe loop6
                sub al,07h
            loop6:
                sub al,30h
                add bl,al
                inc esi
            loop loop5
    mov byte[resl],00        ; initializing the data
    mov byte[resm],00
    mov byte[tempnum],00
    mov [tempnum],bl
    mov al,[tempnum]
    mov byte[count],2
    addp1:
        add[resl],al
        adc byte[resm],00
        dec byte[count]
        jnz addp1        ; successive addition for two times
                    ; base=base+base
    mov bl,[resl]            ; height=height+height
    mov bh,[resm]
    mov [res1],bx
    ;add byte[res1],30h
    ;print res1,4
       
        print msg2,len2
        read height,4
                mov ecx,2
                mov esi,height
                mov bh,00
            loop7:
                rol bh,04
                mov ah,byte[esi]
                cmp ah,39h
                jbe loop8
                sub ah,07h
            loop8:
                sub ah,30h
                add bh,ah
                inc esi
            loop loop7

    mov byte[resl],00
    mov byte[resm],00
    mov byte[tempnum],00
    mov [tempnum],bh        ;Similar operations on height
    mov al,[tempnum]
    mov byte[count],2
    addp2:
        add[resl],al
        adc byte[resm],00
        dec byte[count]
        jnz addp2

    mov bl,[resl]
    mov bh,[resm]
    add bx,[res1]        ;adding the both results
    mov [res2],bx
    ;add byte[res2],30h
    ;print res2,4
   
       
            mov ecx,4
            mov rsi,perirect
            loopl:
                rol bx,04
                mov al,bl
                and al,0Fh
                cmp al,09h
                jbe loopl2
                add al,07h
            loopl2:
                add al,30h
                mov [rsi],ax
                inc rsi        ;converting hex to ascii
            loop loopl
    print msg4,len4   
    print perirect,4
jmp menuprint
EXIT:
mov rax,60
mov rdi,0
syscall

Hex to BCD BCD to Hex Conversion NASM

%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro read 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro

SECTION .data
msg: db"Enter the four digit hex number::",0xA
len: equ $-msg

msg1: db"Enter the five digit BCD number::",0xA
len1: equ $-msg1

msg2: db"BCD number of given hex number::"
len2: equ $-msg2

msg3: db"HEX number of given BCD number::"
len3: equ $-msg3

menu: db 0xA,"1.HEX TO BCD",0xA,"2.BCD TO HEX",0xA,"3.EXIT",0xA
lmenu: equ $-menu

SECTION .bss
choice: resb 2
hexNum: resb 10
bcdNum:resb 10
count: resb 1
result: resb 6
result1: resb 5

SECTION .text

global _start:
_start:

menuprint:
    print menu,lmenu
    read choice,2

cmp byte[choice],31h
je HextoBCD
cmp byte[choice],32h
je BCDtoHex
cmp byte[choice],33h
je exit

HextoBCD:
    ;accepting the number
    print msg,len
    read hexNum,10
        ;converting the ascii to hex
        convert:
                mov esi,hexNum
                mov bx,0
                mov ax,0
                mov ecx,4
                loop1:
                    rol bx,04h
                    mov al,[rsi]
                    cmp al,39h
                    jbe loop2
                    sub al,07h
                loop2:
                    sub al,30h
                    add bx,ax
                    inc rsi
        loop loop1   
mov ax,bx
mov edx,0 ; mov 00 in edx
mov ecx,10 ; mov counter as 10
mov byte[count],5
mov rsi,result ;pointing source as result

Div:
      div cx
    mov byte[rsi],dl
    add rsi,1
    dec byte[count]
    mov dl,0
jnz Div

sub rsi,1
mov byte[count],5
mov rdi,result1

Transfer:
        mov al,byte[rsi]
        mov byte[rdi],al
        dec rsi
        inc rdi
        dec byte[count]
jnz Transfer

mov byte[count],5
mov rsi,result1

convertResult:
        add byte[rsi],30h
        inc rsi
        dec byte[count]
jnz convertResult

print msg2,len2
print result1,5
jmp menuprint
   
BCDtoHex:
print msg1,len1
read bcdNum,10

convert_bcd:
        mov ecx,5
        mov ebx,0
        mov eax,0
        mov rsi,bcdNum
        loop31:
            rol ebx,04h
            mov al,byte[rsi]
            cmp al,39h
            jbe loop41
            sub al,07h
        loop41:
            sub al,30h
            add ebx,eax
            inc esi
        loop loop31


mov eax,0h

mov [result],ebx
mov esi,result

add esi,2 ;addin two mean?
mov dl,byte[esi]

mov byte[count],dl
cmp byte[count],0

jz loop4

loop5:
    add ax,10000
    dec byte[count]
jnz loop5

loop4:
    dec esi
    mov dl,byte[esi]
    rol dl,04h
    and dl,0Fh
    mov byte[count],dl
    cmp byte[count],0
jz loop6
loop7:
    add ax,1000
    dec byte[count]
jnz loop7

loop6:
    mov dl,byte[rsi]
    and dl,0Fh
    mov byte[count],dl
    cmp byte[count],0
jz loop8
loop9:
    add ax,100
    dec byte[count]
jnz loop9

loop8:
    mov esi,result
    mov dl,byte[esi]
    rol dl,04h
    and dl,0Fh
    mov byte[count],dl
    cmp byte[count],0
jz loop10

loop11:
    add ax,10
    dec byte[count]
jnz loop11

loop10:
    mov dl,byte[esi]
    and dl,0Fh
    mov byte[count],dl
    cmp byte[count],0
jz loop12
loop13:
    add ax,1
    dec byte[count]
jnz loop13
loop12:
    mov dx,ax

convert_result_to_ascii:
            mov ax,0
            mov ecx,4
            mov esi,result1
        loop14:
            rol dx,04
            mov al,dl
            and al,0Fh
            cmp al,09h
            jbe loop15
            add al,07h
        loop15:
            add al,30h
            mov [esi],al
            inc rsi
           
            loop loop14
print msg3,len3
print result1,4
jmp menuprint

exit:
mov rax,60
mov rdi,0
syscall


   
Home Java Python PHP