Skip to content

Instantly share code, notes, and snippets.

@rain-1
Created March 18, 2019 23:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rain-1/2aedd55ca3317079198c7b5bf2af9fd5 to your computer and use it in GitHub Desktop.
Save rain-1/2aedd55ca3317079198c7b5bf2af9fd5 to your computer and use it in GitHub Desktop.
checksum colorizer
package main
import (
"bufio"
"fmt"
"os"
"log"
"regexp"
)
func repl1(hex []byte) []byte {
return []byte(fmt.Sprintf("\x1B[38;5;%dm%c%c\x1B[0m", hex[0] + 0x10*hex[1], hex[0], hex[1]))
}
func repl(line []byte) []byte {
hexet, _ := regexp.Compile("[0-9a-fA-F][0-9a-fA-F]")
return hexet.ReplaceAllFunc(line, repl1)
}
func main() {
hexets, _ := regexp.Compile("([^0-9a-zA-Z]|^|0x)([0-9a-fA-F][0-9a-fA-F])+([^0-9a-zA-Z]|$)")
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Bytes()
line = hexets.ReplaceAllFunc(line, repl)
fmt.Println(string(line))
}
if err := scanner.Err(); err != nil {
log.Println(err)
}
}
@rain-1
Copy link
Author

rain-1 commented Mar 18, 2019

go build then ; sha256sum * | ./foo. colors the hashes for easy comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment