<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK v2: Функция перевода из hex в text]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=18470</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=18470&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK v2: Функция перевода из hex в text».]]></description>
		<lastBuildDate>Fri, 01 Aug 2025 18:46:33 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162617#p162617</link>
			<description><![CDATA[<p><strong>bubblegum</strong>, тут зависит от длины текста.<br />Короткие фразы быстрее через str2hex.<br />Можете написать код для конвертации, например на c++, скомпилировать его и вызывать на ахк.<br /><a href="https://www.autohotkey.com/boards/viewtopic.php?t=32">https://www.autohotkey.com/boards/viewtopic.php?t=32</a></p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Fri, 01 Aug 2025 18:46:33 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162617#p162617</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162616#p162616</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, да, получается, что cript быстрее format работает в 2 раза! Впрочем, универсальность лучше, как Вы уже написали. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (bubblegum)]]></author>
			<pubDate>Fri, 01 Aug 2025 13:53:25 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162616#p162616</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162615#p162615</link>
			<description><![CDATA[<p>Кроме того, тест не совсем корректный. Он в каждой итерации загружает библиотеку crypt32.dll. Надо так:<br /></p><div class="codebox"><pre><code>#Requires AutoHotkey v1

SetBatchLines -1
hLib := DllCall(&quot;LoadLibrary&quot;, &quot;str&quot;, &quot;crypt32.dll&quot;, &quot;ptr&quot;)
text := &quot;The quick brown fox jumps over the lazy dog&quot;
start := A_TickCount
loop 1000
	str2hex(text)
result .= &quot;Format:`t&quot; A_TickCount - start &quot;ms`n&quot;
start := A_TickCount
loop 1000
	crypt_str2hex(text)
result .= &quot;Crypt:`t&quot; A_TickCount - start &quot;ms`n&quot;
msgbox % result


crypt_str2hex(string)
{
    VarSetCapacity(bin, StrPut(string, &quot;UTF-8&quot;)) &amp;&amp; len := StrPut(string, &amp;bin, &quot;UTF-8&quot;) - 1 
    if !(DllCall(&quot;crypt32\CryptBinaryToString&quot;, &quot;ptr&quot;, &amp;bin, &quot;uint&quot;, len, &quot;uint&quot;, 0x4, &quot;ptr&quot;, 0, &quot;uint*&quot;, size))
        throw Exception(&quot;CryptBinaryToString failed&quot;, -1)
    VarSetCapacity(buf, size &lt;&lt; 1, 0)
    if !(DllCall(&quot;crypt32\CryptBinaryToString&quot;, &quot;ptr&quot;, &amp;bin, &quot;uint&quot;, len, &quot;uint&quot;, 0x4, &quot;ptr&quot;, &amp;buf, &quot;uint*&quot;, size))
        throw Exception(&quot;CryptBinaryToString failed&quot;, -1)
    return StrGet(&amp;buf)
}

str2hex(str)
{
	loop, parse, str
		hex .= Format(&quot;{:x}&quot;, Asc(A_LoopField))
	return hex
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 01 Aug 2025 13:49:57 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162615#p162615</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162614#p162614</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, согласен. Потому и попросил другой пример с вызовом dll из text в hex. Ваши варианты лучше моих. Еще раз спасибо.</p>]]></description>
			<author><![CDATA[null@example.com (bubblegum)]]></author>
			<pubDate>Fri, 01 Aug 2025 13:41:00 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162614#p162614</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162613#p162613</link>
			<description><![CDATA[<div class="quotebox"><cite>bubblegum пишет:</cite><blockquote><p>скрипт для теста скорости</p></blockquote></div><p>Ну, иногда универсальность важнее скорости.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 01 Aug 2025 13:38:42 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162613#p162613</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162612#p162612</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, нужна именно конвертация без записи в реестр. Спасибо, все работает <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (bubblegum)]]></author>
			<pubDate>Fri, 01 Aug 2025 13:38:14 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162612#p162612</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162611#p162611</link>
			<description><![CDATA[<p>Но именно для записи в реестр можно просто так:<br /></p><div class="codebox"><pre><code>text := &#039;Первая строка`nВторая строка`nТретья строка&#039;
RegWrite text, &#039;REG_MULTI_SZ&#039;, &#039;HKCU\Software\MyApp&#039;, &#039;MyValue&#039;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 01 Aug 2025 13:36:14 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162611#p162611</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162610#p162610</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, спасибо за эту функцию!</p>]]></description>
			<author><![CDATA[null@example.com (bubblegum)]]></author>
			<pubDate>Fri, 01 Aug 2025 13:34:29 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162610#p162610</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162609#p162609</link>
			<description><![CDATA[<p><strong>teadrinker</strong> Нашел скрипт для теста скорости выполнения конвертации с вызовом dll и без, только для ahk v1</p><div class="codebox"><pre><code>
#Requires AutoHotkey v1

SetBatchLines -1
text := &quot;The quick brown fox jumps over the lazy dog&quot;
start := A_TickCount
loop 1000
	str2hex(text)
result .= &quot;Format:`t&quot; A_TickCount - start &quot;ms`n&quot;
start := A_TickCount
loop 1000
	crypt_str2hex(text)
result .= &quot;Crypt:`t&quot; A_TickCount - start &quot;ms`n&quot;
msgbox % result 
; Format:	47ms
; Crypt:	3375ms


crypt_str2hex(string)
{
    VarSetCapacity(bin, StrPut(string, &quot;UTF-8&quot;)) &amp;&amp; len := StrPut(string, &amp;bin, &quot;UTF-8&quot;) - 1 
    if !(DllCall(&quot;crypt32\CryptBinaryToString&quot;, &quot;ptr&quot;, &amp;bin, &quot;uint&quot;, len, &quot;uint&quot;, 0x4, &quot;ptr&quot;, 0, &quot;uint*&quot;, size))
        throw Exception(&quot;CryptBinaryToString failed&quot;, -1)
    VarSetCapacity(buf, size &lt;&lt; 1, 0)
    if !(DllCall(&quot;crypt32\CryptBinaryToString&quot;, &quot;ptr&quot;, &amp;bin, &quot;uint&quot;, len, &quot;uint&quot;, 0x4, &quot;ptr&quot;, &amp;buf, &quot;uint*&quot;, size))
        throw Exception(&quot;CryptBinaryToString failed&quot;, -1)
    return StrGet(&amp;buf)
}

str2hex(str)
{
	loop, parse, str
		hex .= Format(&quot;{:x}&quot;, Asc(A_LoopField))
	return hex
}

</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (bubblegum)]]></author>
			<pubDate>Fri, 01 Aug 2025 13:32:09 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162609#p162609</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162608#p162608</link>
			<description><![CDATA[<p>Скорее всего так:<br /></p><div class="codebox"><pre><code>#Requires AutoHotkey v2

text := &#039;
(
Первая строка
Вторая строка
Третья строка
)&#039;

MsgBox TextToREG_MULTI_SZ(text)

TextToREG_MULTI_SZ(text, delimiter := &#039;`n&#039;, omit := &#039;`r&#039;) {
    lines := StrSplit(text, delimiter, omit)
    total := 2
    for line in lines {
        total += StrPut(line, &#039;UTF-16&#039;)
    }
    buf := Buffer(total, 0), offset := 0
    for line in lines {
        offset += StrPut(line, buf.Ptr + offset, &#039;UTF-16&#039;)
    }
    return CryptBinaryToString(buf,, &#039;CRYPT_STRING_HEXRAW&#039;)
}


CryptBinaryToString(data, size?, formatName := &#039;CRYPT_STRING_BASE64&#039;, NOCRLF := true)
{
    static formats := { CRYPT_STRING_BASE64: 0x1,
                        CRYPT_STRING_HEX:    0x4,
                        CRYPT_STRING_HEXRAW: 0xC }
         , CRYPT_STRING_NOCRLF := 0x40000000

    sz := size ?? data.size
    fmt := formats.%formatName% | (NOCRLF ? CRYPT_STRING_NOCRLF : 0)
    if !DllCall(&#039;Crypt32\CryptBinaryToString&#039;, &#039;Ptr&#039;, data, &#039;UInt&#039;, sz, &#039;UInt&#039;, fmt, &#039;Ptr&#039;, 0, &#039;UIntP&#039;, &amp;chars := 0)
        throw OSError()
    VarSetStrCapacity(&amp;outString, chars)
    DllCall(&#039;Crypt32\CryptBinaryToString&#039;, &#039;Ptr&#039;, data, &#039;UInt&#039;, sz, &#039;UInt&#039;, fmt, &#039;Str&#039;, outString, &#039;UIntP&#039;, &amp;chars)
    return outString
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 01 Aug 2025 13:29:19 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162608#p162608</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162607#p162607</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, ок, а как сделать подобную функцию с вызовом dll для перевода text to hex реестра windows? Я сделал подобие первой. Может будет лучше Ваш вариант? Только надо учитывать перевод новой строки в REG_MULTI_SZ Видимо, тоже нужно будет использовать RegExReplace?</p>]]></description>
			<author><![CDATA[null@example.com (bubblegum)]]></author>
			<pubDate>Fri, 01 Aug 2025 12:32:25 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162607#p162607</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162606#p162606</link>
			<description><![CDATA[<div class="quotebox"><cite>bubblegum пишет:</cite><blockquote><p>Она считывает данные из Edit</p></blockquote></div><p>В любом случае это не очень хорошая идея. Функция должна делать только то, для чего предназначена, в данном случае перекодировать HEX в текст. Ваша не будет работать, если отсутствует объект DataIn со свойством Value. Лучше считывать текст до вызова функции и передавать его параметром, полученный текст возвращать через return. Ещё вы не учитываете, что текст может быть в разных кодировках.<br />Что по скорости — не знаю, можно сравнить, если сделаете со входящим параметром и выводом. Но способ, который я привёл, это классический способ работы с HEX и base64, в любом серьёзном скрипте увидите именно такой вариант.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 01 Aug 2025 12:25:20 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162606#p162606</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162605#p162605</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, спасибо за ответ - отлично работает! Давно не заходил на сайт и только заметил ответ. Говорят, вызов dll работает медленнее. Я уже сделал эту функцию немного по другому, без вызова dll - тоже работает с кириллицей. Она считывает данные из одного Edit DataIn и отправляет в другой Edit DataOut.</p><div class="codebox"><pre><code>
#Requires AutoHotkey v2

getTxt(){
	strHex := DataIn.Value
	strHex := RegExReplace(strHex, &#039;,00(,00){4}$&#039;, &#039;,00&#039;) ; удалить заключительный блок ,00,00,00,00,00 из REG_MULTI_SZ, чтобы не замещался на \n
	strHex := RegExReplace(strHex, &#039;,00(,00){2}$&#039;, &#039;,00&#039;) ; удалить заключительный блок ,00,00,00 из REG_EXPAND_SZ за ненадобностью
	strHex := RegExReplace(strHex, &#039;im),00,00,00,&#039;, &#039;,00,0A,00,&#039;) ; символ перевода новой строки 00,00,00, (встречается только между строк в REG_MULTI_SZ) заменить на реальный \n = 0a,00
	strHex := RegExReplace(strHex, &#039;i)[^\da-f]&#039;) ; удалить запятые, пробелы и &quot;\&quot;
	Txt := &#039;&#039;
	hexLen := StrLen(strHex)
	Loop (hexLen /4){
		LowByteHex := SubStr(strHex, (A_Index -1) *4 +1, 2) 
		HighByteHex := SubStr(strHex, (A_Index -1) *4 +3, 2)
		CodePointHex := HighByteHex . LowByteHex 
		Txt .= Chr(&#039;0x&#039; CodePointHex)
		}
	DataOut.Value := Txt
}
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (bubblegum)]]></author>
			<pubDate>Fri, 01 Aug 2025 12:07:42 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162605#p162605</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162578#p162578</link>
			<description><![CDATA[<p>Попробуйте так:<br /></p><div class="codebox"><pre><code>#Requires AutoHotkey v2

hex_en := &#039;31,00,2d,00,45,00,6e,00,67,00,6c,00,69,00,73,00,68,00&#039;
hex_ru := &#039;32,00,2d,00,20,04,43,04,41,04,41,04,3a,04,38,04,39,04&#039;
buf_en := CryptStringToBinary(hex_en, &#039;CRYPT_STRING_HEX&#039;)
buf_ru := CryptStringToBinary(hex_ru, &#039;CRYPT_STRING_HEX&#039;)
MsgBox StrGet(buf_en) . &#039;`n&#039; . StrGet(buf_ru)

CryptStringToBinary(string, formatName := &#039;CRYPT_STRING_BASE64&#039;)
{
    static formats := { CRYPT_STRING_BASE64: 0x1,
                        CRYPT_STRING_HEX:    0x4,
                        CRYPT_STRING_HEXRAW: 0xC }
    fmt := formats.%formatName%
    chars := StrLen(string)
    if !DllCall(&#039;Crypt32\CryptStringToBinary&#039;, &#039;Str&#039;, string, &#039;UInt&#039;, chars, &#039;UInt&#039;, fmt
                                             , &#039;Ptr&#039;, 0, &#039;UIntP&#039;, &amp;bytes := 0, &#039;UIntP&#039;, 0, &#039;UIntP&#039;, 0)
        throw OSError()
    outBuf := Buffer(bytes, 0)
    DllCall(&#039;Crypt32\CryptStringToBinary&#039;, &#039;Str&#039;, string, &#039;UInt&#039;, chars, &#039;UInt&#039;, fmt
                                         , &#039;Ptr&#039;, outBuf, &#039;UIntP&#039;, &amp;bytes, &#039;UIntP&#039;, 0, &#039;UIntP&#039;, 0)
    return outBuf
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sat, 26 Jul 2025 18:22:56 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162578#p162578</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: Функция перевода из hex в text]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162577#p162577</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, спасибо за подсказку! Нашел <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /> Только почему-то русский шрифт перестал читать. В ahk v1 все работало.</p>]]></description>
			<author><![CDATA[null@example.com (bubblegum)]]></author>
			<pubDate>Fri, 25 Jul 2025 22:40:45 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162577#p162577</guid>
		</item>
	</channel>
</rss>
