discord test stars

About

Hashes in the Mys programming language.

Project: https://github.com/mys-lang/package-hash

Examples

SHA-1

Single buffer

The code:

from hash.sha1 import sha1

func main():
    print(sha1(b"The quick brown fox jumps over the lazy dog"))

Build and run:

 mys run
 Reading package configuration (0 seconds)
 Building (0.51 seconds)
b"\x2f\xd4\xe1\xc6\x7a\x2d\x28\xfc\xed\x84\x9e\xe1\xbb\x76\xe7\x39\x1b\x93\xeb\x12"

Multiple (or single) buffers

The code:

from hash.sha1 import Sha1

func main():
    hasher = Sha1()
    hasher.update(b"The quick brown fox jumps")
    hasher.update(b" over the lazy dog")
    print(hasher.digest())

Build and run:

 mys run
 Reading package configuration (0 seconds)
 Building (0.51 seconds)
b"\x2f\xd4\xe1\xc6\x7a\x2d\x28\xfc\xed\x84\x9e\xe1\xbb\x76\xe7\x39\x1b\x93\xeb\x12"

API

SHA-1

class Sha1:

    func __init__(self):

    func update(self, data: bytes):
        Update the hash with given data.

    func digest(self) -> bytes:
        Returns the hash.

    func reset(self):
        Reset the hasher state.
func sha1(data: bytes) -> bytes:
    Returns the hash of given data.