├── README.md └── SHA Cryptography.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # SHA-Algorithms-Blockchain -------------------------------------------------------------------------------- /SHA Cryptography.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "fifth-carol", 6 | "metadata": {}, 7 | "source": [ 8 | "### SHA, ( Secure Hash Algorithms )- Base Of BlockChain" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "golden-basket", 14 | "metadata": {}, 15 | "source": [ 16 | "- SHA256 : This hash function belong to hash class SHA-2, the internal block size of it is 32 bits.\n", 17 | "- SHA384 : This hash function belong to hash class SHA-2, the internal block size of it is 32 bits. This is one of the truncated version.\n", 18 | "- SHA224 : This hash function belong to hash class SHA-2, the internal block size of it is 32 bits. This is one of the truncated version.\n", 19 | "- SHA512 : This hash function belong to hash class SHA-2, the internal block size of it is 64 bits.\n", 20 | "- SHA1 : The 160 bit hash function that resembles MD5 hash in working and was discontinued to be used seeing its security vulnerabilities." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 1, 26 | "id": "mature-desire", 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "import hashlib" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "id": "corresponding-annotation", 36 | "metadata": {}, 37 | "source": [ 38 | "### SHA256" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 13, 44 | "id": "sought-perfume", 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "name": "stdout", 49 | "output_type": "stream", 50 | "text": [ 51 | "\n" 52 | ] 53 | } 54 | ], 55 | "source": [ 56 | "str1=\"Krish Naik1\"\n", 57 | "### Process of Hashing\n", 58 | "### First step is to encode\n", 59 | "### Then Apply hashing Algorithms\n", 60 | "hashedval = hashlib.sha256(str1.encode()) \n", 61 | "print(hashedval)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 14, 67 | "id": "pacific-beaver", 68 | "metadata": {}, 69 | "outputs": [ 70 | { 71 | "data": { 72 | "text/plain": [ 73 | "'f05951c931847852c55a683e04018ae1a16d9307391b88898bae706f589e8fb9'" 74 | ] 75 | }, 76 | "execution_count": 14, 77 | "metadata": {}, 78 | "output_type": "execute_result" 79 | } 80 | ], 81 | "source": [ 82 | "###convert this value to hexadecimal\n", 83 | "hashedval.hexdigest()" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "id": "first-butter", 89 | "metadata": {}, 90 | "source": [ 91 | "### SHA384" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 16, 97 | "id": "express-looking", 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "data": { 102 | "text/plain": [ 103 | "'d8dfdd25d4b3e428a2af3b5ec773e2ac26d6b3086c422b633cadf1b08699897bddf5d848fb26e739012d694f4d38b245'" 104 | ] 105 | }, 106 | "execution_count": 16, 107 | "metadata": {}, 108 | "output_type": "execute_result" 109 | } 110 | ], 111 | "source": [ 112 | "hashedval=hashlib.sha384(str1.encode()) \n", 113 | "hashedval.hexdigest()" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "id": "comic-afghanistan", 119 | "metadata": {}, 120 | "source": [ 121 | "### SHA224" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 17, 127 | "id": "simple-campbell", 128 | "metadata": {}, 129 | "outputs": [ 130 | { 131 | "data": { 132 | "text/plain": [ 133 | "'7f0092838d56259557a4189398992ab151dbe60934366665dd88287e'" 134 | ] 135 | }, 136 | "execution_count": 17, 137 | "metadata": {}, 138 | "output_type": "execute_result" 139 | } 140 | ], 141 | "source": [ 142 | "hashedval=hashlib.sha224(str1.encode()) \n", 143 | "hashedval.hexdigest()" 144 | ] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "id": "conventional-vector", 149 | "metadata": {}, 150 | "source": [ 151 | "### SHA512" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 18, 157 | "id": "noted-channels", 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "data": { 162 | "text/plain": [ 163 | "'12ac8c737a635bf446090d2b1197bcac06066c997a2c9cbeab9cc8a4357a58fd1fd0e53f853c9ff199ee777b2eada917796b3e2352c97216309e853c3c81567e'" 164 | ] 165 | }, 166 | "execution_count": 18, 167 | "metadata": {}, 168 | "output_type": "execute_result" 169 | } 170 | ], 171 | "source": [ 172 | "hashedval=hashlib.sha512(str1.encode()) \n", 173 | "hashedval.hexdigest()" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 19, 179 | "id": "secondary-witness", 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "data": { 184 | "text/plain": [ 185 | "'7904cce5c2f62f0bd6fbe72f768c4b96f9f8449b'" 186 | ] 187 | }, 188 | "execution_count": 19, 189 | "metadata": {}, 190 | "output_type": "execute_result" 191 | } 192 | ], 193 | "source": [ 194 | "hashedval=hashlib.sha1(str1.encode()) \n", 195 | "hashedval.hexdigest()" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": null, 201 | "id": "destroyed-relationship", 202 | "metadata": {}, 203 | "outputs": [], 204 | "source": [] 205 | } 206 | ], 207 | "metadata": { 208 | "kernelspec": { 209 | "display_name": "Python 3", 210 | "language": "python", 211 | "name": "python3" 212 | }, 213 | "language_info": { 214 | "codemirror_mode": { 215 | "name": "ipython", 216 | "version": 3 217 | }, 218 | "file_extension": ".py", 219 | "mimetype": "text/x-python", 220 | "name": "python", 221 | "nbconvert_exporter": "python", 222 | "pygments_lexer": "ipython3", 223 | "version": "3.8.5" 224 | } 225 | }, 226 | "nbformat": 4, 227 | "nbformat_minor": 5 228 | } 229 | --------------------------------------------------------------------------------