Sunday, October 8, 2017

WT practicals 5,6,7

Login.html


<html>
<title>Login</title>
<head><center><font size="20" color="aqua" face="Times New Roman">Login</font></center>
<script language="javascript">
function my(){
if(f.m1.value="9023074222" && f.p1.value="1507623"){
alert('Welcome Iron Man');
return true;
document.getElementById('demo').innerHtml="Hello";

}else{
alert('Wrong Credentials');
return false;
}
}


</script>
</head>
<body background="t.jpg">
<center>
<p id="demo"></p>
<font size="5" color="red"><p>* Mandatory Fields</p></font>
<form name="f" action="" method="post">
<pre>
<font size="5" color="DarkTurquoise" face="Arial">
Mobile Number:<font color="red">*</font>    <input type="number" name="m1" required placeholder="Mobile Number" style="margin-left:-0.2in;"><br>
Password:<font color="red">*</font>    <input type="password" name="p1" required placeholder="Password" style="margin-left:0.3in;"><br><br>
<input type="submit" name="s"  value="Submit" onClick="my()">     <input type="reset" value="Reset" name="r1"><br>
<a href="forgot.html" >Forgot Password</a>
</font>
</pre>
</form>
</center>
<marquee direction="left" behavior="alternate"><img src="f.png" height=200 width=200>   <img src="i.png" height=200 width=200>    <img src="tw.png" height=200 width=200>
</marquee>

</body>
</html>

Output:



Registration.html


<html>
<head><title>Register Nearur</title>
<center style="color:purple; font-size:50px;">Registration Form</center>
<img src="photo.jpg" width="200px" height="200px">
</head>
<style>
.b
{
font-size:25px;
}
</style>
<body>
<br>
<br>
<center>
<form method="post" action="reg.php">
<table style=" font-size:25px; margin-top:-2in;">
<tr><td>First Name:</td> <td><input type="text" required name="a1" class="b"></td></tr>
<tr><td>Last Name:</td> <td>  <input type="text" required name="a2"class="b"></td></tr>
<tr><td>Mobile Number:</td> <td> <input type="number" required name="a3"class="b"></td></tr>
<tr><td>Password:</td> <td> <input type="password" required name="a4"class="b"></td></tr>
<tr><td>Retype Password:</td> <td> <input type="password" required name="a5"class="b"></td></tr>
<tr><td>Address:</td> <td> <input type="text" required name="a6"class="b"></td></tr>
<tr><td>Security Question:</td> <td> <select required name="a7"class="b"><option>What is Your Nickname?</option><option>Who is your favourite Cricket Player?</option><option>What is your BirthPlace?</option><option>Which is your Favourite Dish?</option></select></td></tr>
<tr><td>Answer:</td> <td> <input type="text" required name="a8"class="b"></td></tr>
</table>
<br>
<input type="submit" name="a9" value="Register" class="b">&nbsp;<input type="reset" name="b" value="Reset" class="b">
</form>
</center>
<marquee behavior="alternate" scrollamount="9"><img src="b.jpg" width="300px" height="200px"><img src="c.jpg" width="300px" height="200px"><img src="d.jpg" width="300px" height="200px"></marquee>
</body>
</html>

Output:



Link.html


<html>
<head>
<title>Practical5</title>
</head>
<body background=""><center>
<h1 style="font-size:50px; font-family:Arial;">Nearur</h1>
<p style="font-size:25px; font-family:Arial;">Choose From Below Mobiles</p>
<a href="#8" title="#8"><img src="8.jpeg" align="left" /></a>
<a href="X.html" title="X.html"><img src="9.png" align="right" style="margin-right:1.5in;"></a>
</center>
</body>

</html>

Output:




Wednesday, October 4, 2017

Problem Array Sort Shuffle

Code:

public class Akhil {

    public static void main(String [] nt){

        int[] a={1,3,4,2};

        if(!sorted(a)){
            for (int i=0;i<a.length-2;i++){
                if(!sorteda(a[i],a[i+1],a[i+2])){
                    if(sorteda(a[i+1],a[i+2],a[i])){
                        int temp=a[i];
                        a[i]=a[i+1];
                        a[i+1]=a[i+2];
                        a[i+2]=temp;
                        continue;
                    }else {
                        if(sorteda(a[i+2],a[i],a[i+1])){
                            int temp=a[i];
                            a[i]=a[i+2];
                            a[i+2]=a[i+1];
                            a[i+1]=temp;
                            continue;
                        }else{
                            break;
                        }
                    }
                }
            }
        }

        if(sorted(a)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }

    static boolean sorted(int[] a){

        for(int i=0;i<a.length-1;i++){
            if(a[i]>a[i+1]){
                return false;
            }
        }

        return true;
    }

    static boolean sorteda(int a,int b,int c){
        if(a<b && b<c){
            return true;
        }
        return false;
    }

}

Primorial Prime Numbers

Code:

import java.util.ArrayList;

public class PP {

