Thursday 2 November 2023

The aphorism “security through obscurity” suggests that hiding information provides some level of security. Give an example of a situation in which hiding information does not add appreciably to the security of a system. Then give an example of a situation in which it does.

Answer

An example of a situation in which hiding information does not add appreciably to the security of a system is hiding the implementation of the UNIX password hashing algorithm. The algorithm can be determined by extracting the object code from the relevant library routine. Revealing the algorithm does not appreciably simplify the task of an attacker because he still must guess the password itself. An example of a situation in which hiding information adds appreciably to the security of a system is hiding the password or a cryptographic key. This is private information affecting a single user. Revealing it would give the attacker access to the user’s account.

Thursday 27 September 2018

Develop a program that creates a vector to insert and display five elements of different data types

Develop a program that creates a vector to insert and display five elements of different data types

Program:


import java.util.*;
class VectorDemo
{
                public static void main(String args[])
                {
                                Vector v = new Vector();
                                v.addElement(new Integer(10));
                                v.addElement(new Float(1.2));
                                v.addElement(new Double(5.2));
                                v.addElement(new Character('A'));
                                v.addElement(new String("Ashish"));
                                int s = v.size();
                                for(int i=0;i<s;i++)
                                System.out.println(v.elementAt(i));
                }
}

Output:


Develop a program to convert a string from lowercase to uppercase using method of String class.

Develop a program to convert a string from lowercase to uppercase using method of String class.

Program:

import java.util.*; 
class ConvertCasePrg
{
   public static void main(String args[])
   {
Scanner sc= new Scanner(System.in);
String str="";

//input string
System.out.print("Enter any string: ");
str=sc.nextLine();

//declaring objects to store lowercase and uppercase strings
String lowerCaseString="",upperCaseString="";

//convert into lower case
lowerCaseString= str.toLowerCase();  
//convert into upper case
upperCaseString= str.toUpperCase();  

//printing the strings
System.out.println("Original String: "+str);
System.out.println("Lower Case String: "+lowerCaseString);
System.out.println("Upper Case String: "+upperCaseString);   
   }

}

Output:



Develop a program to create a class Student with data membersstudent_name, roll_no& branch. Initialize and display values of data members.

Develop a program to create a class Student with data members student_name, roll_no&  branch. Initialize and display values of data members.

Program:

import java.lang.*;
import java.io.*;
class Student
{
 String name;
 int roll_no;
 String branch;

 void getdata() throws IOException {
 
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  System.out.println ("Enter Name of Student");
  name = br.readLine();
 
  System.out.println ("Enter Roll No. of Student");
  roll_no = Integer.parseInt(br.readLine());
 
  System.out.println ("Enter branch name");
  branch = br.readLine();

  }

 void show() {
 
  System.out.println ("Roll No. = "+roll_no);
  System.out.println ("Name = "+name);
  System.out.println ("Enter branch name = "+branch);
   }
}

public class StudentDemo {

 public static void main(String[] args) throws IOException {
 
  Student s=new Student();
  s.getdata();
  s.show();
 }
}

Output:



Number Pattern Printing Programming

How to print number pattern programming

class NumberPattern
{
  public static void main(String[] args)
  {
  for (int i = 1; i <= 5; i++)
  {
for (int j = 1; j <= i; j++)
     {
  System.out.print(j+" ");
   }
System.out.println();
}
}
}

Output:



class NoPattern
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
  {
   for (int j = 1; j <= i; j++)
   {
         if(j%2 == 0)
     {
System.out.print(0);
     }
else
{
System.out.print(1);
}
   }           
System.out.println();
}
}
}

Output:



class NumberPattern
{
public static void main(String[] args)
{
for (int i = 1; i <= 6; i++)
  {
    for (int j = 1; j <= i; j++)
     {
       System.out.print(j+" ");
     }
for (int j = i-1; j >= 1; j--)
  {
      System.out.print(j+" ");
    }
    System.out.println();
   }
}
}

Output:

Thursday 20 July 2017

Java to print Star Pattern

