Difference between revisions of "Widget:CRCprefix"

From RECESSIM, A Reverse Engineering Community
Jump to navigation Jump to search
(Blanked the page)
Tag: Blanking
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
<noinclude>
 +
This widget adds the '''GridStream CRC Prefix Calculator''' to your wiki page.
  
 +
Code written by L0scher, widget wrapper by [[User:Hash|Hash]].
 +
 +
== Copy to your site ==
 +
To use this widget on your site, just install the [https://www.mediawiki.org/wiki/Extension:Widgets MediaWiki Widgets extension] and the copy [{{fullurl:{{FULLPAGENAME}}|action=edit}} full source code] of this page to your wiki, as an article called '''{{FULLPAGENAME}}'''.
 +
</noinclude><includeonly>
 +
<html>
 +
<head lang="en">
 +
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
 +
<title>GridStream CRC Prefix Calculator by L0scher</title>
 +
<script type="text/javascript">
 +
//<![CDATA[
 +
function calculateInit () {
 +
    str = document.crcform.hexstring.value.toString();
 +
    var prefix = crc.calculateInitFunc(str);
 +
    document.getElementById("initcrc").textContent =
 +
                    prefix.toString(16).toUpperCase().padStart(4, "0");
 +
}
 +
 +
var crc = (function() {
 +
    applyCRC = function(crc, value) {
 +
        crc ^= value << 8;
 +
        crc &= 0xffff;
 +
        for (bit = 0; bit < 8; bit++) {
 +
            var olddata = crc & 0x8000;
 +
            crc <<= 1;
 +
            if (olddata) {
 +
                crc ^= 0x1021;
 +
            }
 +
            crc &= 0xffff;
 +
        }
 +
        return crc;
 +
    }
 +
 +
    calcCRC = function(pkt, crc) {
 +
        return pkt.reduce(applyCRC, crc);
 +
    }
 +
 +
    stringToBytes = function(s){
 +
        return s.split(/([a-fA-F0-9][a-fA-F0-9])/g).filter(p => !!p).map(c => parseInt(c, 16));
 +
    }
 +
 +
    bytesToString = function(b) {
 +
        return b.map(c => c.toString(16).padStart(2,"0")).join("");
 +
    }
 +
 +
    return {
 +
        calculateInitFunc : function (str) {
 +
            str = str.toUpperCase().replace(/\s/g,"");
 +
            var bytes = stringToBytes(str);
 +
            for (testvalue = 0; testvalue < 65536; testvalue+=1) {
 +
                if (calcCRC(bytes,testvalue) === 0) {
 +
                    return testvalue;
 +
                }
 +
            }
 +
        }
 +
    };
 +
})();
 +
//]]>
 +
</script>
 +
</head>
 +
<body>
 +
<h1>CRC Prefix Calculator by L0scher</h1>
 +
<p>Enter a string of hex bytes in the box and hit the <b>Find CRC init</b> button searches for the initial CRC value which would make the calculated CRC equal to zero.  It uses the 0x1021 polynomial value.  If it cannot find such a value, it will leave the value unchanged.
 +
</p>
 +
<form name="crcform">
 +
<textarea name="hexstring" rows="5" cols="80">30FFFFFFFFFFFF50CF5DD9E2C0B80065F5D1A483F0FBBC6F01001E6C043B517E90B286
 +
</textarea>
 +
<br>
 +
<label>Initial CRC value (hex):</label>
 +
<label id="initcrc">5FD6</label>
 +
<br>
 +
<input name="submit" type="button" value="Find CRC init" onclick="calculateInit()">
 +
</form>
 +
</body></html>
 +
</includeonly>

Latest revision as of 21:26, 21 May 2022

This widget adds the GridStream CRC Prefix Calculator to your wiki page.

Code written by L0scher, widget wrapper by Hash.

Copy to your site

To use this widget on your site, just install the MediaWiki Widgets extension and the copy full source code of this page to your wiki, as an article called Widget:CRCprefix.