    public static void main(String[] nt){

        // To avoid repetion of Primorial primes        ArrayList<Integer>integers=new ArrayList<>();

        //This is end Value        int x=11;


        for(int J=2;J<=x;J++) {
            int pn = 1;
//Calculating Primorial            for (int i = 2; i <= J; i++) {
                if (isprime(i)) {
                    pn = pn * i;
                }
            }
//Checking For Prime            if(isprime(pn-1)){
                if(!integers.contains(pn-1)){
                    integers.add(pn-1);
                }

            }if(isprime(pn+1)){
                if(!integers.contains(pn+1)){
                    integers.add(pn+1);
                }
            }
        }
//Printing all Primorial Primes        for (int a:integers){
            System.out.println(a);
        }


    }

    static boolean isprime(int n){

        for (int i=2;i<=n/2;i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }

}

Output:


Tuesday, October 3, 2017

Bresenham VS DDA

Write a program to input the line coordinates from the user to generate a line using Bresenham’s method and DDA algorithm. Compare the lines for their values on theplotted line.

Code:


#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main(){

    int g=DETECT,gmode;
    initgraph(&g,&gmode,"C://TURBOC3//BGI");
    float x1,x2,y1,y2;
    cout<<"Enter coordinates\n";
    cout<<"x1:";
    cin>>x1;
    cout<<"y1:";
    cin>>y1;
    cout<<"x2:";
    cin>>x2;
    cout<<"y2:";
    cin>>y2;
    int x3=x1+100;
    int x4=x2+100;
    int y3=y1,y4=y2;
    int y=y2-y1;
    int x=x2-x1;
    float m=y/x;
    int d=2*y-x;
    putpixel(x1,y1,10);
    if(m<=1){
    while(x1!=x2){
      if(d>0){
y1++;
d=d+2*(y-x);
      }else{
      d=d+2*y;
      }
      x1++;
      putpixel(x1,y1,10);
    }}else{
      while(y1!=y2){
      if(d>0){
x1++;
d=d+2*(y-x);
      }else{
      d=d+2*y;
      }
      y1++;
      putpixel(x1,y1,10);
    }
    }
    if(m<=1){
    while(x3!=x4){
    x3++;
    y3=y3+m;
    putpixel(x3,y3,10);
    }
    }else{
    while(y3!=y4){
    y3++;
    x3=x3+1/m;
    putpixel(x3,y3,10);
    }

    }
    setcolor(15);
    settextstyle(1,HORIZ_DIR,2);
    outtextxy(x2+15,y2,"Bresenham");
    outtextxy(x2+135,y2,"DDA");
    getch();
}

   Output:


Sunday, September 24, 2017

DDA(Digital Differential Algorithm)

Code:

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main(){

    int g=DETECT,gmode;
    initgraph(&g,&gmode,"C://TURBOC3//BGI");
    float x1,x2,y1,y2;
    cout<<"Enter coordinates\n";
    cout<<"x1:";
    cin>>x1;
    cout<<"y1:";
    cin>>y1;
    cout<<"x2:";
    cin>>x2;
    cout<<"y2:";
    cin>>y2;
    float m=(y2-y1)/(x2-x1);
    putpixel(x1,y1,10);
    if(m<=1){
    while(x1!=x2){
    x1++;
    y1=y1+m;
    putpixel(x1,y1,10);
    }
    }else{
    while(y1!=y2){
    y1++;
    x1=x1+1/m;
    putpixel(x1,y1,10);
    }

    }
    getch();
}


Output:



Thursday, September 21, 2017

Indeed Prime Challenge 2015

Problem:
For example, consider array A such that:
A[0] = 1 A[1] = 3 A[2] = 2 A[3] = 1 A[4] = 2 A[5] = 1 A[6] = 5 A[7] = 3 A[8] = 3 A[9] = 4 A[10] = 2
The following picture illustrates the landscape after it has flooded:
The gray area is the rock floor described by the array A above and the blue area with dashed lines represents the water filling the low-lying areas with maximum possible volume. Thus, blocks 3 and 5 have a water depth of 2 while blocks 2, 4, 7 and 8 have a water depth of 1. Therefore, the maximum water depth of this area is 2.


Code:

public class Solution {

    public static void main(String[] nt){
        int[] a={1,3,2,1,2,1,5,3,3,4,2};
        System.out.print("Max Depth is : "+solution(a));
    }

    static int solution(int[] a){
        int i=Integer.MIN_VALUE;
        int[] left=new int[a.length];
        int[] right=new int[a.length];

        int max=a[0];
        for(int x=0;x<a.length;x++){
            if(a[x]>max){
                max=a[x];
            }
            left[x]=max;
        }

        max=a[a.length-1];
        for(int x=a.length-1;x>=0;x--){
            if(a[x]>max){
                max=a[x];
            }
            right[x]=max;
        }

        for(int x=0;x<a.length;x++){
            int z=min(left[x],right[x])-a[x];
            i=i<z?z:i;
        }

        return i;
    }

    static int min(int a,int b){
        if(a>b){
            return b;
        }return a;
    }
}

Output:



Saturday, September 16, 2017

PlayFair Cipher

PlayFair Cipher Java:

Code:

1-----> PlayFair.java



package com.nearur;

