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 VIGENERE CIPHER using C++


AIM:

            Towrite a  C++ program toimplement Vigenere  Cipher.



ALGORITHM:

Step 1: Enter the plain text  for encryption.

Step 2:Enter  the  encryption key pharse.

Step 3:  Cipher text is obtained by modular addition  of a  key pharse and  plain  text.

Step 4: For decryption to get the plaintext again the key pharse is modularly subtracted from the cipher  text.

Step 5: Display the cipher text and plaintext.





PROGRAM:

// Vigenere Cipher

#include <iostream>

#include <string>

using namespace std;

class Vigenere

{

    public:

        string key;

Vigenere(string key)

        {

for (int i = 0; i <key.size(); ++i)

            {

                if (key[i] >= 'A' && key[i] <= 'Z')

                    this->key += key[i];

                else if (key[i] >= 'a' && key[i] <= 'z')

                    this->key += key[i] + 'A' - 'a';

            }

        }                                             

string encrypt(string text)

        {

            string out;

for (int i = 0, j = 0; i <text.length(); ++i)

            {

                char c = text[i];

             if (c >= 'a' && c <= 'z')

                    c += 'A' - 'a';

                else if (c < 'A' || c > 'Z')

                    continue;

                out += (c + key[j] - 2 * 'A') % 26 + 'A';

                j = (j + 1) % key.length();

            }

            return out;

       }

string decrypt(string text)

        {

            string out;

for (int i = 0, j = 0; i <text.length(); ++i)

            {

                char c = text[i];

                if (c >= 'a' && c <= 'z')

                    c += 'A' - 'a';

                else if (c < 'A' || c > 'Z')

                    continue;

                out += (c - key[j] + 26) % 26 + 'A';

                j = (j + 1) % key.length();

            }

            return out;

 }

};

int main()

{

Vigenere cipher("VIGENERECIPHER");

    string original = "Beware of Dogs";

string encrypted = cipher.encrypt(original);

string decrypted = cipher.decrypt(encrypted);

cout<<"original"<<endl;

cout<<"Encrypted: "<<encrypted<<endl;

cout<<"Decrypted: "<<decrypted<<endl;

}


OUTPUT:

Comments

Popular posts from this blog

IMPLEMENTATION OF SHA-1 ALGORITHM using JAVA

IMPLEMENTATION OF RSA ALGORITHM using c++

IMPLEMENTATION OF DIFFIE HELLMAN KEY EXCHANGE ALGORITHM