You are on page 1of 24

PROGRAMS

Installing Metamask, getting free Ethers and transaction between accounts

Google Metamask.io
https://www.myetherwallet.com/
Java program to implement SHA 256 Hashing algorithm

import java.math.BigInteger;
import java.security.MessageDigest;

public class checkSHA256


{
public static String getSHA(String input)
{
try
{
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] messageDigest = md.digest(input.getBytes());
BigInteger no = new BigInteger(1, messageDigest);
String hashtext = no.toString(16);

while (hashtext.length() < 32)


{
hashtext = "0" + hashtext;
}
return hashtext;
}

catch (Exception e)
{
System.out.println("Invalid algorithm: " + e);
return null;
}
}

public static void main(String args[]) throws Exception


{
System.out.println("HashCode Generated by SHA-256 for:");
String s1 = "Hello ";
System.out.println(s1+ ":" + getSHA(s1));
String s2="World";
System.out.println(s2+ ":" +getSHA(s2));
String s3=s1.concat(s2);
System.out.println(s3+":"+ getSHA(s3));
}
}

Java program to demonstrate Encryption and Decryption using MD5

import java.math.BigInteger;
import java.security.MessageDigest;

public class checkMD5


{
public static String getMD5(String input)
{
try
{
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(input.getBytes());
BigInteger no = new BigInteger(1, messageDigest);
String hashtext = no.toString(16);

while (hashtext.length() < 32)


{
hashtext = "0" + hashtext;
}
return hashtext;
}

catch (Exception e)
{
System.out.println("Invalid algorithm: " + e);
return null;
}
}

public static void main(String args[]) throws Exception


{
System.out.println("HashCode Generated by MD5 for:");
String s1 = "Hello ";
System.out.println(s1+ ":" + getMD5(s1));
String s2="World";
System.out.println(s2+ ":" +getMD5(s2));
String s3=s1.concat(s2);
System.out.println(s3+":"+ getMD5(s3));
}
}

Solidity program to (i) deposit money (ii) withdraw money (iii) get balance

pragma solidity >=0.8.2 <0.9.0;


contract bank
{
int bal;

constructor() public
{
bal = 0;
}

function getbalance() view public returns(int)


{
return bal;
}

function withdraw(int amt) public


{
bal = bal - amt;
}
function deposit(int amt) public
{
bal = bal + amt;
}
}

Solidity program to implement Simple Calculator

pragma solidity >=0.8.2 <0.9.0;

contract Calculator
{
    
   function add(int a, int b) public pure returns (int)
{
     return (a+b);
   }
        function sub(int a, int b) public pure returns (int)
{
     return (a-b);
   }
        function mul(int a, int b) public pure returns (int)
{
     return (a*b);
   }
        function div(int a, int b) public pure returns (int)
{
     return (a/b);
   }
}

Solidity program to implement Stack

pragma solidity >=0.8.2 <0.9.0;

contract Stack
{
   uint[] stack;

   function push(uint data) public


{
     stack.push(data);
   }
   function pop() public view returns (uint data)
{
     data = stack[stack.length - 1];
     return data;
           }
}

Solidity program to Array Index

pragma solidity >=0.8.2 <0.9.0;

contract Array {

uint[] public arrayValue = [1, 2, 3, 4, 5, 6, 7];

function getArrayValue() public view returns (uint) {

uint x = arrayValue[5];
return x;
}

function addArrayValue() public view returns (uint) {

uint y=arrayValue[1] + arrayValue[4];


return y;
}
}

You might also like