Revision: 8867 https://osdn.net/projects/ttssh2/scm/svn/commits/8867 Author: nmaya Date: 2020-08-04 23:13:46 +0900 (Tue, 04 Aug 2020) Log Message: ----------- crc16 マクロコマンドの説明を修正 MFT to: 4-stable ticket #40615 ヘルプ 実装に使われているのは CRC-16-IBM ではなく CRC-16-CCITT なので説明を修正 crc16 の多項式を修正・表現を crc32 に合わせてビット列にした アルゴリズム説明のソースの関数名・定数を実装のソースコードに合わせて修正 マクロのサンプルコードの ja/en の違いを吸収 ソースコード コメントの typo を修正 Ticket Links: ------------ https://osdn.net/projects/ttssh2/tracker/detail/40615 Modified Paths: -------------- trunk/doc/en/html/macro/command/crc16.html trunk/doc/en/html/macro/command/crc32.html trunk/doc/ja/html/macro/command/crc16.html trunk/doc/ja/html/macro/command/crc32.html trunk/teraterm/ttpmacro/ttl.cpp -------------- next part -------------- Modified: trunk/doc/en/html/macro/command/crc16.html =================================================================== --- trunk/doc/en/html/macro/command/crc16.html 2020-07-29 14:39:44 UTC (rev 8866) +++ trunk/doc/en/html/macro/command/crc16.html 2020-08-04 14:13:46 UTC (rev 8867) @@ -14,7 +14,7 @@ <h1>crc16, crc16file</h1> <p> -Calculates the CRC-16-IBM of a string or a file. +Calculates the CRC-16-CCITT of a string or a file. </p> <pre class="macro-syntax"> @@ -28,7 +28,7 @@ This macro function calculates the CRC(Cyclic Redundancy Checking) of a string or a file. The polynomial expression(right rotation) is as follows: <br><br> -0xA001 (x<sup>16</sup>+x<sup>15</sup>+x<sup>2</sup>+x<sup>0</sup>) +10001000000100001 (x<sup>16</sup>+x<sup>12</sup>+x<sup>5</sup>+x<sup>0</sup>) <br><br> The calculated value stores the variable "intvar" as mathematical value.<br> @@ -40,8 +40,8 @@ <code> static unsigned int crc16(int n, unsigned char c[]) { +#define CRC16POLY1 0x1021U #define CRC16POLY2 0x8408U /* left-right reversal */ - int i, j; unsigned long r; @@ -60,19 +60,19 @@ <h2>Example</h2> <pre class="macro-example"> -str = 'this is a test string to be crc16ed' +str = 'this is a test string to be CRC16ed' crc16 crc str -; Display crc16 result asHEX +; Display CRC16 result asHEX sprintf '0x%08X' crc -messagebox inputstr 'crc16 = ' +messagebox inputstr 'CRC16 = ' crc16file crc 'foo.bin' if result = -1 then - messagebox 'file open error' 'crc16 = ' + messagebox 'file open error' 'CRC16 = ' else sprintf '0x%08X' crc - messagebox inputstr 'crc16 = ' + messagebox inputstr 'CRC16 = ' endif </pre> Modified: trunk/doc/en/html/macro/command/crc32.html =================================================================== --- trunk/doc/en/html/macro/command/crc32.html 2020-07-29 14:39:44 UTC (rev 8866) +++ trunk/doc/en/html/macro/command/crc32.html 2020-08-04 14:13:46 UTC (rev 8867) @@ -39,10 +39,10 @@ This algorithm is often used as the Ethernet FCS(Frame Check Sequence). <pre> <code> -#define CRCPOLY2 0xEDB88320UL /* left-right reversal */ - -static unsigned long crc2(int n, unsigned char c[]) +static unsigned long crc32(int n, unsigned char c[]) { +#define CRC32POLY1 0x04C11DB7UL +#define CRC32POLY2 0xEDB88320UL /* left-right reversal */ int i, j; unsigned long r; @@ -50,7 +50,7 @@ for (i = 0; i < n; i++) { r ^= c[i]; for (j = 0; j < CHAR_BIT; j++) - if (r & 1) r = (r >> 1) ^ CRCPOLY2; + if (r & 1) r = (r >> 1) ^ CRC32POLY2; else r >>= 1; } return r ^ 0xFFFFFFFFUL; Modified: trunk/doc/ja/html/macro/command/crc16.html =================================================================== --- trunk/doc/ja/html/macro/command/crc16.html 2020-07-29 14:39:44 UTC (rev 8866) +++ trunk/doc/ja/html/macro/command/crc16.html 2020-08-04 14:13:46 UTC (rev 8867) @@ -14,7 +14,7 @@ <h1>crc16, crc16file</h1> <p> -CRC-16-IBM\x82\xF0\x8Cv\x8EZ\x82\xB7\x82\xE9\x81B +CRC-16-CCITT\x82\xF0\x8Cv\x8EZ\x82\xB7\x82\xE9\x81B </p> <pre class="macro-syntax"> @@ -28,7 +28,7 @@ \x88\xF8\x90\x94\x82̕\xB6\x8E\x9A\x97\xE6\x82уt\x83@\x83C\x83\x8B\x82\xA9\x82\xE7CRC(Cyclic Redundancy Checking)\x82\xF0\x8Cv\x8EZ\x82\xB7\x82\xE9\x81B\x91\xBD\x8D\x80\x8E\xAE\x81i\x89E\x89\xF1\x82\xE8\x81j\x82͈ȉ\xBA\x82̂Ƃ\xA8\x82\xE8\x81B <br><br> -0xA001 (x<sup>16</sup>+x<sup>15</sup>+x<sup>2</sup>+x<sup>0</sup>) +10001000000100001 (x<sup>16</sup>+x<sup>12</sup>+x<sup>5</sup>+x<sup>0</sup>) <br><br> \x8Cv\x8EZ\x8C\x8B\x89ʂ\xCD intvar \x95ϐ\x94\x82ɐ\x94\x92l\x82Ƃ\xB5\x82Ċi\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br> @@ -40,8 +40,8 @@ <code> static unsigned int crc16(int n, unsigned char c[]) { +#define CRC16POLY1 0x1021U #define CRC16POLY2 0x8408U /* \x8D\xB6\x89E\x8Bt\x93] */ - int i, j; unsigned long r; Modified: trunk/doc/ja/html/macro/command/crc32.html =================================================================== --- trunk/doc/ja/html/macro/command/crc32.html 2020-07-29 14:39:44 UTC (rev 8866) +++ trunk/doc/ja/html/macro/command/crc32.html 2020-08-04 14:13:46 UTC (rev 8867) @@ -38,10 +38,10 @@ CRC\x83A\x83\x8B\x83S\x83\x8A\x83Y\x83\x80\x82̎\xC0\x91\x95\x81iC\x8C\xBE\x8C\xEA\x81j\x82\xF0\x88ȉ\xBA\x82Ɏ\xA6\x82\xB7\x81B\x82\xB1\x82̃A\x83\x8B\x83S\x83\x8A\x83Y\x83\x80\x82́AEthernet\x82\xCCFCS(Frame Check Sequence)\x82ɓK\x97p\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x81B <pre> <code> -#define CRCPOLY2 0xEDB88320UL /* \x8D\xB6\x89E\x8Bt\x93] */ - -static unsigned long crc2(int n, unsigned char c[]) +static unsigned long crc32(int n, unsigned char c[]) { +#define CRC32POLY1 0x04C11DB7UL +#define CRC32POLY2 0xEDB88320UL /* \x8D\xB6\x89E\x8Bt\x93] */ int i, j; unsigned long r; @@ -49,7 +49,7 @@ for (i = 0; i < n; i++) { r ^= c[i]; for (j = 0; j < CHAR_BIT; j++) - if (r & 1) r = (r >> 1) ^ CRCPOLY2; + if (r & 1) r = (r >> 1) ^ CRC32POLY2; else r >>= 1; } return r ^ 0xFFFFFFFFUL; Modified: trunk/teraterm/ttpmacro/ttl.cpp =================================================================== --- trunk/teraterm/ttpmacro/ttl.cpp 2020-07-29 14:39:44 UTC (rev 8866) +++ trunk/teraterm/ttpmacro/ttl.cpp 2020-08-04 14:13:46 UTC (rev 8867) @@ -635,7 +635,7 @@ static unsigned long crc32(int n, unsigned char c[]) { #define CRC32POLY1 0x04C11DB7UL - /* x^{32}+x^{26}+x^{23}+x^{22}+x^{16}+x^{12}+x^{11]+ + /* x^{32}+x^{26}+x^{23}+x^{22}+x^{16}+x^{12}+x^{11}+ x^{10}+x^8+x^7+x^5+x^4+x^2+x^1+1 */ #define CRC32POLY2 0xEDB88320UL /* \x8D\xB6\x89E\x8Bt\x93] */ int i, j;