<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Преобразование текста в хэш]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=17608&amp;type=atom" />
	<updated>2023-02-15T18:32:20Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=17608</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование текста в хэш]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=156822#p156822" />
			<content type="html"><![CDATA[<p>Хешируется не строка, а данные (байты). Строку можно по-разному представить в виде байтов, в зависимости от кодировки. Результирующий хеш представлен не в виде какого-то количества знаков, а количества байтов, которое хеш занимает.<br />Пример простого хеширования:<br /></p><div class="codebox"><pre><code>string := &quot;Hello, World!&quot;
len := StrPutBuff(string, buf)
MsgBox % hashCode(&amp;buf, len, 4)

hashCode(pData, dataLength, hashLength := 4) {
   size := 0
   Loop % hashLength
      size |= 0xFF &lt;&lt; 8*(A_Index - 1)
   hash := 0
   Loop % dataLength
      hash := (31 * hash + *(pData + A_Index - 1)) &amp; size
   Return hash
}

StrPutBuff(str, ByRef buff, encoding := &quot;UTF-8&quot;) {
	VarSetCapacity(buff, len := (StrPut(str, encoding) - 1) &lt;&lt; (encoding ~= &quot;i)^(UTF-16|cp1200)$&quot;))
	StrPut(str, &amp;buff, encoding)
	Return len
}</code></pre></div><p>Здесь хеш занимает 4 байта (последний параметр функции hashCode(). Можно его уменьшить, но с потерей уникальности.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-02-15T18:32:20Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=156822#p156822</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Преобразование текста в хэш]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=156820#p156820" />
			<content type="html"><![CDATA[<p>Добрый вечер. Возможно ли по какому-то алгоритму представить определенный текст/ссылку в виде четырехзначного кода/хеш-суммы?</p>]]></content>
			<author>
				<name><![CDATA[john_dease]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=42972</uri>
			</author>
			<updated>2023-02-15T17:29:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=156820#p156820</id>
		</entry>
</feed>
