├── tests ├── __init__.py └── test.py ├── .gitignore ├── images ├── image.png └── test.png ├── blockhash ├── __init__.py └── mains.py ├── .travis.yml ├── setup.py ├── LICENSE ├── CONTRIBUTING.md ├── README.md └── README.rst /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *~ 3 | build/ 4 | dist/ 5 | *.egg-info/ 6 | *pyc 7 | **/*/pyc 8 | -------------------------------------------------------------------------------- /images/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spockuto/blockhash/HEAD/images/image.png -------------------------------------------------------------------------------- /images/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spockuto/blockhash/HEAD/images/test.png -------------------------------------------------------------------------------- /blockhash/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | from .mains import main 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | - "3.3" 5 | - "3.4" 6 | install: 7 | - python setup.py install 8 | - pip install future 9 | - pip install coveralls 10 | script: nosetests 11 | after_success: coveralls 12 | notifications: 13 | email: false -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | try: 2 | from setuptools import setup 3 | except ImportError: 4 | from distutils.core import setup 5 | 6 | 7 | 8 | setup(name='blockhash', 9 | description='Speed up your SHA. A different hash style', 10 | version='1.1.0', 11 | author="Venkkatesh_Sekar", 12 | author_email="venkythesupersaiyan@gmail.com", 13 | packages=['blockhash'], 14 | entry_points={ 15 | 'console_scripts': ['blockhash=blockhash:main'], 16 | }, 17 | test_suite='tests', 18 | url="https://github.com/Spockuto/blockhash", 19 | keywords=[ 'CLI', 'python'], 20 | classifiers=[ 21 | 'Operating System :: POSIX', 22 | 'Environment :: Console', 23 | 'Programming Language :: Python', 24 | 'Programming Language :: Python :: 2', 25 | 'Programming Language :: Python :: 3', 26 | 'Programming Language :: Python :: 3.2', 27 | 'Programming Language :: Python :: 3.3', 28 | 'Topic :: Utilities', 29 | 'Topic :: Software Development :: Libraries :: Python Modules', 30 | ],) 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Harsha Srinivas <95harsha95@gmail.com> (https://in.linkedin.com/in/harshasrinivas) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to py-threadpool 2 | 3 | ## Code style: 4 | * Follow [PEP8](https://www.python.org/dev/peps/pep-0008/) standards. 5 | * Name variables with underscores and lowercase letters. Not camelCase. 6 | 7 | 8 | ## Git commit messages: 9 | * Limit the first line to 72 characters or less 10 | * Reference issues and pull requests 11 | * Consider starting the commit message with an applicable emoji: 12 | * :art: `:art:` when improving the format/structure of the code 13 | * :racehorse: `:racehorse:` when improving performance 14 | * :scroll: `:scroll:` when writing docs 15 | * :penguin: `:penguin:` when fixing something on Linux 16 | * :apple: `:apple:` when fixing something on Mac OS 17 | * :checkered_flag: `:checkered_flag:` when fixing something on Windows 18 | * :bug: `:bug:` when fixing a bug 19 | * :fire: `:fire:` when removing code or files 20 | * :green_heart: `:green_heart:` when fixing the CI build 21 | * :white_check_mark: `:white_check_mark:` when adding tests 22 | * :lock: `:lock:` when dealing with security 23 | * :arrow_up: `:arrow_up:` when upgrading dependencies 24 | * :arrow_down: `:arrow_down:` when downgrading dependencies 25 | * :wrench: `:wrench:` when doing CI 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #`blockhash` 2 | [![Build Status](https://travis-ci.org/Spockuto/blockhash.svg?branch=master)](https://travis-ci.org/Spockuto/blockhash) 3 | [![Coverage Status](https://coveralls.io/repos/Spockuto/blockhash/badge.svg?branch=master&service=github)](https://coveralls.io/github/Spockuto/blockhash?branch=master) 4 | 5 | **A SHA implementations which serves normal SHA for small files and** 6 | **block based SHA for larger files which speeds up your process** 7 | 8 | 9 | ![Block Based Hashing](images/image.png) 10 | 11 | 12 | #Installation 13 | 14 | ##Using `pip` 15 | 16 | `$ pip install blockhash` 17 | 18 | ##Get the latest build from the Source 19 | 20 | * Clone the repo `git clone https://github.com/spockuto/blockhash.git` 21 | * Run `python setup.py install` 22 | 23 | ##Dependencies 24 | 25 | * future `$ pip install future` 26 | 27 | Usage 28 | ===== 29 | ```sh 30 | $ blockhash --help 31 | 32 | usage: blockhash [-h] [-1] [-2] [-3] [-4] [-5] [-f FILE] 33 | 34 | Speed up your SHA. A different hash style. 35 | 36 | optional arguments: 37 | -h, --help show this help message and exit 38 | -1, --sha1 39 | -2, --sha224 40 | -3, --sha256 41 | -4, --sha384 42 | -5, --sha512 43 | -f FILE, --file FILE The path to the file 44 | ``` 45 | 46 | #Contribute 47 | 48 | If you want to add features, improve them, or report issues, feel free to send a pull request. 49 | 50 | #Contributors 51 | 52 | * [Venkkatesh Sekar](https://github.com/Spockuto) 53 | * [Jack Serrino](https://github.com/Detry322) 54 | 55 | #License 56 | 57 | MIT © [Venkkatesh Sekar](https://in.linkedin.com/in/venkkateshsekar) 58 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | blockhash 2 | ========= 3 | .. image:: https://travis-ci.org/Spockuto/blockhash.svg?branch=master 4 | :target: https://travis-ci.org/Spockuto/blockhash 5 | 6 | .. image:: https://coveralls.io/repos/Spockuto/blockhash/badge.svg?branch=master&service=github :target: https://coveralls.io/github/Spockuto/blockhash?branch=master 7 | 8 | A SHA implementations which serves normal SHA for small files and 9 | block based SHA for larger files which speeds up your process. 10 | 11 | Installation 12 | ============ 13 | 14 | Using ``pip`` 15 | ------------- 16 | 17 | .. code:: sh 18 | 19 | $ pip install blockhash 20 | 21 | Latest build from the Source 22 | ---------------------------- 23 | 24 | - Clone the repo 25 | 26 | .. code:: sh 27 | 28 | $ git clone https://github.com/Spockuto/blockhash.git 29 | 30 | - Run 31 | 32 | .. code:: sh 33 | 34 | $ python setup.py install 35 | 36 | Usage 37 | ===== 38 | 39 | .. code:: sh 40 | 41 | blockhash --help 42 | 43 | usage: blockhash [-h] [-1] [-2] [-3] [-4] [-5] [-f FILE] 44 | 45 | Speed up your SHA. A different hash style. 46 | 47 | optional arguments: 48 | -h, --help show this help message and exit 49 | -1, --sha1 50 | -2, --sha224 51 | -3, --sha256 52 | -4, --sha384 53 | -5, --sha512 54 | -f FILE, --file FILE The path to the file 55 | 56 | Contribute 57 | ========== 58 | 59 | If you want to add features, improve them, or report issues, feel free 60 | to send a pull request. 61 | 62 | Contributors 63 | ============ 64 | 65 | - `VenkkateshSekar `__ 66 | - `Jack Serrino `__ 67 | 68 | License 69 | ======= 70 | 71 | MIT `VenkkateshSekar `__ 72 | -------------------------------------------------------------------------------- /blockhash/mains.py: -------------------------------------------------------------------------------- 1 | """set default encoding format""" 2 | from __future__ import print_function 3 | from __future__ import absolute_import 4 | from future.standard_library import install_aliases 5 | install_aliases() 6 | 7 | import sys 8 | import os 9 | import hashlib 10 | from argparse import ArgumentParser 11 | import multiprocessing 12 | from multiprocessing import Pool 13 | 20971520 14 | #Default fixed size for chunks in 20Mb based on multiple experiments 15 | def chunks(file_object, chunk_size): 16 | while True: 17 | data = file_object.read(chunk_size) 18 | if not data: 19 | break 20 | yield data + ":chunk" 21 | 22 | def hashing(piece): 23 | if args.sha1: 24 | return str(hashlib.sha1(piece).hexdigest()) 25 | elif args.sha224: 26 | return str(hashlib.sha224(piece).hexdigest()) 27 | elif args.sha256: 28 | return str(hashlib.sha256(piece).hexdigest()) 29 | elif args.sha384: 30 | return str(hashlib.sha384(piece).hexdigest()) 31 | elif args.sha512: 32 | return str(hashlib.sha512(piece).hexdigest()) 33 | else: 34 | raise ValueError('Specify a Hash function') 35 | 36 | def main(): 37 | 38 | parser = ArgumentParser(description="Speed up your SHA. A different hash style.") 39 | parser.add_argument('-1', '--sha1', action='store_true') 40 | parser.add_argument('-2', '--sha224', action='store_true') 41 | parser.add_argument('-3', '--sha256', action='store_true') 42 | parser.add_argument('-4', '--sha384', action='store_true') 43 | parser.add_argument('-5', '--sha512', action='store_true') 44 | parser.add_argument('-f', '--file', type=str, help="The path to the file") 45 | parser.add_argument('-s', '--size', type=int, help="The size of the chunks") 46 | 47 | if len(sys.argv) == 1: 48 | parser.print_help() 49 | return 50 | 51 | global args 52 | args = parser.parse_args() 53 | 54 | if not args.size: 55 | args.size = 20971520 56 | 57 | hashtree = '' 58 | 59 | big_file = open(args.file, 'rb') 60 | pool = Pool(multiprocessing.cpu_count()) 61 | 62 | for chunk_hash in pool.imap(hashing, chunks(big_file, args.size)): 63 | hashtree += chunk_hash + ":hash" 64 | pool.terminate() 65 | 66 | print(str(hashing(hashtree.encode('ascii')))) 67 | 68 | 69 | if __name__ == '__main__': 70 | main() 71 | 72 | -------------------------------------------------------------------------------- /tests/test.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | from nose.tools import eq_, ok_ 3 | 4 | def test_sha1(): 5 | function_output = subprocess.check_output("python ./blockhash/mains.py -1 --file ./images/test.png", shell=True).rstrip().decode("utf-8") 6 | desired_output = "d886954ae0593abaeb6114e9dd12651378b852c1" 7 | eq_(desired_output ,function_output) 8 | 9 | def test_sha224(): 10 | function_output = subprocess.check_output("python ./blockhash/mains.py -2 --file ./images/test.png", shell=True).rstrip().decode("utf-8") 11 | desired_output = "b45bb365f75bd71d54c726e733754752391a7cc5044d83fd4efb86a9" 12 | eq_(desired_output,function_output) 13 | 14 | def test_sha256(): 15 | function_output = subprocess.check_output("python ./blockhash/mains.py -3 --file ./images/test.png", shell=True).rstrip().decode("utf-8") 16 | desired_output = "546c14f0cf534b37cf9e0579a82ed2cf7e2a279209a5d5b5ca25c6f7ccf79790" 17 | eq_(desired_output,function_output) 18 | 19 | def test_sha384(): 20 | function_output = subprocess.check_output("python ./blockhash/mains.py -4 --file ./images/test.png", shell=True).rstrip().decode("utf-8") 21 | desired_output = "dd98db89a3068a5825da89cc5b57f761e842b304b5b5aff31cb4a2bd055f1208ab1bc2e730c91d4fa96b76a64ede8d2c" 22 | eq_(desired_output,function_output) 23 | 24 | def test_sha512(): 25 | function_output = subprocess.check_output("python ./blockhash/mains.py -5 --file ./images/test.png", shell=True).rstrip().decode("utf-8") 26 | desired_output = "61a67dc1924a0c11508539c058c5d49480d558539bfa51efaa3c3fab18ae4a9bf69dd75b1d62a6228a4b47dae9968d00791cc7b7c8e199b37bf7bf2229b9bde9" 27 | eq_(desired_output,function_output) 28 | 29 | def test_sha1_size(): 30 | function_output = subprocess.check_output("python ./blockhash/mains.py -1 --file ./images/test.png -s 1024", shell=True).rstrip().decode("utf-8") 31 | desired_output = "2f73f1ed42aaea52f6f7e17d73ed2107545658f3" 32 | eq_(desired_output ,function_output) 33 | 34 | def test_sha224_size(): 35 | function_output = subprocess.check_output("python ./blockhash/mains.py -2 --file ./images/test.png -s 1024", shell=True).rstrip().decode("utf-8") 36 | desired_output = "c5afc457d69e82fa7221ff02f00deff1e62b7287ff17a34505029fa6" 37 | eq_(desired_output,function_output) 38 | 39 | def test_sha256_size(): 40 | function_output = subprocess.check_output("python ./blockhash/mains.py -3 --file ./images/test.png -s 1024", shell=True).rstrip().decode("utf-8") 41 | desired_output = "c17a87ddc7b1e325fdb7500c8fe942279e4f6ab9c943f34ad1dc651bc808c33b" 42 | eq_(desired_output,function_output) 43 | 44 | def test_sha384_size(): 45 | function_output = subprocess.check_output("python ./blockhash/mains.py -4 --file ./images/test.png -s 1024", shell=True).rstrip().decode("utf-8") 46 | desired_output = "4454e94b31924def74a9cb4225e3a6d7823daec8d7c896fcd1f8922a83088210899989f8d20075e5687bf7f5e8d5bdd1" 47 | eq_(desired_output,function_output) 48 | 49 | def test_sha512_size(): 50 | function_output = subprocess.check_output("python ./blockhash/mains.py -5 --file ./images/test.png -s 1024", shell=True).rstrip().decode("utf-8") 51 | desired_output = "ecda9fddee6d6e68791f95c897729c0f039e47d0712c06fdf381b07d3dfcbb13bc569e8df5a24ba2a5b67485374bd9fa7fad61feb5adef5f7d7ce7edd85eb9b1" 52 | eq_(desired_output,function_output) --------------------------------------------------------------------------------