Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hash Validator Library

This project aims to check hash values from files using sha256 and compare them between tow given files or between many files and a respective hash value for each one.
62 changes: 34 additions & 28 deletions hash_validator/libreria hash.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,20 @@
},
{
"cell_type": "code",
"execution_count": 194,
"execution_count": 18,
"id": "aec0dd78",
"metadata": {},
"outputs": [],
"source": [
"def check_hash(files:list or str, # revisar\n",
" hash_val:list or str=None):\n",
" \"\"\"\n",
" Check hash values from files usinig sha256 and compare with hash_val, comparison is by position\n",
" Check hash values from files using sha256 and compare with hash_val, where comparison\n",
" is by position, or between two given files.\n",
" \n",
" Param:\n",
" files:list, files' path list\n",
" hash_val: list hases' val list\n",
" between: bool, if it's true the list of files will compare its own hash values\n",
" \n",
" \n",
" files: list or str, files' path list.\n",
" hash_val: list or str, hashes' values list.\n",
" \"\"\"\n",
" \n",
" # DONE: validate len in two list --> DONE\n",
Expand Down Expand Up @@ -77,7 +75,7 @@
" 'ok':[],\n",
" 'not_ok':[] \n",
" }\n",
" for file, val in tuple(zip(files, hash_val)):\n",
" for file, val in zip(files, hash_val):\n",
" tmp_hash = sha256sum(file)\n",
" if tmp_hash == val:\n",
" dict_result['ok'].append(file)\n",
Expand All @@ -87,11 +85,11 @@
" if dict_result['not_ok']:\n",
" print(\"Check the files, the hash aren't the same:{} \".format(','.join(dict_result['not_ok'])))\n",
" else:\n",
" print('Congratulations, hash are the same!! Continue working slave.')\n",
" print('Congratulations, hash are the same!! Continue working, slave.')\n",
"\n",
" else:\n",
" if len_files < 2: #--> Use case 2\n",
" raise Exception(\"List of files must have at least two files if hashes are not provided.\")\n",
" if len_files != 2: #--> Use case 2\n",
" raise Exception(\"List of files must have two files if hashes are not provided.\")\n",
"\n",
" hash_list = []\n",
" for e in files:\n",
Expand All @@ -103,7 +101,7 @@
},
{
"cell_type": "code",
"execution_count": 195,
"execution_count": 19,
"id": "a981fa48",
"metadata": {},
"outputs": [],
Expand All @@ -115,15 +113,15 @@
" ]\n",
"\n",
"hash_val = [\n",
" #'9ef7a2f47e2871adef6616556f1499bbd2702748e371104a63df4246a7232136',\n",
" # '38a0539db6a864881d9fa8a60157e713fd8b63924cea9d83a83f12b9a3a50893',\n",
" '9ef7a2f47e2871adef6616556f1499bbd2702748e371104a63df4246a7232136',\n",
" '38a0539db6a864881d9fa8a60157e713fd8b63924cea9d83a83f12b9a3a50893',\n",
" # 'e1f148287023fe1e7a7d6087e543a11fb49e551cead6d78e1c2a7f25235b940e'\n",
" ]"
]
},
{
"cell_type": "code",
"execution_count": 196,
"execution_count": 20,
"id": "fdfb7435",
"metadata": {},
"outputs": [],
Expand All @@ -133,15 +131,20 @@
},
{
"cell_type": "code",
"execution_count": 197,
"execution_count": 21,
"id": "d36a1f2a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Check the files, the hash aren't the same:../data/experimental/weather_zipcodes.csv,../data/experimental/weather_zipcodes.csv \n"
"ename": "Exception",
"evalue": "Lists don't have the same length.",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mException\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-21-3235da39549f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcheck_hash\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfiles\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhash_val\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m<ipython-input-18-f537ef321a40>\u001b[0m in \u001b[0;36mcheck_hash\u001b[0;34m(files, hash_val)\u001b[0m\n\u001b[1;32m 27\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"List of files is empty.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 28\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mlen_files\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mlen_hash\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mlen_hash\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# --> Use case 3\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 29\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Lists don't have the same length.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 30\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 31\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mException\u001b[0m: Lists don't have the same length."
]
}
],
Expand All @@ -151,24 +154,24 @@
},
{
"cell_type": "code",
"execution_count": 180,
"execution_count": 22,
"id": "4f2b3fae",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('../data/New_Launches_data_test.csv',\n",
" 'd429dfcbd43d91efd7750b09c0c4256dc2fd52713b2bae11a3f036566cb854a1')]"
"[('../../data/sumbission_3.csv',\n",
" '9ef7a2f47e2871adef6616556f1499bbd2702748e371104a63df4246a7232136')]"
]
},
"execution_count": 180,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(zip([files], hash_val))"
"list(zip(files, hash_val))"
]
},
{
Expand All @@ -183,10 +186,13 @@
}
],
"metadata": {
"interpreter": {
"hash": "d15529d9e209a94a09f89984c36a77e2b2b9cb2246b958fadf2bff8346058dd5"
},
"kernelspec": {
"display_name": "Python 3.8.3 64-bit ('topo-chico': conda)",
"display_name": "Python 3.9.2 ('ncr_demo-env')",
"language": "python",
"name": "python383jvsc74a57bd048e877130e9be6e1bedc758079db27feb71a89f1334abb10d9b69c71793f0615"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -198,7 +204,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.9.2"
},
"toc": {
"base_numbering": 1,
Expand Down