<?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=8530</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=8530&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Чтение\запись файла по битам\байтам. (криптография)».]]></description>
		<lastBuildDate>Tue, 29 Oct 2013 06:15:33 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76615#p76615</link>
			<description><![CDATA[<p>Не понял логики. Неграмотный не осознаёт своих ошибок.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Tue, 29 Oct 2013 06:15:33 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76615#p76615</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76614#p76614</link>
			<description><![CDATA[<p>К сожалению сознательно. Зачем незнаю, видимо неграмотный.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Tue, 29 Oct 2013 05:57:28 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76614#p76614</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76612#p76612</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Tue, 29 Oct 2013 03:27:53 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76612#p76612</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76610#p76610</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 28 Oct 2013 23:55:40 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76610#p76610</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76581#p76581</link>
			<description><![CDATA[<p>Интересно, теперь сам непонимаю своё выражение. В Char только 128 вариантов. Например 255 и 1 с учётом <strong>Abs</strong> будут равны.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 28 Oct 2013 10:20:40 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76581#p76581</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76580#p76580</link>
			<description><![CDATA[<p>Значит, все дело в логике работы выражения в целом. Байт 0xFF в виде UChar будет 255, а в виде Char -1. <strong>Abs</strong> от этого будет получаться разный.</p>]]></description>
			<author><![CDATA[null@example.com (Irbis)]]></author>
			<pubDate>Mon, 28 Oct 2013 09:27:26 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76580#p76580</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76577#p76577</link>
			<description><![CDATA[<p>А вот с UChar неработает.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 28 Oct 2013 09:01:45 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76577#p76577</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76576#p76576</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (Irbis)]]></author>
			<pubDate>Mon, 28 Oct 2013 08:53:49 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76576#p76576</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76574#p76574</link>
			<description><![CDATA[<p>Да и не помню как туда попало <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Странно почему работало, поменял на Char.</p><p>Кстати почему именно Char? Подбирал методом перебора.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 28 Oct 2013 07:54:23 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76574#p76574</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76571#p76571</link>
			<description><![CDATA[<div class="codebox"><pre><code>NumGet(Bin, A_Index - 1, &quot;cp1251&quot;)</code></pre></div><p>Кодировка числа? Это как так?</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Mon, 28 Oct 2013 03:47:44 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76571#p76571</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=76555#p76555</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Sun, 27 Oct 2013 19:51:51 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=76555#p76555</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74258#p74258</link>
			<description><![CDATA[<p>Спасибо вам огромное! Теперь моя программа расширила свой спектр до бесконечности!<br />Пока пусть работает так, будет время, разберусь как это сделать в “C++” для еще большей мобильности!</p>]]></description>
			<author><![CDATA[null@example.com (Strongest)]]></author>
			<pubDate>Tue, 06 Aug 2013 13:12:41 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74258#p74258</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74257#p74257</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>Tue, 06 Aug 2013 12:58:39 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74257#p74257</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74256#p74256</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Tue, 06 Aug 2013 12:36:54 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74256#p74256</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Чтение\запись файла по битам\байтам. (криптография)]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74255#p74255</link>
			<description><![CDATA[<p>Ага, точно, это я удалял лишние скобки, не проверив. Отредактировал. А почему File.RawRead не читает BOM нет мыслей? Баг?</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 06 Aug 2013 11:56:04 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74255#p74255</guid>
		</item>
	</channel>
</rss>