import java.awt.*;

public class PlayFair {
   
   private String key="Monarchy";
   private char[] keyarraay=key.toUpperCase().toCharArray();
   private char[] alpha={'A','B','C','D','E','F','G','H','I','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
   char[][] matrix=new char[5][5];
   StringBuffer buffer=new StringBuffer();

   public PlayFair(){
      int j=0,k=0;
      for (int i=0;i<keyarraay.length;i++){
         if(k!=5){
            if(!check(keyarraay[i])){
            matrix[j][k++]=keyarraay[i];
            }
         }else {
            i--;
            k=0;j++;
         }
      }

      for (int i=0;i<alpha.length;i++){
         if(k!=5){
            if(!check(alpha[i])){
               matrix[j][k++]=alpha[i];
            }
         }else {
            i--;
            k=0;j++;
         }
      }

   }

//  function to view matrix   public void show(){
      for (int i=0;i<5;i++) {
         for (int j = 0; j < 5; j++) {
            System.out.print(matrix[i][j]);
         }
         System.out.println();
      }
   }

// function to check for duplicate characters   private boolean check(char a){
      for (int i=0;i<5;i++) {
         for (int j = 0; j < 5; j++) {
            if(matrix[i][j]==a){
               return true;
            }
         }
      }
      return false;
   }


   // function to encrypt   public String encrypt(String msg){

      msg=msg.toUpperCase();
      msg=msg.replaceAll(" ","");
      msg=msg.replaceAll("J","I");
      if(msg.length()%2!=0){
         msg=msg.concat("X");
      }
      char[] msgs=msg.toCharArray();

      for (int i=0;i<msgs.length;i++){
         Point x1=find(msgs[i++]);
         Point x2=find(msgs[i]);

         if(x1.x==x2.x){
//same row            if(x1.y+1==5){
               x1.y=0;
            }
            else {
               x1.y++;
            }
            if(x2.y+1==5){
               x2.y=0;
            }else {
               x2.y++;
            }
            buffer.append(matrix[x1.x][x1.y]);
            buffer.append(matrix[x2.x][x2.y]);
         }else if(x1.y==x2.y){
//same column            if(x1.x+1==5){
               x1.x=0;
            }
            else {
               x1.x++;
            }
            if(x2.x+1==5){
               x2.x=0;
            }else {
               x2.x++;
            }
            buffer.append(matrix[x1.x][x1.y]);
            buffer.append(matrix[x2.x][x2.y]);
         }else{
            //diagonal            if(x2.x>x1.x) {
               int d=x2.x-x1.x;
               x2.x=x2.x-d;
               x1.x=x1.x+d;
            }else{
               int d=x1.x-x2.x;
               x2.x=x2.x+d;
               x1.x=x1.x-d;
            }
            buffer.append(matrix[x2.x][x2.y]);
            buffer.append(matrix[x1.x][x1.y]);

         }

      }

      return buffer.toString();
   }

   // function to decrypt   public String decrypt(String msg){

      buffer.delete(0,buffer.length());
      msg=msg.toUpperCase();

      char[] msgs=msg.toCharArray();

      for (int i=0;i<msgs.length;i++){
         Point x1=find(msgs[i++]);
         Point x2=find(msgs[i]);

         if(x1.x==x2.x){   //same row            if(x1.y-1<0){
               x1.y=4;
            }
            else {
               x1.y--;
            }
            if(x2.y-1<0){
               x2.y=4;
            }else {
               x2.y--;
            }
            buffer.append(matrix[x1.x][x1.y]);
            buffer.append(matrix[x2.x][x2.y]);
         }else if(x1.y==x2.y){   //same column
            if(x1.x-1<0){
               x1.x=4;
            }
            else {
               x1.x--;
            }
            if(x2.x-1<0){
               x2.x=4;
            }else {
               x2.x--;
            }
            buffer.append(matrix[x1.x][x1.y]);
            buffer.append(matrix[x2.x][x2.y]);
         }else{  //diagonal                        if(x2.x>x1.x) {
               int d=x2.x-x1.x;
               x2.x=x2.x-d;
               x1.x=x1.x+d;
            }else{
               int d=x1.x-x2.x;
               x2.x=x2.x+d;
               x1.x=x1.x-d;
            }
            buffer.append(matrix[x2.x][x2.y]);
            buffer.append(matrix[x1.x][x1.y]);

         }

      }

      return buffer.toString();
   }


// function  to return positon of character in matrix   private Point find(char c){
      Point p=null;
      for (int i=0;i<5;i++) {
         for (int j = 0; j < 5; j++) {
            if(matrix[i][j]==c){
               p=new Point(i,j);
               return p;
            }
         }
      }
      return p;
   }

}

2.-------> Encyption.java

package com.nearur;

public class Encryption {

   public static void main(String[] args) {


      PlayFair playFair=new PlayFair();
      String x=playFair.encrypt("key square");
      System.out.println("Cipher : "+x);
      System.out.println("Plain  : "+playFair.decrypt(x));

   }

}

Output:



For Project Click Here  (GitHub Link "https://github.com/mrdishant/Cryptography")