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 HILL CIPHER


AIM:

            To write a  C++ program  to implement Hill  Cipher.



ALGORITHM:

Step 1:  Enter the plain text.

Step 2:Enter  the matrix, named key matrix  for encryption. The elements of the matrix will be randomly chosen and of modulo 26.

Step 3: Plain text characters are multiplied by the encryption matrix.

Step 4: Display the cipher text.

Step 5: Find the inverse of the key matrix.

Step 6: For decryption, multiply  the characters of cipher text by key matrix to get plaintext and display it.





PROGRAM:

#include<iostream>

using namespace std;

int check(int);

int main(intargc,char **argv)

{

int l,i,j,temp1,k[3][3],p[3][1],c[3][1];

char ch;

cout<<"\nThis cipher has a key of length 9";

cout<<"\nEnter the 9 character key";

for(i=0;i<3;i++)

{

                        for(j=0;j<3;j++)

                        {

scanf("%c",&ch);

                                    if (65<=ch&&ch<=91)

                                    k[i][j]=(int)ch%65;

                        else

                                    k[i][j]=(int)ch%97;

                        }

            }

            for(i=0;i<3;i++)

            {

                        for(j=0;j<3;j++)

                        {

            cout<<k[i][j]<<"  ";

                        }

            cout<<endl;

}

cout<<"\nEnter the length of string to be encoded(without spaces). ";

cin>>l;

    temp1=check(l);

if(temp1>0)

cout<<"You have to enter "<<temp1<<" bogus characters.";

    char pi[l+temp1];

cout<<"\nEnter the string. ";

            for(i=0;i<l+temp1;i++)

            {

            cin>>pi[i];

            }

int temp2=l;

int n=(l+temp1)/3;

int temp3,k1;

int flag=0;

int count;

cout<<"\n\nThe encoded cipher is : ";

while(n>0)

{

count=0;

                        for(i=flag;i<flag+3;i++)

                        {

            if(65<=pi[i]&&pi[i]<=91)

                        temp3=(int)pi[i]%65;

            else

                        temp3=(int)pi[i]%97;

p[count][0]=temp3;

count=count+1;

                        }

for(i=0;i<3;i++)

c[i][0]=0;

for(i=0;i<3;i++)          

{

                        for(j=0;j<1;j++)

                        {

                                    for (k1=0;k1<3;k1++)

                                    c[i][j]+=k[i][k1]*p[k1][j];

                        }

                        }

                        for(i=0;i<3;i++)

                        {         

            c[i][0]=c[i][0]%26;

            printf("%c",(char)(c[i][0]+65));



                        }

        n=n-1;

        flag=flag+3;

            }

}

int check(int x)

{

inta,b,c;

    if(x%3==0)

        return 0;

    a=x/3;  
}


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++