<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Поразрядная ротация]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=7489</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=7489&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Поразрядная ротация».]]></description>
		<lastBuildDate>Mon, 20 Oct 2014 12:54:34 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87594#p87594</link>
			<description><![CDATA[<p>_</p>]]></description>
			<author><![CDATA[null@example.com (Pogodin)]]></author>
			<pubDate>Mon, 20 Oct 2014 12:54:34 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87594#p87594</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87581#p87581</link>
			<description><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>Однако сравнение файлов показывает единственную разницу: FileAppend добавляет к переводу строки возврат каретки, а File.Write — нет. Поэтому, если к имени файла добавить *, то разница исчезает.</p></blockquote></div><p>М-да, точно. В общем, в итоге пришли к тому, что FileAppend и FileRead всё же достаточно. <img src="//forum.script-coding.com/img/smilies/lol.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 19 Oct 2014 18:58:35 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87581#p87581</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87578#p87578</link>
			<description><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>Поэтому, если к имени файла добавить *, то разница исчезает.</p></blockquote></div><p>&nbsp; Колдовство...</p>]]></description>
			<author><![CDATA[null@example.com (Pogodin)]]></author>
			<pubDate>Sun, 19 Oct 2014 18:25:53 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87578#p87578</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87577#p87577</link>
			<description><![CDATA[<p>Да, первый вариант не работает. Даже если во второй строке 16 вместо 8. <br /> Казалось, что есть готовый способ, надо только его грамотно применить, и вот уже сколько дней бьюсь, а воз и ныне там. Э-хе-хе.</p>]]></description>
			<author><![CDATA[null@example.com (Pogodin)]]></author>
			<pubDate>Sun, 19 Oct 2014 18:23:57 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87577#p87577</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87576#p87576</link>
			<description><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Нет, тут дело не в простоте, а в другом способе записи. В случае FileAppend записываются только те символы, у которых есть реальное текстовое обозначение, а при шифровании оно есть не у всех.</p></blockquote></div><p>Однако сравнение файлов показывает единственную разницу: FileAppend добавляет к переводу строки возврат каретки, а File.Write — нет. Поэтому, если к имени файла добавить *, то разница исчезает.<br /></p><div class="codebox"><pre><code>
FileAppend, % Shifr, *2.txt, UTF-16   ; записываем
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Sun, 19 Oct 2014 18:22:08 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87576#p87576</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87572#p87572</link>
			<description><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>Так проще. Ну, а использовать объект File, по-моему, удобнее. Как-то единообразнее всё выглядит и проще.</p></blockquote></div><p>Нет, тут дело не в простоте, а в другом способе записи. В случае FileAppend записываются только те символы, у которых есть реальное текстовое обозначение, а при шифровании оно есть не у всех.<br />Сравните:<br /></p><div class="codebox"><pre><code>#SingleInstance ignore
FileEncoding,UTF-8

FileDelete,1.txt
FileDelete,2.txt

text = 
(
1234
12345
1234567
123456789
1234567890
asdfghjqweryuiop
asdfghjqweryuiopweryu
aspdfghjqweryuiodfghjqweryuio
asdfghjqwepryuioryuioryuioryuioryuio
)

FileAppend,%text%,1.txt

text := &quot;&quot;
FileRead,text,1.txt

MsgBox, начальный текст из файла:`n%text%

Key1 := &quot;jhhgf3&quot;
Key2 := &quot;rtdvs4&quot;

MsgBox, % &quot;Шифрованный текст:`n&quot; . Shifr := Cipher(text, Key1, Key2)

FileAppend, % Shifr, 2.txt, UTF-16   ; записываем
FileRead, str, 2.txt

MsgBox, % &quot;Расшифровка:`n`n&quot; . text2 := Cipher(str, Key2, Key1)

if( text = text2 )
    MsgBox, Совпадает.
else
    MsgBox, Не совпадает.
    
; =============== Функция шифровки/дешифровки ====================

