Ethical Hacking Lab Manual
ISBN 9788119221523

Highlights

Notes

  

Chapter 7: Use of software tools/commands to encrypt and decrypt password, implement encryption and decryption using Ceaser Cipher

Aim: Use of software tools/commands to encrypt and decrypt password, implement encryption and decryption using Ceaser Cipher

A) Using Cryptool to encrypt and decrypt password.

Perform encryption and decryption of text by using cryptool 2

Using the cryptool 2 tool perform the following:

    a) Ceaser Cipher

    b) Substitution Cipher

    c) Playfair Cipher

Download the current versions of CrypTool 2. There are two versions of CrypTool 2, the stable version and the nightly version. Both versions are available as an EXE installer and as a ZIP archive. The EXE installer supports the creation of a start menu entry, of a desktop link and of an Explorer file type. If you don’t know which one to choose, you should prefer the stable version with EXE installer. No admin rights are needed for the installation. Each installation type (EXE and ZIP) has its own online update mechanism. For execution, a 64-bit Windows and Microsoft.NET Framework 4.7.2 or higher are needed.

Download Stable version

The “Stable Version” is the CrypTool 2 release version The current release version is CrypTool 2.1

Following is the link for download cryptool 2

https://www.cryptool.org/en/ct2/downloads

Step 1: Open Cryptool 2, Click on Use the wizard to easily try some CrypTool 2 features.

Step 2: Select task Encryption and Decryption.

Step 3: Select Classic Encryption / Decryption

Step 4: Select Caesar cipher

Step 5: Enter message in input e.g., Hello Everyone, Select Encrypt.

Step 6: Caesar Output: Decryption Output

B) Implement encryption and decryption using Ceaser Cipher.

CaesarCipher.java

  • import java.util.*;
  • import java.io.*;
  • public class CeaserCipher
  • {
    • public static void main(String[] args) throws IOException
    • {
      • Scanner sc=new Scanner(System.in);
      • BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println(“Enter Text to Encrypt:”);
      • String str=br.readLine(); System.out.println(“Enter Key Value: “); int key = sc.nextInt();
      • String encrypted = encrypt (str, key); System.out.println(“The Encrypted Text is” +encrypted); String decrypted = decrypt(encrypted, key); System.out.println(“The Decrypted Text is” +decrypted);
    • }
    • static String decrypt(String str, int key)
    • {
      • String decrypted=“”;
      • for(int i=0; i<str.length(); i++)
      • {
        • int c=str.charAt(i);
        • if(Character.isUpperCase(c))
        • {
          • c=c-(key%26);
          • if(c<‘A’) c=c+26;
        • }
        • if(Character.isLowerCase(c))
        • {
          • c=c-(key%26);
          • if(c<‘a’)
          • c=c+26;
        • }
        • decrypted+=(char)c;
      • }
      • return decrypted;
    • }
    • static String encrypt(String str, int key)
    • {
      • String strIncremented=new String();
      • for(int i=0;i<str.length();i++)
      • {
        • if(Character.isUpperCase(str.charAt(i)))
        • {
          • int c=str.charAt(i)+key;
          • if(c>‘Z’)
          • {
            • c=str.charAt(i);
            • c=c-26;
            • strIncremented+=(char)(c+key);
          • }else {
            • strIncremented+=(char)(str.charAt(i)+key);
          • }
        • }
        • if(Character.isLowerCase(str.charAt(i)))
        • {
          • int c=str.charAt(i)+key;
          • if(c>‘z’)
          • {
            • c=str.charAt(i);
            • c=c-26;
            • strIncremented+=(char)(c+key);
            • }else {
            • strIncremented+=(char)(str.charAt(i)+key);
          • }

      • return strIncremented;
    • }
  • }

Output: