IMPLEMENTATION OF SHA-1 ALGORITHM using JAVA

Image
AIM: To   write a java program to calculate the message digest of a text using the SHA-1 algorithm ALGORITHM: Step 1: Input the plain text Step 2: Append padding bits Step 3: Append length Step 4:Initialize   buffer. Step 5: Process message in 512-bit (16word)blocks Step 6: Encrypted in hexa decimal format Step 7: Display the encrypted text. PROGRAM: importjava.security.*; public class SHA1 { public static void main(String[] a) { try { MessageDigest md = MessageDigest.getInstance("SHA1"); System.out.println("Message digest object info: "); System.out.println(" Algorithm = " +md.getAlgorithm()); System.out.println(" Provider = " +md.getProvider()); System.out.println(" ToString = " +md.toString());   String input = ""; md.update(input.getBytes()); byte[] output = md.digest(); System.out.println(); System.out.println("SHA1(\""+...

IMPLEMENTATION OF CAESER CIPHER using C++


AIM:

            To write  a  program in C++  to implement  Caesar Cipher.



ALGORITHM:


Step 1: Enter the plaintext to be encrypted and enter the key value.

Step 2: Function encrypt ( ) will be invoked for encryption.

    (a)Take the  ascii value of each plain text char  and add  it with the value  of  key % 26 

               (b)Take the equivalent char value for the resultant value  of  sub-step

               (c)Return the cipher text.

Step 3: Function decrypt ( ) will be invoked for decryption.

              (a)Take the  ascii  value of each cipher text  char  and subtract  the value  of   key % 26  from it

   (b)Take the equivalent char value for the resultant value  of  sub-step(a)

   (c)Return the plain text.



PROGRAM:



#include <iostream>

using namespace std;

void encrypt(char[], int);

void decrypt(char[], int);

int main( )

{ 

char plaintext[20];

int key;

cout<<"\nCAESAR CIPHER\n\n";

cout<<"\nEnter any String:";

cin>>plaintext;

cout<<"\n Enter the Key: ";

cin>>key;

encrypt(plaintext,key);

return 0;

}

void  encrypt(char str[20], int   key)

{

char ch;

int   length= strlen(str);

for(int i = 0; i < length; i++)

{

            ch = str[i];

                        if (isupper(ch))

{

                        ch = ch + (key % 26);

       if (ch> 'Z')

                                    ch = ch - 26;

                        }

                        else if (islower(ch))

                        {

                        ch = ch + (key % 26);

                                    if (ch> 'z')

                                    ch = ch - 26;

                        }

            str[i] = (char) ch;

}

cout<<"\n\nEncrypted String is:" <<str;

decrypt(str,key);

}

void  decrypt(char str[20], int key)

{

char  ch;

int length= strlen(str);

            for(int i = 0; i < length; i++)

            {

            ch = str[i];

                        if (isupper(ch))

                        {

                        ch = ch - (key % 26);

                                    if (ch< 'A')

                                                ch = ch - 26;

                        }

                        else if (islower(ch))

                        {

                        ch = ch - (key % 26);

                                    if (ch< 'a')

                                                ch = ch - 26;

                        }

            str[i] = (char) ch;

}

cout<<"\n\nDecrypted String is:"<<str;

}

                                            


OUTPUT:


Comments

Popular posts from this blog

IMPLEMENTATION OF SHA-1 ALGORITHM using JAVA

IMPLEMENTATION OF DIFFIE HELLMAN KEY EXCHANGE ALGORITHM

IMPLEMENTATION OF VIGENERE CIPHER using C++