<\/span><\/h2>\n\n\n\nCryptographic hash functions are mathematical operations run on digital data; by comparing the computed hash (i.e., the output produced by executing a hashing algorithm) to a known and expected hash value, a person can determine the data’s integrity. For example, computing the hash of a downloaded file and comparing the result to a previously published hash result can show whether the download has been modified or tampered with. In addition, cryptographic hash functions are extremely collision-resistant; in other words, it should be extremely difficult to produce the same hash output from two different input values using a cryptographic hash function.<\/p>\n\n\n\n
Secure Hash Algorithm 2 (SHA-2) is a set of cryptographic hash functions designed by the National Security Agency (NSA). It consists of six identical hashing algorithms (i.e., SHA-256, SHA-512, SHA-224, SHA-384, SHA-512\/224, SHA-512\/256) with a variable digest size. SHA-256 is a 256<\/strong>-bit ( 32 <\/strong>byte) hashing algorithm which can calculate a hash code for an input of up to 264 – 1 <\/strong>bits. It undergoes 64 <\/strong>rounds of hashing and calculates a hash code that is a 64<\/strong>-digit hexadecimal number. Given a string, s<\/strong>, print its SHA-256 hash value.<\/p>\n\n\n\n<\/span>Input Format<\/strong><\/span><\/h2>\n\n\n\nA single alphanumeric string denoting s<\/strong>.<\/p>\n\n\n\n<\/span>Constraints<\/strong><\/span><\/h4>\n\n\n\n- 6 <= |s| <= 20<\/strong><\/li>
- String s <\/strong>consists of English alphabetic letters (i.e.,[a-z A-Z]<\/strong> and\/or decimal digits (i.e.,0<\/strong> through 9<\/strong>) only.<\/li><\/ul>\n\n\n\n
<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nPrint the SHA-256 encryption value of s <\/strong>on a new line.<\/p>\n\n\n\n<\/span>Sample Input 0<\/strong><\/span><\/h4>\n\n\n\n HelloWorld<\/code><\/pre>\n\n\n\n<\/span>Sample Output 0<\/strong><\/span><\/h4>\n\n\n\n 68e109f0f40ca72a15e05cc22786f8e6<\/code><\/pre>\n\n\n\n<\/span>Sample Input 1<\/strong><\/span><\/h4>\n\n\n\n Javarmi123<\/code><\/pre>\n\n\n\n<\/span>Sample Output 1<\/strong><\/span><\/h4>\n\n\n\n 2da2d1e0ce7b4951a858ed2d547ef485<\/code><\/pre>\n\n\n\n<\/span>Solution – Java SHA-256<\/strong><\/span><\/h2>\n\n\n\nimport java.util.*;\nimport java.security.*;\n\npublic class Solution {\n\n public static void main(String[] args) throws NoSuchAlgorithmException {\n Scanner input = new Scanner(System.in);\n MessageDigest m = MessageDigest.getInstance(\"SHA-256\");\n m.reset();\n m.update(input.nextLine().getBytes());\n for (byte i : m.digest()) {\n System.out.print(String.format(\"%02x\", i));\n }\n System.out.println();\n }\n}<\/pre>\n\n\n\n