<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=17331</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=17331&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: AHK_H V2 вызов класса из Base64.ahk».]]></description>
		<lastBuildDate>Sun, 21 Aug 2022 16:51:32 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154490#p154490</link>
			<description><![CDATA[<p>В общем, долго мучаясь я нашел тему с нужным мне содержанием.<br />Отредактировал главный пост.</p>]]></description>
			<author><![CDATA[null@example.com (Clannad5)]]></author>
			<pubDate>Sun, 21 Aug 2022 16:51:32 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154490#p154490</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154489#p154489</link>
			<description><![CDATA[<p>Почему бессмысленные? Вполне осмысленные! <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 21 Aug 2022 16:13:23 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154489#p154489</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154488#p154488</link>
			<description><![CDATA[<p>Это не кодек, а формат.<br /><a href="https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptbinarytostringw">https://docs.microsoft.com/en-us/window … ytostringw</a></p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 21 Aug 2022 16:11:02 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154488#p154488</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154487#p154487</link>
			<description><![CDATA[<p><strong>teadrinker</strong></p><p>Я попробовал поставить кодек &quot;0x00000004&quot; и он добавляет бессмысленные нули между байтами &quot;48 00 65 00 6c 00 6c 00&nbsp; 6f 00&quot;.<br />Поэтому я понял, почему кодируется так странно(с невидимыми символами), но не понял как это исправить <img src="//forum.script-coding.com/img/smilies/hmm.png" width="15" height="15" />.</p>]]></description>
			<author><![CDATA[null@example.com (Clannad5)]]></author>
			<pubDate>Sun, 21 Aug 2022 15:35:44 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154487#p154487</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154486#p154486</link>
			<description><![CDATA[<p>Нужно понять, что в base64 кодируется не строка, а байты. Как строка представлена в байтах, зависит от её кодировки.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 21 Aug 2022 14:06:38 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154486#p154486</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154485#p154485</link>
			<description><![CDATA[<p><strong>Malcev</strong><br />а я попробовал только что и без второго параметры и вы правы, результат не меняется, я просто уже запутался и как-то сам его добавил.<br />Однако убрав их, кодируется, но на онлайн сервисах по декодировке возвращает результат со странными невидимыми знаками в виде квадратов.</p><p>Видимо из-за этих квадратов, у меня не работает декод метод.</p>]]></description>
			<author><![CDATA[null@example.com (Clannad5)]]></author>
			<pubDate>Sun, 21 Aug 2022 13:56:34 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154485#p154485</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154484#p154484</link>
			<description><![CDATA[<p>Зачем вы отправляете в функцию 2 параметра?<br />Чтобы понять почему у вас не работает, вам надо понять как эта функция работает, что принимает и что возвращает.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 21 Aug 2022 13:46:02 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154484#p154484</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154483#p154483</link>
			<description><![CDATA[<p><strong>Malcev</strong></p><p>Я попробовал поиграться с функцией и понял, что ошибся.<br />Поправил и сделал так:</p><div class="codebox"><pre><code>
Text := &quot;HelloWorld&quot;
Bytes := StrLen(Text)
Encoded := &quot;&quot;
Decoded := &quot;&quot;

Msgbox Encoded := Base64.Encode(Text, Bytes)
Msgbox Base64.Decode(Encoded)
ExitApp


Class Base64 {
	Static Encode(Buf, Bytes, Codec := 0x00000001) {
		if Buf is String
			p := StrPtr(Buf), s := StrLen(Buf) * 2
		else p := Buf, s := Buf.Size
		if (DllCall(&quot;crypt32\CryptBinaryToString&quot;, &quot;Ptr&quot;, p, &quot;UInt&quot;, s, &quot;UInt&quot;, Codec, &quot;Ptr&quot;, 0, &quot;Uint*&quot;, &amp;nSize := 0) &amp;&amp;
			(VarSetStrCapacity(&amp;VarOut, nSize &lt;&lt; 1), DllCall(&quot;crypt32\CryptBinaryToString&quot;, &quot;Ptr&quot;, p, &quot;UInt&quot;, s, &quot;UInt&quot;, Codec, &quot;Str&quot;, VarOut, &quot;Uint*&quot;, &amp;nSize)))
			return (VarSetStrCapacity(&amp;VarOut, -1), VarOut)
	}

	Static Decode(VarIn, Codec := 0x00000001) {
		if (DllCall(&quot;crypt32\CryptStringToBinary&quot;, &quot;Str&quot;, VarIn, &quot;UInt&quot;, 0, &quot;UInt&quot;, Codec, &quot;Ptr&quot;, 0, &quot;Uint*&quot;, &amp;SizeOut := 0, &quot;Ptr&quot;, 0, &quot;Ptr&quot;, 0) &amp;&amp;
			DllCall(&quot;Crypt32.dll\CryptStringToBinary&quot;, &quot;Str&quot;, VarIn, &quot;UInt&quot;, 0, &quot;UInt&quot;, Codec, &quot;Ptr&quot;, VarOut := Buffer(SizeOut), &quot;Uint*&quot;, &amp;SizeOut, &quot;Ptr&quot;, 0, &quot;Ptr&quot;, 0))
			return VarOut
	}
}
</code></pre></div><p>Теперь кодируется верно, а вот раскодировка почему-то отправляет пустое значение. Даже если поправить функцию как с первым вариантом( то есть добавить параметр Bytes в функцию).</p>]]></description>
			<author><![CDATA[null@example.com (Clannad5)]]></author>
			<pubDate>Sun, 21 Aug 2022 13:43:56 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154483#p154483</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154482#p154482</link>
			<description><![CDATA[<p>Ваш вопрос ahk_h не касается.<br />Лично я вторую версию автохотки не знаю.<br />Вам надо задать этот вопрос на оф.форуме в топике по ahk_l 2.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 21 Aug 2022 13:24:53 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154482#p154482</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154479#p154479</link>
			<description><![CDATA[<p><strong>Malcev</strong></p><div class="codebox"><pre><code>
Text := &quot;Text&quot;
Bytes := StrLen(Text)
Encoded := &quot;&quot;
Decoded := &quot;&quot;
	Msgbox Encoded := Base64.Encode(Text, Bytes)
	Msgbox Decoded := Base64.Decode(Encoded, Bytes)
ExitApp


Class Base64 {
	Static Encode(Buf, Codec := 0x40000001) {
		if Buf is String
			p := StrPtr(Buf), s := StrLen(Buf) * 2
		else p := Buf, s := Buf.Size
		if (DllCall(&quot;crypt32\CryptBinaryToString&quot;, &quot;Ptr&quot;, p, &quot;UInt&quot;, s, &quot;UInt&quot;, Codec, &quot;Ptr&quot;, 0, &quot;Uint*&quot;, &amp;nSize := 0) &amp;&amp;
			(VarSetStrCapacity(&amp;VarOut, nSize &lt;&lt; 1), DllCall(&quot;crypt32\CryptBinaryToString&quot;, &quot;Ptr&quot;, p, &quot;UInt&quot;, s, &quot;UInt&quot;, Codec, &quot;Str&quot;, VarOut, &quot;Uint*&quot;, &amp;nSize)))
			return (VarSetStrCapacity(&amp;VarOut, -1), VarOut)
	}

	Static Decode(VarIn, Codec := 0x00000001) {
		if (DllCall(&quot;crypt32\CryptStringToBinary&quot;, &quot;Str&quot;, VarIn, &quot;UInt&quot;, 0, &quot;UInt&quot;, Codec, &quot;Ptr&quot;, 0, &quot;Uint*&quot;, &amp;SizeOut := 0, &quot;Ptr&quot;, 0, &quot;Ptr&quot;, 0) &amp;&amp;
			DllCall(&quot;Crypt32.dll\CryptStringToBinary&quot;, &quot;Str&quot;, VarIn, &quot;UInt&quot;, 0, &quot;UInt&quot;, Codec, &quot;Ptr&quot;, VarOut := Buffer(SizeOut), &quot;Uint*&quot;, &amp;SizeOut, &quot;Ptr&quot;, 0, &quot;Ptr&quot;, 0))
			return VarOut
	}
}
</code></pre></div><p>В Encoded я получаю это: 54 00 65 00 78 00 74 00.<br />В Decoded я получаю пустое значение.</p><p>При написание длинной строки в переменную &quot;Text&quot; я получаю пустое значение.<br />Я, видимо, делаю что-то не так.</p>]]></description>
			<author><![CDATA[null@example.com (Clannad5)]]></author>
			<pubDate>Sun, 21 Aug 2022 12:23:20 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154479#p154479</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154477#p154477</link>
			<description><![CDATA[<p>Берете код на ahk_l, который переводит в base64.<br />Пытаетесь его понять.<br />Читаете справку об отличиях ahk_l первой и второй версии.<br />Переводите код.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 21 Aug 2022 10:54:31 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154477#p154477</guid>
		</item>
		<item>
			<title><![CDATA[AHK: AHK_H V2 вызов класса из Base64.ahk]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=154474#p154474</link>
			<description><![CDATA[<p>Здравствуйте!<br />Понимаю что возможно не каждый изучает AHK_H v2, но возможно кто-то сможет помочь с проблемой.</p><p>Нашел данный код для AHK_H v2: <a href="https://github.com/Ixiko/AHK-libs-and-classes-collection/blob/master/AHK_V2/Base64.ahk">Base64.ahk.</a><br />Однако там не приведён пример того, как использовать это.</p><p>Пытался везде гуглить, но без результатно, а предоставленный chm(документация) файл я не понимаю.<br />Может ли кто помочь с этим?</p><p>Хотелось бы для примера закодировать строчку &quot;Hello World&quot;.</p><p><strong>UPD: Проблема решена примером ниже.</strong></p><p><a href="https://www.autohotkey.com/boards/viewtopic.php?t=81968">base64 and RC4 encode/decode.</a></p><div class="codebox"><pre><code>
; ====================
; https://autohotkey.com/boards/viewtopic.php?f=6&amp;t=47895
; Base64 by user AlleyArtwork
;
; https://autohotkey.com/board/topic/6316-rc4-encryption-to-hex-stream/
; RC4 by user Laszlo
; =========================

; ========================================
; Usage:  b64Encode(InString,Encoding := &quot;&quot;)
;         b64Decode(InString,Encoding := &quot;&quot;)
;
;    Encoding is an optional parameter.  Use it to force &quot;UTF-8&quot;, &quot;UTF-16&quot; or other encoding.
;    Otherwise encoding is automatically selected based on the current system.
; ========================================
; Examples
; ========================================
; myVar := b64Encode(&quot;a b c d&quot;, &quot;UTF-16&quot;) ; 
; msgbox &quot;output 1: &quot; myVar
; myVar2 := b64Decode(myVar, &quot;UTF-16&quot;) ; 
; msgbox &quot;output 2: &quot; myVar2
; ========================================

b64Encode(sInput,encoding:=&quot;UTF-8&quot;) {
    If (sInput != &quot;&quot;) {
        funcName := (encoding = &quot;UTF-8&quot;) ? &quot;CryptBinaryToStringA&quot; : &quot;CryptBinaryToStringW&quot;
        
        bin := Buffer(StrPut(sInput, encoding),0)
        StrPut(sInput, bin, encoding)
        
        if !(DllCall(&quot;crypt32\&quot; funcName, &quot;Ptr&quot;, bin.ptr, &quot;UInt&quot;, bin.size, &quot;uint&quot;, 0x1, &quot;ptr&quot;, 0, &quot;uint*&quot;, &amp;chars:=0)) ; param 2 was len
            throw Error(funcName &quot; failed to determine size.&quot;, -1)
        
        buf := Buffer(chars * ((encoding=&quot;UTF-16&quot;) ? 2 : 1), 0)
        
        if !(DllCall(&quot;crypt32\&quot; funcName, &quot;ptr&quot;, bin.ptr, &quot;uint&quot;, bin.size, &quot;uint&quot;, 0x1, &quot;ptr&quot;, buf.ptr, &quot;uint*&quot;, &amp;chars))
            throw Error(funcName &quot; failed to execute&quot;, -1)
		
        return StrGet(buf,encoding)
    } Else
        return &quot;&quot;
}

b64Decode(sInput,encoding:=&quot;UTF-8&quot;) {
    InvalidChars := RegexMatch(sInput,&quot;[\#\(\)\$\^\{\}\[\]\.\*\?\+\|]+&quot;)
    If (InvalidChars &gt; 0) {
        MsgBox &quot;Invalid characters detected.  Halting.  (Char position: &quot; InvalidChars &quot;)&quot;
        return &quot;&quot;
    }
    
    size := 0
    If (sInput != &quot;&quot;) {
        funcName := (encoding = &quot;UTF-8&quot;) ? &quot;CryptStringToBinaryA&quot; : &quot;CryptStringToBinaryW&quot;
        
        buf := Buffer(StrPut(sInput,encoding),0)
        StrPut(sInput,buf,encoding)
        
        if !(DllCall(&quot;crypt32\&quot; funcName, &quot;ptr&quot;, buf.ptr, &quot;uint&quot;, 0, &quot;uint&quot;, 0x1, &quot;ptr&quot;, 0, &quot;uint*&quot;, &amp;size:=0, &quot;ptr&quot;, 0, &quot;ptr&quot;, 0))
            throw Error(funcName &quot; failed to determine size.&quot;, -1)
        
        buf2 := Buffer(size, 0)
        if !(DllCall(&quot;crypt32\&quot; funcName, &quot;ptr&quot;, buf.ptr, &quot;uint&quot;, 0, &quot;uint&quot;, 0x1, &quot;ptr&quot;, buf2.ptr, &quot;uint*&quot;, &amp;size, &quot;ptr&quot;, 0, &quot;ptr&quot;, 0))
            throw Error(funcName &quot; failed to execute.&quot;, -1)
        
        return StrGet(buf2, encoding)
    } Else
        return &quot;&quot;
}

; ========================================
; Usage:   RC4txt2hex(InString, password := &quot;&quot;)  ; password optional
;          RC4hex2txt(InString, password := &quot;&quot;)
; ========================================
; Examples
; ========================================
; myVar := RC4txt2hex(&quot;a b c d&quot;,&quot;poof&quot;)
; MsgBox myVar
; myVar2 := RC4hex2txt(myVar,&quot;poof&quot;)
; msgbox myVar2
; ========================================

RC4txt2hex(Data,Pass:=&quot;&quot;) {
    If (Data != &quot;&quot;) {
       Key := Map(), sBox := Map()
	   passLen := StrLen(Pass)
       b := Format(&quot;0x{:X}&quot;,0), j := Format(&quot;0x{:X}&quot;,0)
       Result := &quot;&quot;
       Loop 256 {
          a := Format(&quot;0x{:X}&quot;,A_Index - 1)
          ,Key[a] := Format(&quot;0x{:X}&quot;,passLen?Ord(SubStr(Pass, Mod(a,passLen)+1, 1)):0)
          ,sBox[a] := Format(&quot;0x{:X}&quot;,a)
	   }
       Loop 256 {
          a := Format(&quot;0x{:X}&quot;,A_Index - 1)
          b := b + sBox[a] + Key[a]  &amp; 255, b := Format(&quot;0x{:X}&quot;,b)
		  temp := sBox[a], sBox[a] := sBox[b], sBox[b] := temp, temp := &quot;&quot; ; swap
	   }
	   Loop Parse, Data
	   {
          i := Format(&quot;0x{:X}&quot;,A_Index &amp; 255)
          j := Format(&quot;0x{:X}&quot;,sBox[i] + j &amp; 255)
          k := Format(&quot;0x{:X}&quot;,sBox[i] + sBox[j] &amp; 255)
		  temp := sBox[i], sBox[i] := sBox[j], sBox[j] := temp, temp := &quot;&quot; ; swap
		  numConv := String(Format(&quot;0x{:02X}&quot;,Ord(A_LoopField)^sBox[k]))
          Result .= SubStr(numConv, -2, 2)
	   }
       Return Result
   }
}

RC4hex2txt(Data,Pass:=&quot;&quot;) {
    If (Data != &quot;&quot;) {
       Key := Map(), sBox := Map()
	   passLen := StrLen(Pass)
       b := 0, j := 0, x := &quot;0x&quot;
       Result := &quot;&quot;
       Loop 256
          a := A_Index - 1
         ,Key[a] := passLen?Ord(SubStr(Pass, Mod(a,passLen)+1, 1)):0
         ,sBox[a] := a
       Loop 256 {
          a := A_Index - 1
          b := b + sBox[a] + Key[a]  &amp; 255
		  temp := sBox[a], sBox[a] := sBox[b], sBox[b] := temp, temp := &quot;&quot; ; swap
	   }
       Loop StrLen(Data)//2 {
          i := A_Index  &amp; 255
          j := sBox[i] + j  &amp; 255
          k := sBox[i] + sBox[j]  &amp; 255
		  temp := sBox[i], sBox[i] := sBox[j], sBox[j] := temp, temp := &quot;&quot; ; swap
          Result .= Chr((x SubStr(Data,2*A_Index-1,2)) ^ sBox[k])
	   }
       Return Result
   }
}
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Clannad5)]]></author>
			<pubDate>Sun, 21 Aug 2022 10:05:35 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=154474#p154474</guid>
		</item>
	</channel>
</rss>