Cipher(Src, Key1, Key2 = 0)  ; Два последних ключа необязательны.
{
  Loop, 2
  {
    If not Key%A_Index%
      Break
    StringSplit, Keys, Key%A_Index%  ; Разбиваем фразу на отдельные ключи.
    Dest =
    Loop, Parse, Src  ; Перебор символов текста.
    {
      Index := Mod(A_Index, Keys0) + 1  ; Чтобы Index не вышел за пределы
                                        ; числа символов в ключевой фразе.
      Key := Asc(Keys%Index%)   ; Очередной ключ.
      Code := Asc(A_LoopField)  ; Код очередного символа текста.
      Dest .= Chr(Code = Key ? Code : Code ^ Key) ; Шифруем и добавляем.
    }
    Src := Dest
  }
  Return Dest
}</code></pre></div><p>и<br /></p><div class="codebox"><pre><code>#SingleInstance ignore
FileEncoding,UTF-8

FileDelete,1.txt
FileDelete, 2.txt

text = 
(
1234
12345
1234567
123456789
1234567890
asdfghjqweryuiop
asdfghjqweryuiopweryu
aspdfghjqweryuiodfghjqweryuio
asdfghjqwepryuioryuioryuioryuioryuio
)

FileAppend,%text%,1.txt

text := &quot;&quot;
FileRead,text,1.txt

MsgBox, начальный текст из файла:`n%text%

Key1 := &quot;jhhgf3&quot;
Key2 := &quot;rtdvs4&quot;

MsgBox, % &quot;Шифрованный текст:`n&quot; . Shifr := Cipher(text, Key1, Key2)

oFile := FileOpen(&quot;2.txt&quot;, &quot;w&quot;, &quot;UTF-16&quot;)
oFile.Write(Shifr)   ; записываем
oFile.Close()

FileRead, str, 2.txt

MsgBox, % &quot;Расшифровка:`n`n&quot; . text2 := Cipher(str, Key2, Key1)

if( text = text2 )
    MsgBox, Совпадает.
else
    MsgBox, Не совпадает.
    
; =============== Функция шифровки/дешифровки ====================

