Wednesday, 9 July 2014

Caesar Cipher Encryption and decryption concept

Caesar Cipher Encryption and decryption concept is very essential technique when working with Cryptography. The key values can be set on the basis of the programmers need. Here I have set the default key as 4 here. And my loop will cover 26 alphabets only... Hope it will help you...
*********************************************************************************

import javax.swing.JOptionPane;


public class Caesar_Cipher {

/* It is not needed to show our assumption explicitly */
    private final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
    /* function _encrypt to encrypt the plain text with key value assumed
     * The key value assumed here is _shiftKey=4 indexed in main */
    public String encrypt(String plainText,int shiftKey)
    {
    /*converting to lower case as per the assumption*/
          plainText = plainText.toLowerCase();
          String cipherText="";
          for(int i=0;i<plainText.length();i++)
          {
               int charPosition = ALPHABET.indexOf(plainText.charAt(i));
               /* appending key value to the actual index */
               int keyVal = (shiftKey+charPosition)%26;
               char replaceVal = this.ALPHABET.charAt(keyVal);
               cipherText += replaceVal;
          }
          return cipherText;
    }
    public String decrypt(String cipherText, int shiftKey)
    {
          cipherText = cipherText.toLowerCase();
          String plainText="";
          for(int i=0;i<cipherText.length();i++)
          {
               int charPosition = this.ALPHABET.indexOf(cipherText.charAt(i));
               int keyVal = (charPosition-shiftKey)%26;
               if(keyVal<0)
               {
                     keyVal = this.ALPHABET.length() + keyVal;
               }
               char replaceVal = this.ALPHABET.charAt(keyVal);
               plainText += replaceVal;
          }
          return plainText;
    }
}

class CaesarDemo {
 

public static void main(String args[])
    {
  String plainText = (JOptionPane.showInputDialog("Input Data to encypt:"));
          int shiftKey=4;
       
          Caesar_Cipher cc = new Caesar_Cipher();
       
          String cipherText = cc.encrypt(plainText,shiftKey);
          System.out.println("Your Plain  Text :" + plainText);
          System.out.println("Your Cipher Text :" + cipherText);
       
          String cPlainText = cc.decrypt(cipherText,shiftKey);
          System.out.println("Your Plain Text  :" + cPlainText.replaceAll("z", " "));
    }
}

*****************************Thank You*******************************

Saturday, 14 June 2014

DOUBLE POINTER TO REVERSE ARRAY

# include <stdio.h>
# include <conio.h>
display(int *a);
show(int **b);
int main()
{
 clrscr();
 int arr[]={1,2,3};
 for(int i=2;i>=0;i--)
 {
  display(&arr[i]);
 }
 return 00;
}
 display(int *p)
 {
  show(&p);
 }
 show(int **pointer)
 {
  printf("\n %d",**pointer);
 }

 

Friday, 24 January 2014

scrolling Tag in html

<html>
<head>
<title> Dragon Scroll </title>
<body bgcolor="pink">
<h1>
<marquee dir="right" > <font color="red" > Dragon warrior will have the dragon Scroll...... !! </font> </marquee>
</h1>
</body>
</html>


Smart Table

<html>
<head>
<title> Table </title>
</head>
<body>
<table border="2">
<tr>
  <th rowspan="2"> S.No </th>
  <th colspan="2"> Name </th>
</tr>
<tr>
  <th> First Name </th>
  <th> Last Name </th>
</tr>
<tr>
 <td> 1 </td>
 <td> TOM </td>
 <td> FARCRY </td>
</tr>
</table>
 </body>
 </html>



Red color link in html

<html>
<head>
<title> Link </title>
</head>
<body bgcolor="blue">
<h1> Exciting
<a href="http://www.wallcg.com" > <Font color="red" size="48"> Wall papers <Font> </a>
</h1>
</body>
</html>



Paragraph tag

<html>
<head>
<title> Sample Paragraph </title>
</head>
<body>
<h1> Internet Protocols </h1>
<p> Protocols are just like guide lines for packet. The Internet Protocol (IP) is the principal communications protocol in the Internet protocol suite for relaying datagrams across network boundaries. Its routing function enables internetworking, and essentially establishes the Internet.
</p>
</body>
</html>


Proper Alingment

<html>
<head>
<title> Proper align </title>
</head>
<body>
<h1> STUDENT DETAIL </h1>
<h5> Name : Tom Farcry </h5>
<h5> Roll NO : 12xyz12 </h5>
<h5> Age : 20 </h5>
<h5> PhoneNo : 1234567890 </h5>
<h5> Address : DownTown street </h5>
</body>
</html>