<?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=8530&amp;type=atom" />
	<updated>2013-10-29T06:15:33Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=8530</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=76615#p76615" />
			<content type="html"><![CDATA[<p>Не понял логики. Неграмотный не осознаёт своих ошибок.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2013-10-29T06:15:33Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=76615#p76615</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=76614#p76614" />
			<content type="html"><![CDATA[<p>К сожалению сознательно. Зачем незнаю, видимо неграмотный.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-10-29T05:57:28Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=76614#p76614</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=76612#p76612" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>сам непонимаю своё выражение</p></blockquote></div><div class="codebox"><pre><code>(Error_FileExist ? &quot;`n`n*** Кодируемый файл несуществует&quot; : &quot;&quot;)</code></pre></div><p>Скажите, вы сознательно пишете &quot;не&quot; с глаголами слитно? Зачем?</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2013-10-29T03:27:53Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=76612#p76612</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=76610#p76610" />
			<content type="html"><![CDATA[<p>Irbis спасибо за совет, разобрался, поправил на видимо правильный вариант с UChar:<br /></p><div class="codebox"><pre><code>

  ;  http://forum.script-coding.com/viewtopic.php?pid=76555#p76555

/*
В пин коде допустимы цифры, и регистрозависимые буквы латинского алфавита.
Длинна пин кода может быть любой длинны.
Если файл кодируется, то файл-шифр создаётся в той же папке с добавлением &quot;.crypt&quot;
к имени файла. Файл-шифр всегда бинарный. Кодировать можно любые типы файлов,
 с сохранением кодировки.
Если файл декодируется, то файл-шифр должен иметь расширение &quot;crypt&quot;,
результат создаётся в той же папке с удалением &quot;.crypt&quot; в конце имени файла.
Файл добавляется путём перетаскивания на окно.
*/
#SingleInstance Force
#Persistent 
#MaxMem 4095  
SetBatchLines -1 
   
Gui, +AlwaysOnTop -DPIScale 
Gui, Add, Text, x10, Pin:
Gui, Add, Edit, x55 yp w220 r1 vPIN 
Gui, Add, Text, x10, File:
Gui, Add, Edit, x55 yp w220 vFile +ReadOnly 
 
Gui, Add, Button, xs y+5 w74 gCode vEnCode, EnCode
Gui, Add, Button, x+115 w74 gCode vDeCode, DeCode
Gui, Show, , Шифрование
Return 
    
GuiDropFiles: 
    If (A_EventInfo &gt; 1)     
        MsgBox, 262192, Ошибка!, Можно выбрать только один файл, 1
    Else
        GuiControl,, File, % RegExReplace(CodeFile := A_GuiControlEvent, &quot;.*\\(.*)&quot;, &quot;$1&quot;)
    Return
 

Code:  
    Critical
    Gui, Submit, NoHide 
    GuiControl := A_GuiControl
    SplitPath, CodeFile, , Dir, Ext, NameNoExt 
    Error_PIN := (RegExMatch(PIN, &quot;i)[^0-9a-z]&quot;) || PIN = &quot;&quot;)
    Error_FileExist := (!FileExist(CodeFile) || InStr(FileExist(CodeFile), &quot;D&quot;))
    Error_DeCodeExt := (GuiControl = &quot;DeCode&quot; &amp;&amp; Ext != &quot;crypt&quot;)
    If (Error_PIN || Error_FileExist || Error_DeCodeExt)
        MsgBox, 262192, Ошибка!
            , % (Error_PIN ? &quot;*** В пин коде допустимы только цифры, и символы латинского алфавита&quot; : &quot;&quot;)
            . (Error_FileExist ? &quot;`n`n*** Кодируемый файл несуществует&quot; : &quot;&quot;)
            . (Error_DeCodeExt ? &quot;`n`n*** Это не кодированный файл&quot; : &quot;&quot;)
    Else   
    {     
        TargetFile := GuiControl = &quot;EnCode&quot; ? CodeFile &quot;.crypt&quot; : Dir &quot;\&quot; NameNoExt 
        GuiControl,, %GuiControl%, 0 `% 
        crypt() 
        GuiControl,, %GuiControl%, %GuiControl%
        Gui, Show
    } 
    Return
    
crypt()   {    
    Global PIN, CodeFile, TargetFile, GuiControl
    File := FileOpen(CodeFile, &quot;r&quot;), File.Pos := 0 
    Size := File.RawRead(Bin, file.length), File.Close()
    VarSetCapacity(buf, Size, 0)  
    maxPin := StrLen(PIN), iPin := Percent := 0, StepPercent := Size // 100
    
    Loop % Size
    { 
        NumPut(Abs(NumGet(Bin, A_Index - 1, &quot;UChar&quot;) - 255) + Asc(SubStr(PIN, (iPin := iPin = maxPin ? 1 : iPin + 1), 1)), buf, A_Index - 1, &quot;UChar&quot;)         
        If !Mod(A_Index, StepPercent)
            GuiControl,, %GuiControl%, % ++Percent &quot; `%&quot;   
    }
    File := FileOpen(TargetFile, &quot;w&quot;), File.Length := 0
    File.RawWrite(buf, Size), File.Close()  
}     
   
GuiClose: 
    ExitApp 
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-10-28T23:55:40Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=76610#p76610</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=76581#p76581" />
			<content type="html"><![CDATA[<p>Интересно, теперь сам непонимаю своё выражение. В Char только 128 вариантов. Например 255 и 1 с учётом <strong>Abs</strong> будут равны.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-10-28T10:20:40Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=76581#p76581</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=76580#p76580" />
			<content type="html"><![CDATA[<p>Значит, все дело в логике работы выражения в целом. Байт 0xFF в виде UChar будет 255, а в виде Char -1. <strong>Abs</strong> от этого будет получаться разный.</p>]]></content>
			<author>
				<name><![CDATA[Irbis]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27384</uri>
			</author>
			<updated>2013-10-28T09:27:26Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=76580#p76580</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=76577#p76577" />
			<content type="html"><![CDATA[<p>А вот с UChar неработает.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-10-28T09:01:45Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=76577#p76577</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=76576#p76576" />
			<content type="html"><![CDATA[<p>Char: An 8-bit integer, whose range is -128 (-0x80) to 127 (0x7F). An unsigned character (UChar) can be used with functions that expect a BYTE.</p><p>Формально подходя, более верно использовать тип UChar, хотя и так в данном случае ошибки не будет - Numget получает размер&nbsp; операнда (1 байт), знаковое оно или нет, неважно.</p>]]></content>
			<author>
				<name><![CDATA[Irbis]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27384</uri>
			</author>
			<updated>2013-10-28T08:53:49Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=76576#p76576</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=76574#p76574" />
			<content type="html"><![CDATA[<p>Да и не помню как туда попало <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Странно почему работало, поменял на Char.</p><p>Кстати почему именно Char? Подбирал методом перебора.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-10-28T07:54:23Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=76574#p76574</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=76571#p76571" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>NumGet(Bin, A_Index - 1, &quot;cp1251&quot;)</code></pre></div><p>Кодировка числа? Это как так?</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2013-10-28T03:47:44Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=76571#p76571</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=76555#p76555" />
			<content type="html"><![CDATA[<p>Надо было закодировать файл, написал такой скрипт:<br /></p><div class="codebox"><pre><code>
/*
В пин коде допустимы цифры, и регистрозависимые буквы латинского алфавита.
Длинна пин кода может быть любой длинны.
Если файл кодируется, то файл-шифр создаётся в той же папке с добавлением &quot;.crypt&quot;
к имени файла. Файл-шифр всегда бинарный. Кодировать можно любые типы файлов,
 с сохранением кодировки.
Если файл декодируется, то файл-шифр должен иметь расширение &quot;crypt&quot;,
результат создаётся в той же папке с удалением &quot;.crypt&quot; в конце имени файла.
Файл добавляется путём перетаскивания на окно.
*/
#SingleInstance Force
#Persistent 
#MaxMem 4095  
SetBatchLines -1 
   
Gui, +AlwaysOnTop -DPIScale 
Gui, Add, Text, x10, Pin:
Gui, Add, Edit, x55 yp w220 vPIN 
Gui, Add, Text, x10, File:
Gui, Add, Edit, x55 yp w220 vFile +ReadOnly 
 
Gui, Add, Button, xs y+5 w74 gCode vEnCode, EnCode
Gui, Add, Button, x+115 w74 gCode vDeCode, DeCode
Gui, Show, , Шифрование
Return 
    
GuiDropFiles: 
    If (A_EventInfo &gt; 1)     
        MsgBox, 262192, Ошибка!, Можно выбрать только один файл, 1
    Else
        GuiControl,, File, % RegExReplace(CodeFile := A_GuiControlEvent, &quot;.*\\(.*)&quot;, &quot;$1&quot;)
    Return
 

Code:  
    Critical
    Gui, Submit, NoHide 
    GuiControl := A_GuiControl
    SplitPath, CodeFile, , Dir, Ext, NameNoExt 
    Error_PIN := (RegExMatch(PIN, &quot;i)[^0-9a-z]&quot;) || PIN = &quot;&quot;)
    Error_FileExist := (!FileExist(CodeFile) || InStr(FileExist(CodeFile), &quot;D&quot;))
    Error_DeCodeExt := (GuiControl = &quot;DeCode&quot; &amp;&amp; Ext != &quot;crypt&quot;)
    If (Error_PIN || Error_FileExist || Error_DeCodeExt)
        MsgBox, 262192, Ошибка!
            , % (Error_PIN ? &quot;*** В пин коде допустимы только цифры, и символы латинского алфавита&quot; : &quot;&quot;)
            . (Error_FileExist ? &quot;`n`n*** Кодируемый файл несуществует&quot; : &quot;&quot;)
            . (Error_DeCodeExt ? &quot;`n`n*** Это не кодированный файл&quot; : &quot;&quot;)
    Else   
    {     
        TargetFile := GuiControl = &quot;EnCode&quot; ? CodeFile &quot;.crypt&quot; : Dir &quot;\&quot; NameNoExt 
        GuiControl,, %GuiControl%, 0 `% 
        crypt() 
        GuiControl,, %GuiControl%, %GuiControl%
        Gui, Show
    } 
    Return
    
crypt()   {    
    Global PIN, CodeFile, TargetFile, GuiControl
    File := FileOpen(CodeFile, &quot;r&quot;), File.Pos := 0 
    Size := File.RawRead(Bin, file.length), File.Close()
    VarSetCapacity(buf, Size, 0)  
    maxPin := StrLen(PIN), iPin := Percent := 0, StepPercent := Size // 100
    
    Loop % Size
    {
        NumPut((Abs(((NumGet(Bin, A_Index - 1, &quot;Char&quot;)) + (Asc(SubStr(PIN, (iPin := iPin = maxPin ? 1 : iPin + 1), 1)))) - 255)), buf, A_Index - 1, &quot;Char&quot;)  
        If !Mod(A_Index, StepPercent)
            GuiControl,, %GuiControl%, % ++Percent &quot; `%&quot;   
    }
    File := FileOpen(TargetFile, &quot;w&quot;), File.Length := 0
    File.RawWrite(buf, Size), File.Close()  
}     
   
GuiClose: 
    ExitApp 
</code></pre></div><p>Что (возможно) интересно, функция кодирования без-условно одинакова для шифровки \ расшифровки.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-10-27T19:51:51Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=76555#p76555</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=74258#p74258" />
			<content type="html"><![CDATA[<p>Спасибо вам огромное! Теперь моя программа расширила свой спектр до бесконечности!<br />Пока пусть работает так, будет время, разберусь как это сделать в “C++” для еще большей мобильности!</p>]]></content>
			<author>
				<name><![CDATA[Strongest]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=30412</uri>
			</author>
			<updated>2013-08-06T13:12:41Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=74258#p74258</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=74257#p74257" />
			<content type="html"><![CDATA[<p>Вот чёрт, иногда полезно бывает справку прочитать! <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>2013-08-06T12:58:39Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=74257#p74257</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=74256#p74256" />
			<content type="html"><![CDATA[<p>Хм, действительно, не читает. Судя по справке, не баг, а фича:<br /></p><div class="quotebox"><blockquote><p>When a file containing a UTF-8 or UTF-16 byte order mark (BOM) is opened with read access, the BOM is excluded from the output by positioning the file pointer after it. Therefore, File.Position may report 3 or 2 immediately after opening the file.</p></blockquote></div><p>Т.е. нужен сдвиг на начало:<br /></p><div class="codebox"><pre><code>
File.Pos := 0
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2013-08-06T12:36:54Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=74256#p74256</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=74255#p74255" />
			<content type="html"><![CDATA[<p>Ага, точно, это я удалял лишние скобки, не проверив. Отредактировал. А почему File.RawRead не читает BOM нет мыслей? Баг?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2013-08-06T11:56:04Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=74255#p74255</id>
		</entry>
</feed>
