<commit_before>package main

import (
    "bufio"
    "crypto/sha256"
    "fmt"
    "os"
)

func main() {
    reader := bufio.NewReader(os.Stdin)

    buf := make([]byte, 1024)
    digest := sha256.New()

    for {
        len, err := reader.Read(buf)
        if len == 0 {
            break;
        }
        if err != nil {
			fmt.Fprintf(os.Stderr, "read error: %v\n", err)
			os.Exit(1)
        }
        digest.Write(buf[:len])
    }
    fmt.Printf("%x\n", digest.Sum(nil))
}
<commit_msg>Modified ch04/p02_sha256.<commit_after>package main

import (
    "bufio"
    "crypto/sha256"
    "crypto/sha512"
    "flag"
    "fmt"
    "hash"
    "os"
)

func main() {
    var length int

    flag.IntVar(&length, "l", 256, "specify the length of sha. 256, 384, 512")
    flag.Parse()

    var digest hash.Hash

    if length == 256 {
        digest = sha256.New()
    } else if length == 384 {
        digest = sha512.New384()
    } else if length == 512 {
        digest = sha512.New()
    } else {
        fmt.Fprintf(os.Stderr, "Unrecognized algorithm: %d\n", length)
        flag.PrintDefaults()
        os.Exit(1)
    }

    reader := bufio.NewReader(os.Stdin)
    buf := make([]byte, 1024)

    for {
        len, err := reader.Read(buf)
        if len == 0 {
            break;
        }
        if err != nil {
			fmt.Fprintf(os.Stderr, "read error: %v\n", err)
			os.Exit(1)
        }
        digest.Write(buf[:len])
    }
    fmt.Printf("%x\n", digest.Sum(nil))
}

{'fraction_non_alphanumeric': 0.15828804347826086, 'fraction_numerical': 0.044157608695652176, 'mean_word_length': 1.8436293436293436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '941824', 'n_tokens_mistral': 598, 'n_tokens_neox': 531, 'n_words': 117}