Wednesday, April 17, 2019

chmod 777/media/ enable
chmod 444/media/ disable 
cat /dev/null > ~/.bash_history && history -c && exit
*****************************************************************
*********************************************Chinese Reminder assignment******************************

#include<iostream>
using namespace std;

int calc_inv(int a, int b)
{
 int x, y; 
        int b0 = b, t, q;
 int x0 = 0, x1 = 1;
 if (b == 1) 
  return 1;
 while (a > 1) 
 {
     q = a / b;
     t = b, 
     b = a % b, 
     a = t;
     t = x0, 
     x0 = x1 - q * x0, 
     x1 = t;
 }
 if (x1 < 0) x1 += b0;
 return x1;  
}

int main()
{ 
 int i,n, a[10], b[10], m[10], m_inv[10], prod = 1, sum = 0;
 cout<< "\n Enter the numer of equations";
 cin >>n;
 for(i=0;i<n;i++)
 { 
  cout<<"\nEnter the quation "<< i+1;
  cout<<"\n Enter the value of a1 :";
  cin>>a[i];
  cout<<"\n Enter the value of b1 :";
  cin>>b[i];
  prod = prod * b[i];
 }
 for(i=0;i<n;i++)
 {
  m[i] = prod / b[i];
  m_inv[i] = calc_inv(m[i],b[i]);
  sum = sum + (a[i] * m[i] * m_inv[i]);
 }
 cout<<"The number is :" << (sum % prod);
}


************************************RSA Assignment******************************

#include<iostream>
#include<math.h>
using namespace std;

int gcd(int a,int b)
{
 int r;
    while(1)
 {
  r = b%a;
  if (r == 0)
   return a;
  b = a;
  a = r;
    }
}
int main()
{
 int p,q,n,z,d=0,e,i,x,y;
 double msg,c,msgback;
 cout<<"Enter the number to be encrypted :";
 cin>>msg;
 cout<<"Enter first prime number :";
 cin>>p;
 cout<<"Enter second prime number :";
 cin>>q;
 n=p*q;
 z=(p-1)*(q-1);
 
 cout<<"The value of Z is :" << z <<endl;
 for(e=2;e<z;e++)
 {
  if (gcd(e,z)==1)
  {
   break;
  }
 }
 cout<<"The value of E is :" << e <<endl;
 i=1;
 while(1)
 {
  int x=1+(i*z);
  if(x%e==0)      
  {
  d=x/e;
  break;
  }
  i++;
 }
 cout<<"The value of D is :" << d <<endl;
 c=pow(msg,e);
 c=fmod(c,n);
 cout<<"Encrypted Message is :" << c << endl;
 msgback = pow(c,d);
 msgback=fmod(msgback,n);
 cout<<"Decrypted Message is :" << msgback << endl;
 return 0;
}
*****************************************************************
********************* Assignment   ************************************
*********************************************SHA assignment******************************

// Java program to calculate SHA-1 hash value 
import java.io.BufferedReader; 
import java.io.IOException; 
import java.math.BigInteger; 
import java.security.MessageDigest; 
import java.security.NoSuchAlgorithmException; 
import java.io.InputStreamReader; 
import java.io.UnsupportedEncodingException; 


public class sha1 { 
 public static String encryptThisString(String input) 
 { 
  try { 
   // getInstance() method is called with algorithm SHA-1 
   MessageDigest md = MessageDigest.getInstance("SHA-1"); 

   // digest() method is called 
   // to calculate message digest of the input string 
   // returned as array of byte 
   byte[] messageDigest = md.digest(input.getBytes()); 

   // Convert byte array into signum representation 
   BigInteger no = new BigInteger(1, messageDigest); 

   // Convert message digest into hex value 
   String hashtext = no.toString(16); 

   // Add preceding 0s to make it 32 bit 
   while (hashtext.length() < 32) { 
    hashtext = "0" + hashtext; 
   } 

   // return the HashText 
   return hashtext; 
  } 

  // For specifying wrong message digest algorithms 
  catch (NoSuchAlgorithmException e) { 
   throw new RuntimeException(e); 
  } 
 } 

 // Driver code 
 public static void main(String[] args) throws IOException { 
        BufferedReader userInput = new BufferedReader (new InputStreamReader(System.in));
 
        System.out.println("Enter string:");
        String rawString = userInput.readLine();

        System.out.println("SHA1 hash of string: " + encryptThisString(rawString));

}
}

javac filename.java
java filename

***********************************************************************************************************