program 1

class StarTriangle
{
 public static void main(String[] args)
 {
  int i,j,k;
  for(i=1; i<=5; i++)
  {
   for(j=4; j>=i; j--)
   {
    System.out.print(" ");
   }
    for(k=1; k<=(2*i-1); k++)
    {
     System.out.print("*");
    }
     System.out.println("");
   }
  }
}

Output
          *
        *  *
       *  *  *
     *  *  *  *

   *   *  *  *  * 

program 2

class Star 
{
 public static void main(String[] args) 
 {
  int i, j, k;
  for(i=5;i>=1;i--)
  {
   for(j=5;j>i;j--)
   {
    System.out.print(" ");
   }
    for(k=1;k<(i*2);k++)
    {
     System.out.print("*");
    }
     System.out.println();
   }
  }
}
Output:

* * * * * * * * *
  * * * * * * *
    * * * * *
      * * * 
        *


program 3

class Star 
{
 public static void main(String[] args) 
 {
  int i,j;
  for(i=1; i<=6; i++)
  {
   for(j=1; j<i; j++)
   {
    System.out.print("*");
   }
    System.out.println();
  }
 }
}

Output
*
* *
* * *
* * * *
 * * * * *

program 4

class Star 
{
 public static void main(String[] args) 
 {
  int i, j;
  for(i=5;i>=1;i--)
  {
   for(j=1;j<=i;j++)
   {
    System.out.print("*");
   }
    System.out.println();
  }
 }
}

Output
* * * * *
* * * *
* * *
* *
*

program 5

class Star 
{
 public static void main(String[] args) 
 {
  int i, j, k;
  for(i=5;igt;=1;i--)
  {
   for(j=1;jlt;i;j++)
   {
    System.out.print(" ");
   }
    for(k=5;k>=i;k--)
    {
     System.out.print("*");
    }
     System.out.println();
  }
 }
}

Output
        *
      * *
    * * *
  * * * *
* * * * *

program 6

class Star 
{
 public static void main(String[] args) 
 {
  int i, j, k;
  for(i=5;i>=1;i--)
  {
   for(j=5;j>i;j--)
   {
    System.out.print(" ");
   }
    for(k=1;k<=i;k++)
    {
     System.out.print("*");
    }
     System.out.println();
   }
  }
}

Output
* * * * *
  * * * * 
    * * * 
      * * 
        *

program 7

class Star 
{
 public static void main(String[] args) 
 {
  int i, j, k;
  for(i=1;i<=5;i++)
  {
   for(j=i;j<5;j++)
   {
    System.out.print(" ");
   }
    for(k=1;k<(i*2);k++)
    {
     System.out.print("*");
    }
     System.out.println();
  }
     for(i=4;i>=1;i--)
     {
for(j=5;j>i;j--)
{
System.out.print(" ");
}
for(k=1;k<(i*2);k++)
{
 System.out.print("*");
         }
 System.out.println();
     }
  }
}


Output
            *
         * * * 
     * * * * * *
  * * * * * * * *
* * * * * * * * *
  * * * * * * *
    * * * * *
      * * *
        *

Friday 24 March 2017

Diffie Hellman algortihm java code

package diffiehellman;
import java.util.*;
import java.io.*;
class DiffieHellman
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println(“Enter the value of Xa & Xb”);
        int Xa=sc.nextInt();
        int Xb=sc.nextInt();
        System.out.println(“Enter a Prime no. p”);
        int p=sc.nextInt();
        System.out.println(“Enter Primitive Root a, such that a<p”);
        int a=sc.nextInt();
        int Ya=(int)((Math.pow(a,Xa))%p);
        int Yb=(int)((Math.pow(a,Xb))%p);
        int Ka=(int)((Math.pow(Yb,Xa))%p);
        int Kb=(int)((Math.pow(Ya,Xb))%p);
        if(Ka==Kb)
        {
            System.out.println(“Transmission successful”);
        }
        else
        {
            System.out.println(“Transmission failed”);
        }
    }
}