<commit_before>package mysql

import (
	"crypto/sha1"
)

// formula :
// SHA1(password) XOR SHA1("20-byte public seed from server" <concat> SHA1( SHA1( password)))

func scramble41(password string, seed []byte) [20]byte {
	var final [sha1.Size]byte

	h1 := sha1.New()
	h1.Write([]byte(password))
	hashStage1 := h1.Sum(nil)

	h2 := sha1.New()
	h2.Write(hashStage1)
	hashStage2 := h2.Sum(nil)

	h := sha1.New()
	h.Write(seed)
	tmp := h.Sum(hashStage2)

	for i := 0; i < sha1.Size; i++ {
		final[i] = hashStage1[i] ^ tmp[i]
	}

	return final
}<commit_msg>Fixed the password scramble function.<commit_after>package mysql

import (
	"crypto/sha1"
)

// formula :
// SHA1(password) XOR SHA1("20-byte public seed from server" <concat> SHA1( SHA1( password)))

func scramble41(password string, seed []byte) (buf []byte) {
	if len(password) == 0 {
		return
	}

	hash := sha1.New()

	// stage 1: SHA1(password)
	hash.Write([]byte(password))
	hashStage1 := hash.Sum(nil)

	// stage 2: SHA1(SHA1(password))
	hash.Reset()
	hash.Write(hashStage1)
	hashStage2 := hash.Sum(nil)

	// SHA1("20-byte public seed from server" <concat> SHA1(SHA1(password)))
	hash.Reset()
	hash.Write(seed)
	hash.Write(hashStage2)
	buf = hash.Sum(nil)

	for i := 0; i < sha1.Size; i++ {
		buf[i] ^= hashStage1[i]
	}

	return
}
{'fraction_non_alphanumeric': 0.17468944099378883, 'fraction_numerical': 0.043478260869565216, 'mean_word_length': 4.03515625, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, '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': '5786228', 'n_tokens_mistral': 543, 'n_tokens_neox': 513, 'n_words': 118}