<?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="http://forum.script-coding.com/extern.php?action=feed&amp;tid=7489&amp;type=atom" />
	<updated>2014-10-20T12:54:34Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=7489</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87594#p87594" />
			<content type="html"><![CDATA[<p>_</p>]]></content>
			<author>
				<name><![CDATA[Pogodin]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=30956</uri>
			</author>
			<updated>2014-10-20T12:54:34Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87594#p87594</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87581#p87581" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2014-10-19T18:58:35Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87581#p87581</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87578#p87578" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>Поэтому, если к имени файла добавить *, то разница исчезает.</p></blockquote></div><p>&nbsp; Колдовство...</p>]]></content>
			<author>
				<name><![CDATA[Pogodin]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=30956</uri>
			</author>
			<updated>2014-10-19T18:25:53Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87578#p87578</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87577#p87577" />
			<content type="html"><![CDATA[<p>Да, первый вариант не работает. Даже если во второй строке 16 вместо 8. <br /> Казалось, что есть готовый способ, надо только его грамотно применить, и вот уже сколько дней бьюсь, а воз и ныне там. Э-хе-хе.</p>]]></content>
			<author>
				<name><![CDATA[Pogodin]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=30956</uri>
			</author>
			<updated>2014-10-19T18:23:57Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87577#p87577</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87576#p87576" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2014-10-19T18:22:08Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87576#p87576</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87572#p87572" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2014-10-19T17:36:28Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87572#p87572</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87570#p87570" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2014-10-19T17:17:49Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87570#p87570</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87566#p87566" />
			<content type="html"><![CDATA[<p>Я уже думаю, может проще всего перед записью всё преобразовать в банальные 00-FF и записывать как текст?</p>]]></content>
			<author>
				<name><![CDATA[Pogodin]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=30956</uri>
			</author>
			<updated>2014-10-19T16:32:13Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87566#p87566</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87565#p87565" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Pogodin]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=30956</uri>
			</author>
			<updated>2014-10-19T16:28:45Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87565#p87565</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87560#p87560" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p><strong>Pogodin</strong><br />Шифр нужно писать в файл и читать из файла в кодировке UTF16. Это родная кодировка для строк юникодного АНК, поэтому при чтении и записи файла не будет перекодировок.</p></blockquote></div><p>&nbsp; Спасибо, попробую.</p>]]></content>
			<author>
				<name><![CDATA[Pogodin]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=30956</uri>
			</author>
			<updated>2014-10-19T15:44:19Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87560#p87560</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87554#p87554" />
			<content type="html"><![CDATA[<p>Здесь ошибка, скорее всего. Вообще не описан вариант с указанием не &quot;адреса переменной&quot;, а &quot;адреса в переменной&quot;. В прошлых версиях это было.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2014-10-19T15:13:24Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87554#p87554</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87552#p87552" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2014-10-19T14:58:32Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87552#p87552</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87544#p87544" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2014-10-19T14:24:34Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87544#p87544</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87540#p87540" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2014-10-19T12:36:13Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87540#p87540</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поразрядная ротация]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=87536#p87536" />
			<content type="html"><![CDATA[<p><strong>Pogodin</strong><br />Шифр нужно писать в файл и читать из файла в кодировке UTF16. Это родная кодировка для строк юникодного АНК, поэтому при чтении и записи файла не будет перекодировок.</p><p>Лишнее показывается потому, что после чтения из файла вы не ставите в конце прочитанного нулевой терминатор строки. Поэтому АНК читает всё до конца буфера, а не только то, что вы в него прочитали на этот раз.</p><p>Если в str находится число, то оно воспринимается, как адрес буфера, куда нужно считывать файл. По адресу 0 писать нельзя.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2014-10-19T11:43:34Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=87536#p87536</id>
		</entry>
</feed>