Cipher(Src, Key1, Key2 = 0)  ; Два последних ключа необязательны.
{
  Loop, 2
  {
    If not Key%A_Index%
      Break
    StringSplit, Keys, Key%A_Index%  ; Разбиваем фразу на отдельные ключи.
    Dest =
    Loop, Parse, Src  ; Перебор символов текста.
    {
      Index := Mod(A_Index, Keys0) + 1  ; Чтобы Index не вышел за пределы
                                        ; числа символов в ключевой фразе.
      Key := Asc(Keys%Index%)   ; Очередной ключ.
      Code := Asc(A_LoopField)  ; Код очередного символа текста.
      Dest .= Chr(Code = Key ? Code : Code ^ Key) ; Шифруем и добавляем.
    }
    Src := Dest
  }
  Return Dest
}
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 19 Oct 2014 17:36:28 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87572#p87572</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87570#p87570</link>
			<description><![CDATA[<div class="quotebox"><cite>Pogodin пишет:</cite><blockquote><p>&nbsp; Я правильно понял, что Raw, не пропущено, а Вы именно так предлагаете записывать? Это же то ж самое, что привычное мне <br /></p><div class="codebox"><pre><code>FileAppend,%str%,1.txt, UTF-16</code></pre></div><p>?</p></blockquote></div><p>Да, предлагаю использовать строковые чтение и запись, а не бинарные. Так проще. Ну, а использовать объект File, по-моему, удобнее. Как-то единообразнее всё выглядит и проще.</p><div class="quotebox"><blockquote><p>Я уже думаю, может проще всего перед записью всё преобразовать в банальные 00-FF и записывать как текст?</p></blockquote></div><p>А в чём простота? Лишняя возня скорее.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Sun, 19 Oct 2014 17:17:49 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87570#p87570</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87566#p87566</link>
			<description><![CDATA[<p>Я уже думаю, может проще всего перед записью всё преобразовать в банальные 00-FF и записывать как текст?</p>]]></description>
			<author><![CDATA[null@example.com (Pogodin)]]></author>
			<pubDate>Sun, 19 Oct 2014 16:32:13 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87566#p87566</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87565#p87565</link>
			<description><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><div class="codebox"><pre><code>
oFile.Write(Shifr)   ; записываем
</code></pre></div></blockquote></div><p>&nbsp; Я правильно понял, что Raw, не пропущено, а Вы именно так предлагаете записывать? Это же то ж самое, что привычное мне <br /></p><div class="codebox"><pre><code>FileAppend,%str%,1.txt, UTF-16</code></pre></div><p>?</p>]]></description>
			<author><![CDATA[null@example.com (Pogodin)]]></author>
			<pubDate>Sun, 19 Oct 2014 16:28:45 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87565#p87565</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87560#p87560</link>
			<description><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p><strong>Pogodin</strong><br />Шифр нужно писать в файл и читать из файла в кодировке UTF16. Это родная кодировка для строк юникодного АНК, поэтому при чтении и записи файла не будет перекодировок.</p></blockquote></div><p>&nbsp; Спасибо, попробую.</p>]]></description>
			<author><![CDATA[null@example.com (Pogodin)]]></author>
			<pubDate>Sun, 19 Oct 2014 15:44:19 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87560#p87560</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87554#p87554</link>
			<description><![CDATA[<p>Здесь ошибка, скорее всего. Вообще не описан вариант с указанием не &quot;адреса переменной&quot;, а &quot;адреса в переменной&quot;. В прошлых версиях это было.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 19 Oct 2014 15:13:24 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87554#p87554</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87552#p87552</link>
			<description><![CDATA[<p>Да, верно. Справка меня сбила с толку.<br /></p><div class="quotebox"><blockquote><p>VarOrAddress <br />A memory address or variable. If VarOrAddress is a variable such as MyVar <strong>and the variable does not contain a pure number</strong> or an object, it is equivalent to passing &amp;MyVar. However, omitting the &quot;&amp;&quot; performs better and ensures that the target address + offset is valid.</p></blockquote></div><p>О каком pure number тогда речь?</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Sun, 19 Oct 2014 14:58:32 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87552#p87552</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87544#p87544</link>
			<description><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>Если в str находится число, то оно воспринимается, как адрес буфера, куда нужно считывать файл.</p></blockquote></div><p>Нет, это только в случае, если str указано, как число (str + 0 или str*1).<br />В остальном согласен. <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, 19 Oct 2014 14:24:34 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87544#p87544</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87540#p87540</link>
			<description><![CDATA[<div class="codebox"><pre><code>
#SingleInstance ignore
FileEncoding,UTF-8

FileDelete,1.txt
FileDelete,2.txt

text = 
(
1234
12345
1234567
123456789
1234567890
asdfghjqweryuiop
asdfghjqweryuiopweryu
aspdfghjqweryuiodfghjqweryuio
asdfghjqwepryuioryuioryuioryuioryuio
)

FileAppend,%text%,1.txt

text := &quot;&quot;
FileRead,text,1.txt

MsgBox, начальный текст из файла:`n%text%

Key1 := &quot;jhhgf3&quot;
Key2 := &quot;rtdvs4&quot;

MsgBox, % &quot;Шифрованный текст:`n&quot; . Shifr := Cipher(text, Key1, Key2)

oFile := FileOpen(&quot;2.txt&quot;, &quot;w&quot;, &quot;UTF-16&quot;)
oFile.Write(Shifr)   ; записываем
oFile.Close()

oFile := FileOpen(&quot;2.txt&quot;, &quot;r&quot;, &quot;UTF-16&quot;)
Shifr := oFile.Read()   ; читаем
oFile.Close()

MsgBox, % &quot;Расшифровка:`n`n&quot; . text2 := Cipher(Shifr, Key2, Key1)

if( text = text2 )
    MsgBox, Совпадает.
else
    MsgBox, Не совпадает.
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Sun, 19 Oct 2014 12:36:13 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87540#p87540</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=87536#p87536</link>
			<description><![CDATA[<p><strong>Pogodin</strong><br />Шифр нужно писать в файл и читать из файла в кодировке UTF16. Это родная кодировка для строк юникодного АНК, поэтому при чтении и записи файла не будет перекодировок.</p><p>Лишнее показывается потому, что после чтения из файла вы не ставите в конце прочитанного нулевой терминатор строки. Поэтому АНК читает всё до конца буфера, а не только то, что вы в него прочитали на этот раз.</p><p>Если в str находится число, то оно воспринимается, как адрес буфера, куда нужно считывать файл. По адресу 0 писать нельзя.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Sun, 19 Oct 2014 11:43:34 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=87536#p87536</guid>
		</item>
	</channel>
</rss>
