Giter Site home page Giter Site logo

thomdixon / pysha2 Goto Github PK

View Code? Open in Web Editor NEW
55.0 6.0 28.0 16 KB

Pure Python implementation of SHA2 (i.e., SHA224, SHA256, SHA384, and SHA512).

License: MIT License

Python 100.00%
sha256 sha2 python sha512 cryptography-library crypto cryptography mit-license

pysha2's Introduction

image

pysha2

License

This software is distributed under the MIT License.

About

pysha2 is a pure Python implementation of the FIPS 180-2 secure hash standard. I originally wrote and published this on the web prior to the inclusion of hashlib into the Python standard library. Unfortunately, the original source was lost due to a hard drive failure. Fortunately, the library proved useful to some at the time (due to the prevalence of Python 2.3 and 2.4), and so I was able to recover all but the unit tests (which I later rewrote).

Usage

The library supports both the "old" hash interface of md5 and sha, as well as the "new" hash interface introduced by hashlib. This permits you to use pysha2 as a drop-in replacement for either interface.

A quick example of hashing a string:

import sha2

print sha2.sha256('Can you keep a secret?').hexdigest()

Testing

To run the included unit tests, execute:

python test.py

in the current directory or run with nosetests.

pysha2's People

Contributors

connorskees avatar mistydemeo avatar nickodell avatar thomdixon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pysha2's Issues

Missing something?

Hello,
I used your code to hash the variable a
a= "00baf6626abc2df808da36a518c69f09b0d2ed0a79421ccfde4f559d2e42128" {#b"# CHAINS SHORTER at 2128_ }
and it gives the correct value (compared to hashlib),
but if I try to hash
a= "00baf6626abc2df808da36a518c69f09b0d2ed0a79421ccfde4f559d2e42128b" it provides a wrong hash value, got lost on the code so I thought I'd better ask you.
I am intending to use your code two 64 char concatenated variables.

Thanks a lot for your comments.

Typeerror issue on SHA256

sha256 type error
in this function a Typeerror is raised if m in not string BUT:

def update(self, m):
        if not m:
            return
        if type(m) is not str:
            raise TypeError, '%s() argument 1 must be string, not %s' % (sys._getframe().f_code.co_name, type(m).__name__)

In here you call the update function with bytes. therefore causing function to raise error

def digest(self):
        mdi = self._counter & 0x3F
        length = struct.pack('!Q', self._counter<<3)
        
        if mdi < 56:
            padlen = 55-mdi
        else:
            padlen = 119-mdi
        
        r = self.copy()
        r.update('\x80'+('\x00'*padlen)+length)
        return ''.join([struct.pack('!L', i) for i in r._h[:self._output_size]])

is it possible to backwards-hash(sha256) a known-size reversed input from a given hash?

Hi. You wrote the sha256 implementation in this repository which makes me assume that you know how it works (unlike me) and I was wondering if you could answer with YES/NO this question which I'll reiterate here:

Is possible to start from a hash and work backwards through the sha256 algorithm using the same input (but reversed, from the last byte to the first) and get to the same initial hash (which is the hash of empty input, or a 0 bytes file) ?

For example:
I have the input Hello World! which (sha256)hashes to 7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069
then can I use that very hash to go backwards via a reversed_sha256 algorithm(if it even can be reversed like that!) and coupled with the reversed input (!dlroW olleH) to get to the hash of the empty input which is e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ?

Thank you in advance for any reply, even if it's you don't know. It's much appreciated either way!
All the best to you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.