Solidity-023 CryptoFunctions

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

contract CryptoFunctions {

   

    // cryptoDemo function: Demonstrates the use of two cryptographic hash functions - SHA-256 and Keccak256.

    // It takes no inputs and returns two hash values, one for each hash function, both generated from the same string "r".

    function cryptoDemo() public pure returns (bytes32, bytes32){

        // SHA-256 hash function applied to the string "r"

        bytes32 sha256Hash = sha256("r");

       

        // Keccak256 hash function (the same hashing algorithm used by Ethereum) applied to the string "r"

        bytes32 keccak256Hash = keccak256("r");

        // Returning both hashes

        return (sha256Hash, keccak256Hash);

    }

   

    // ripemd160Hash function: Computes the RIPEMD-160 hash of a given input string.

    // This function takes a string as input and returns its RIPEMD-160 hash.

    function ripemd160Hash(string memory _input) public pure returns (bytes20) {

        // Encoding the string to bytes and applying the RIPEMD-160 hash function

        return ripemd160(abi.encodePacked(_input));

    }

    // concatenateStrings function: Concatenates two input strings into one.

    // This function takes two strings as inputs and returns their concatenation.

    function concatenateStrings(string memory _str1, string memory _str2) public pure returns (string memory) {

        // Using abi.encodePacked to efficiently concatenate the strings and then converting the result back to a string

        return string(abi.encodePacked(_str1, _str2));

    }

}

//Deploy screenshot: