<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>HotPower超级CRC计算器HotCRC</title>
<meta name="Author" content="雁塔菜农HotPower">
<meta name="Description" content="HotPower超级CRC计算器HotCRC是地球上最优秀的CRC计算器之一">
<meta name="Keywords" content="雁塔菜农,HotPower,HotWC3,HotCRC,超级CRC计算器">
<meta name="viewport" content="width=device-width,user-scalable=1.0">
<style type="text/css">
html, body{
width: 100%;
height: 100%;
-webkit-width: 90%;
margin: 0;
padding: 0;
border: 0;
font-weight: normal;
font-style: normal;
font-size: 100%;
font-family: sans-serif;
vertical-align: baseline;
background-color: #C7EDCC;
color: #1f2126;
line-height: 1;
text-align: left;
}
h2 {
text-align: center;
font-style: italic;
margin: 5px;
padding: 0;
color: red;
width: 82%;
min-width: 1020px;
}
h2 label {
text-align: center;
font-style:italic;
margin: 5px;
padding: 0;
color: blue;
width: 82%;
}
h3 {
text-align: left;
font-style: italic;
margin: 5px;
padding: 0;
color: blue;
width: 82%;
min-width: 1020px;
}
div {
display: inline-block;
margin: 0px;
margin-bottom: 0px;
padding: 3px 6px 2px 2px;
border-radius: 6px;
border: 2px solid #1F497D;
margin-right: 10px;
}
fieldset {
width: 82%;
-webkit-width: 82%;
max-width: 88%;
min-width: 1018px;
-webkit-box-sizing:content-box;
font-family: sans-serif;
border: 5px solid #1F497D;
background: #ddd;
border-radius: 5px;
padding: 15px;
}
fieldset legend {
background: #1F497D;
color: #fff;
padding: 5px 10px ;
border-radius: 5px;
box-shadow: 0 0 0 5px #ddd;
margin-left: 20px;
}
.fieldsetwidth div {
width: 100%;
}
marquee {
width: 85%;
min-width: 1050px;
-webkit-width: 85%;
margin: 5px;
font-size: 20px;
font-style: italic;
background: red;
color: yellow;
}
textarea {
width: 99%;
}
input[type="button"] {
margin: 2px;
padding: 2px;
}
.labelblue {
font-size: 14px;
color: blue;
}
.labelred {
font-size: 14px;
color: red;
}
.labelblack {
font-size: 14px;
color: black;
}
.labelred:hover {
color: yellow;
background-color: red;
border-radius: 5px;
box-shadow: 0 0 0 2px #ddd;
}
.labelblue:hover {
color: white;
background-color: blue;
border-radius: 5px;
box-shadow: 0 0 0 2px #ddd;
}
.labelblack:hover {
color: white;
background-color: black;
border-radius: 5px;
box-shadow: 0 0 0 2px #ddd;
}
input[type="text"], input[type="number"], input[type="range"], input[type="checkbox"], select, textarea {
font-family: sans-serif;
background-color: powderblue;
color: black;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="range"]:focus, input[type="checkbox"]:focus, select:focus, textarea:focus {
background: white;
color: black;
}
#idmenuselect{
margin-top: 3px;
margin-bottom: 3px;
width: 98%;
float: left;
}
#idmenuselect .labelred,#idmenuselect .labelblue{
font-size: 16px;
}
#idmenuselect ul{
list-style-type: none;
margin-top: 3px;
margin-bottom: 3px;
padding: 0px;
clear: both;
width: 100%;
}
#idmenuselect ul li {
margin-top: 3px;
margin-bottom: 3px;
padding: 0px;
float: left;
text-align: left;
width: 11%;
}
.radioli {
width: 100%;
}
.radioli ul {
list-style-type: none;
margin: 0px;
padding: 0px;
clear: both;
}
.radioli ul li {
margin: 0px;
padding: 0px;
float: left;
text-align: left;
width: 14%;
}
.triangleworkfieldset {
margin: 0;
padding: 0;
width: 100%;
}
.wc3input {
margin-top: 5px;
margin-bottom: 5px;
width: 50%;
float: left;
}
.wc3output {
margin-top: 5px;
margin-bottom: 5px;
width: 50%;
float: right;
}
#HotWC3PassEdit {
width: 98%;
}
#wc3input {
display: block;
clear: both;
float: left;
width: 59%;
}
#wc3output {
display: block;
float: right;
width: 39%;
}
#idHotWC3TextArray {
margin-top: 9px;
margin-bottom: 0px;
padding-top: 3px;
padding-bottom: 3px;
float: left;
width: 61%;
}
#idHotWC3TextArray ul {
list-style-type: none;
margin: 0px;
padding: 0px;
clear: both;
text-align: center;
}
#idHotWC3TextArray ul li {
margin: 0px;
padding: 0px;
float: left;
text-align: left;
}
#divhotwc3work {
margin-top: 9px;
padding-top: 2px;
padding-bottom: 2px;
float: right;
width: 34%;
font-family: sans-serif;
}
#divdatedisplay {
margin-top: 0px;
width: 98%;
float: left;
}
#divsystemtest {
margin-top: 9px;
width: 98%;
float: left;
}
#triangleleftup {
margin-bottom: 9px;
float: left;
width: 54%;
}
#triangleright {
float: right;
width: 41%;
height: 100%;
font-family: sans-serif;
background-color: powderblue;
color: black;
}
#triangleleftdn {
margin-top: 9px;
width: 54%;
clear: both;
}
#wc3inputanalysis {
display: block;
width: 100%;
}
#wc3outputanalysis {
display: block;
width: 100%;
}
#divhotwc3menu {
margin-top: 1px;
margin-left: 4px;
width: 96%;
}
#divhotwc3passtext {
margin-top: 2px;
margin-left: 4px;
width: 96%;
}
#divhotwc3passbutton {
margin-top: 2px;
margin-left: 4px;
width: 96%;
}
#idhotwc3passstring {
margin-top: 9px;
margin-left: 3px;
padding-top: 3px;
padding-bottom: 3px;
height: 100%;
font-family: sans-serif;
float: left;
width: 73%;
}
#idhotwc3valuetring{
margin-top: 9px;
margin-right: 3px;
padding-top: 3px;
padding-bottom: 3px;
height: 100%;
font-family: sans-serif;
float: right;
width: 22%;
}
#divHotWC3calculator{
margin-top: 9px;
margin-bottom: 9px;
margin-left: 4px;
margin-right: 4px;
padding-top: 3px;
padding-bottom: 3px;
height: 100%;
font-family: sans-serif;
clear: both;
float: left;
width: 98%;
}
#idhotwc3crcntest {
margin-top: 9px;
margin-left: 4px;
padding-top: 3px;
padding-bottom: 3px;
float: left;
height: 100%;
font-family: sans-serif;
float: left;
width: 98%;
}
#lbHotWC3Count {
float: right;
}
input:out-of-range {
background: red;
}
</style>
</head>
<body>
<h2><label>HotPower超级CRC计算器</label> HotCRC</h2>
<marquee rows="1" scrollamount="8" onMouseOver="this.stop()" onMouseOut="this.start()" onClick="fieldsethelp(-1)">
HotPower超级CRC计算器HotCRC是地球上最优秀的CRC计算器之一
菜农星期公式 =((百年&3)*5+年+(年>>2)+(13*月+8)/5+日)%7
特殊直角边口诀:
当直角边a(>=3)为奇数时,另一直角边b为a平方砍半取整,斜边c比b大1。
当直角边a(>=3)为偶数时,另一直角边b为a砍半平方减1,斜边c比b大2。
</marquee>
<fieldset class="fieldsetwidth" id="systemtestfieldset">
<legend onClick="">系统测试</legend>
<div id="divdatedisplay">
<select size="1" id="year1000" title="千年" value="2" onChange="hotwc3()">
<option value="0"> 0</option>
<option value="1"> 1</option>
<option value="2" selected="selected"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="6"> 6</option>
<option value="7"> 7</option>
<option value="8"> 8</option>
<option value="9"> 9</option>
</select>
<select size="1" id="year100" title="百年" value="0" onChange="hotwc3()">
<option value="0" selected="selected"> 0</option>
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="6"> 6</option>
<option value="7"> 7</option>
<option value="8"> 8</option>
<option value="9"> 9</option>
</select>
<select id="year10" value="1" size="1" onChange="hotwc3()" title="十年">
<option value="0"> 0</option>
<option value="1" selected="selected"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="6"> 6</option>
<option value="7"> 7</option>
<option value="8"> 8</option>
<option value="9"> 9</option>
</select>
<select size="1" id="year1" title="年" onChange="hotwc3()" value="7" year1="">
<option value="0"> 0</option>
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="6"> 6</option>
<option value="7" selected="selected"> 7</option>
<option value="8"> 8</option>
<option value="9"> 9</option>
</select>
<input type="text" id="tgdztext" value="庚申" size="4" maxlength="0" title="天干地支年">
<label class="labelblue" for="year1" title="年">年</label>
<select id="monthselect" value="8" size="1" onChange="hotwc3()" title="月">
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="6"> 6</option>
<option value="7"> 7</option>
<option value="8" selected="selected"> 8</option>
<option value="9"> 9</option>
<option value="10"> 10</option>
<option value="11"> 11</option>
<option value="12"> 12</option>
</select>
<label class="labelblue" for="monthselect" title="月">月</label>
<select id="dayselect" value="16" size="1" onChange="hotwc3()" title="日">
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
<option value="6"> 6</option>
<option value="7"> 7</option>
<option value="8"> 8</option>
<option value="9"> 9</option>
<option value="10"> 10</option>
<option value="11"> 11</option>
<option value="12"> 12</option>
<option value="13"> 13</option>
<option value="14"> 14</option>
<option value="15"> 15</option>
<option value="16" selected="selected"> 16</option>
<option value="17"> 17</option>
<option value="18"> 18</option>
<option value="19"> 19</option>
<option value="20"> 20</option>
<option value="21"> 21</option>
<option value="22"> 22</option>
<option value="23"> 23</option>
<option value="24"> 24</option>
<option value="25"> 25</option>
<option value="26"> 26</option>
<option value="27"> 27</option>
<option value="28"> 28</option>
<option value="29"> 29</option>
<option value="30"> 30</option>
<option value="31"> 31</option>
</select>
<label class="labelblue" for="dayselect" title="日">日</label>
<select id="weekselect" value="3" size="1" onChange="SetHotwc3WeekDisply()" title="自动由多种星期公式算出">
<option value="0"> 星期日</option>
<option value="1"> 星期一</option>
<option value="2"> 星期二</option>
<option value="3" selected="selected"> 星期三</option>
<option value="4"> 星期四</option>
<option value="5"> 星期五</option>
<option value="6"> 星期六</option>
</select>
<label class="labelblue" for="timetext" title="当前时间">时间</label>
<input type="text" id="timetext" value="18:18:18" size="9" maxlength="8" title="当前时间">
<select id="weeksele" value="0" size="1" onChange="weekselehelp()" title="多种星期公式选择">
<option value="0"> 菜农星期公式</option>
<option value="1"> 蔡勒星期公式</option>
<option value="2"> 基姆拉尔森星期公式</option>
<option value="3"> 菜农第二星期公式</option>
<option value="4"> 菜农第三星期公式</option>
<option value="5"> 查表星期公式</option>
</select>
<select id="idwc3help" size="1" onChange="HotWC3Readme()" title="选择全屏文本行数">
<option value="0">操作指南</option>
<option value="1">密码分析</option>
<option value="2">密码问答</option>
</select>
<input type="button" value="版本" onClick="wc3help()" id="wc3help" title="HotCRC超级CRC计算器更新版本说明">
<input type="button" value="秘籍" onClick="HotWC3ManualLoad()" id="manual" title="菜农CRC宝典秘籍">
</div>
<div id="divsystemtest">
<input type="checkbox" id="hotwc3wificheckbox" title="有无网络实时监测" onClick="hotwc3wifi()" value="">
<label class="labelblue" id="hotwc3wifilabel" for="hotwc3wificheckbox" title="有无网络实时监测">网络</label>
<input type="checkbox" id="iecheckbox" onClick="iecheckboxChange()" title="推荐采用HotCode" value="">
<label class="labelblue" id="ielabel" for="iecheckbox" title="IE浏览器,推荐采用HotCode">IE</label>
<input type="checkbox" id="wincheckbox" onClick="wincheckboxChange()" title="Windows操作系统" value="">
<label class="labelblue" id="winlabel" for="wincheckbox" title="Windows操作系统">Win</label>
<input type="checkbox" id="adrcheckbox" onClick="adrcheckboxChange()" title="安卓手机" value="">
<label class="labelblue" id="adrlabel" for="adrcheckbox" title="安卓手机">Adr</label>
<input type="checkbox" id="ioscheckbox" onClick="ioscheckboxChange()" title="苹果浏览器" value="">
<label class="labelblue" id="ioslabel" for="ioscheckbox" title="苹果浏览器">iOS</label>
<input type="checkbox" id="filecheckbox" title="浏览器支持HTML5或IE文件操作" onClick="filecheckboxChange()" value="">
<label class="labelblue" id="filelabel" for="filecheckbox" title="浏览器支持HTML5或IE文件操作">文件</label>
<input type="checkbox" id="hotwc3onlinecheckbox" title="网页是否在线" onClick="hotwc3online()" value="">
<label class="labelblue" id="hotwc3onlinelabel" for="hotwc3onlinecheckbox" title="网页是否在线">在线</label>
<input type="checkbox" id="localStoragecheckbox" title="本地存储" onClick="HotwclocalStorage()" value="">
<label class="labelblue" id="localStoragelabel" for="localStoragecheckbox" title="本地存储">存储</label>
<label id="lbHotWC3Count">
<label class="labelblue" id="HotWC3Countlabel" onClick="GetHotWC3BrowseCount()" for="HotWC3Count" title="在线浏览总次数">在线浏览</label>
<input type="text" id="HotWC3Count" placeholder="在线浏览总次数" title="在线浏览总次数" value="" size="12" maxlength="">
<label class="labelblue" id="lbhotwc3browsecount" for="hotwc3browsecount" title="本地浏览总次数">本地浏览</label>
<input type="text" id="hotwc3browsecount" placeholder="本地浏览总次数" title="本地浏览总次数" value="" size="12" maxlength="">
</label>
</div>
<div id="idmenuselect">
<ul>
<li>
<input type="radio" name="menubutton" id="mainmenubutton" onClick="HotWC3WindowsMenu(0, 1)" value="" title="主界面选择">
<label class="labelblue" for="mainmenubutton" title="主界面选择">主界面</label>
</li>
<li>
<input type="radio" name="menubutton" id="passmenubutton" onClick="HotWC3WindowsMenu(1, 1)" value="" title="密码界面选择">
<label class="labelred" for="passmenubutton" title="主界面选择">密码操作</label>
</li>
<li>
<input type="radio" name="menubutton" id="analysismenubutton" onClick="HotWC3WindowsMenu(2, 1)" value="" title="密码分析界面选择">
<label class="labelblue" for="analysismenubutton" title="主界面选择">密码分析</label>
</li>
<li>
<input type="radio" name="menubutton" id="crcmenubutton" onClick="HotWC3WindowsMenu(3, 1)" value="" title="CRC计算器界面选择" checked="checked">
<label class="labelred" for="crcmenubutton" title="主界面选择">CRC计算器</label>
</li>
<li>
<input type="radio" name="menubutton" id="trianglemenubutton" onClick="HotWC3WindowsMenu(4, 1)" value="" title="三角密码界面选择">
<label class="labelblue" for="trianglemenubutton" title="主界面选择">三角密码</label>
</li>
<li>
<input type="radio" name="menubutton" id="webmenubutton" onClick="HotWC3WindowsMenu(5, 1)" value="" title="网页转换界面选择">
<label class="labelred" for="webmenubutton" title="主界面选择">网页转换</label>
</li>
<li>
<input type="radio" name="menubutton" id="allmenubutton" onClick="HotWC3WindowsMenu(6, 1)" value="" title="全部界面选择">
<label class="labelblue" for="allmenubutton" title="全部界面选择">全部界面</label>
</li>
</ul>
</div>
</fieldset>
<p>
</p>
<fieldset class="fieldsetwidth" id="hotwc3workfieldset">
<legend onClick="fieldsethelp(0);wc3input.value=''">HotWC3密码操作</legend>
<div id="HotWC3PassEdit">
<textarea cols="85" rows="8" id="wc3input" onDblClick="ChangeidinputHotWC3TextBox();wc3inputclipboard()" onChange="ChangeidinputHotWC3TextBox()" placeholder="HotWC3密码需要输入的明文" title="HotWC3密码需要输入的明文"></textarea>
<textarea cols="45" rows="8" id="wc3output" onDblClick="ChangeidoutputHotWC3TextBox();wc3outputclipboard()" onChange="ChangeidoutputHotWC3TextBox()" placeholder="HotWC3密码需要输入的密文" title="HotWC3密码需要输入的密文"></textarea>
</div>
<div id="idHotWC3TextArray">
<ul id="idHotWC3TextString_X" name="idHotWC3TextString_X">
<li>
<input type="text" id="HotWC3TextString_X_6" onClick="" for="idselecrcnmode" title="" value="内 核" size="6">
</li>
<li>
<input type="text" id="HotWC3TextString_X_0" value="天地" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_X_1" value="星期" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_X_2" value="三 角" size="5">
</li>
<li>
<input type="text" id="HotWC3TextString_X_3" value="日 期" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_X_4" value="用 户" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_X_5" value="扩 展" size="9">
</li>
</ul>
<ul id="idHotWC3TextString_0" name="idHotWC3TextString_0">
<li>
<input type="text" id="HotWC3TextString_0_X" for="idselecrcnmode" title="选择内核CRC8" value="CRC8" size="6">
</li>
<li>
<input type="text" id="HotWC3TextString_0_0" value="A3" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_0_1" value="65" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_0_2" value="210F" size="5">
</li>
<li>
<input type="text" id="HotWC3TextString_0_3" value="19790413" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_0_4" value="19591119" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_0_5" value="19491001" size="9">
</li>
</ul>
<ul id="idHotWC3TextString_1" name="idHotWC3TextString_1">
<li>
<input type="text" id="HotWC3TextString_1_X" for="idselecrcnmode" title="选择内核CRC16" value="CRC16" size="6">
</li>
<li>
<input type="text" id="HotWC3TextString_1_0" value="A3" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_1_1" value="65" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_1_2" value="210F" size="5">
</li>
<li>
<input type="text" id="HotWC3TextString_1_3" value="19790413" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_1_4" value="19591119" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_1_5" value="19491001" size="9">
</li>
</ul>
<ul id="idHotWC3TextString_2" name="idHotWC3TextString_2">
<li>
<input type="text" id="HotWC3TextString_2_X" for="idselecrcnmode" title="选择内核CRC24" value="CRC24" size="6">
</li>
<li>
<input type="text" id="HotWC3TextString_2_0" value="A3" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_2_1" value="65" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_2_2" value="210F" size="5">
</li>
<li>
<input type="text" id="HotWC3TextString_2_3" value="19790413" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_2_4" value="19591119" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_2_5" value="19491001" size="9">
</li>
</ul>
<ul id="idHotWC3TextString_3" name="idHotWC3TextString_3">
<li>
<input type="text" id="HotWC3TextString_3_X" for="idselecrcnmode" title="选择内核CRC32" value="CRC32" size="6">
</li>
<li>
<input type="text" id="HotWC3TextString_3_0" value="A3" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_3_1" value="65" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_3_2" value="210F" size="5">
</li>
<li>
<input type="text" id="HotWC3TextString_3_3" value="19790413" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_3_4" value="19591119" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_3_5" value="19491001" size="9">
</li>
</ul>
<ul id="idHotWC3TextString_4" name="idHotWC3TextString_4">
<li>
<input type="text" id="HotWC3TextString_4_X" for="idselecrcnmode" title="选择内核CRC40" value="CRC40" size="6">
</li>
<li>
<input type="text" id="HotWC3TextString_4_0" value="A3" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_4_1" value="65" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_4_2" value="210F" size="5">
</li>
<li>
<input type="text" id="HotWC3TextString_4_3" value="19790413" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_4_4" value="19591119" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_4_5" value="19491001" size="9">
</li>
</ul>
<ul id="idHotWC3TextString_5" name="idHotWC3TextString_5">
<li>
<input type="text" id="HotWC3TextString_5_X" for="idselecrcnmode" title="选择内核CRC48" value="CRC48" size="6">
</li>
<li>
<input type="text" id="HotWC3TextString_5_0" value="A3" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_5_1" value="65" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_5_2" value="210F" size="5">
</li>
<li>
<input type="text" id="HotWC3TextString_5_3" value="19790413" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_5_4" value="19591119" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_5_5" value="19491001" size="9">
</li>
</ul>
<ul id="idHotWC3TextString_6" name="idHotWC3TextString_6">
<li>
<input type="text" id="HotWC3TextString_6_X" for="idselecrcnmode" title="选择内核CRC56" value="CRC56" size="6">
</li>
<li>
<input type="text" id="HotWC3TextString_6_0" value="A3" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_6_1" value="65" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_6_2" value="210F" size="5">
</li>
<li>
<input type="text" id="HotWC3TextString_6_3" value="19790413" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_6_4" value="19591119" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_6_5" value="19491001" size="9">
</li>
</ul>
<ul id="idHotWC3TextString_7" name="idHotWC3TextString_7">
<li>
<input type="text" id="HotWC3TextString_7_X" for="idselecrcnmode" title="选择内核CRC64" value="CRC64" size="6">
</li>
<li>
<input type="text" id="HotWC3TextString_7_0" value="A3" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_7_1" value="65" size="4">
</li>
<li>
<input type="text" id="HotWC3TextString_7_2" value="210F" size="5">
</li>
<li>
<input type="text" id="HotWC3TextString_7_3" value="19790413" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_7_4" value="19591119" size="9">
</li>
<li>
<input type="text" id="HotWC3TextString_7_5" value="19491001" size="9">
</li>
</ul>
</div>
<div id="divhotwc3work">
<div id="divhotwc3menu">
<label class="labelblue" for="wc3input" onClick="wc3inputclipboard()" title="复制明文到剪切板">明文</label>
<select size="1" id="idselechnmode" title="明文编码格式,推荐采用HotCode" onChange="selechnmode()">
<option value="HEX">HEX</option>
<option value="ASCII">ASCII</option>
<option value="GB2312-80"> GB2312-80</option>
<option value="UniCode"> UniCode</option>
<option value="UTF-8"> UTF-8</option>
<option value="HotCode" selected="selected"> HotCode</option>
<option value="BASE64"> BASE64</option>
<option value="UUEncode"> UUEncode</option>
<option value="XXEncode"> XXEncode</option>
<option value="Quoted-printable"> Quoted-printable</option>
</select>
<input type="text" id="wc3inputcount" value="" size="4" maxlength="6" title="明文字节数">
<input type="button" id="idclearwc3input" title="清空明文编辑框" onClick="wc3input.value=''" value="清空">
<input type="radio" name="radiohotwc3versionbutton" id="radiohotwc3version1" onClick="" value="V1.0" title="HotWC3密码版本V1.0,适合硬件实现">
<label class="labelblue" for="radiohotwc3version1" title="HotWC3密码版本V1.0,适合硬件实现">V1.0</label>
<br>
<label class="labelblue" for="wc3output" onClick="wc3outputclipboard()" title="复制密文到剪切板">密文</label>
<select size="1" id="idseleoutmode" title="密文编码格式">
<option value="HEX">HEX</option>
<option value="BASE64"> BASE64</option>
<option value="UUEncode"> UUEncode</option>
<option value="XXEncode"> XXEncode</option>
<option value="Quoted-printable"> Quoted-printable</option>
<option value="BASE4096" selected="selected"> BASE4096</option>
</select>
<input type="text" id="wc3outputcount" value="" size="4" maxlength="6" title="密文字节数">
<input type="button" id="idclearwc3output" title="清空密文编辑框" onClick="wc3output.value=''" value="清空">
<input type="radio" name="radiohotwc3versionbutton" id="radiohotwc3version2" onClick="" value="V2.0" title="HotWC3密码V2.0" checked="checked">
<label class="labelred" for="radiohotwc3version2" title="HotWC3密码版本V2.0">V2.0</label>
<br>
<label class="labelred" for="idselecrcnmode" title="HotWC3密码可逆CRC内核选择">内核</label>
<select size="1" id="idselecrcnmode" title="可逆CRC内核选择" onChange="LoadCRCTextString(idselecrcnmode.selectedIndex)"><!--selecrcnmode()-->
<option value="CRC8" selected="selected"> CRC8</option>
<option value="CRC16"> CRC16</option>
<option value="CRC24"> CRC24</option>
<option value="CRC32"> CRC32</option>
<option value="CRC40"> CRC40</option>
<option value="CRC48"> CRC48</option>
<option value="CRC56"> CRC56</option>
<option value="CRC64"> CRC64</option>
</select>
<input type="checkbox" id="hotwc3CRC32checkbox" title="选择CRC32" onClick="" value="" checked="checked">
<label class="labelred" for="hotwc3CRC32checkbox" title="密文输出选择CRC32">CRC32</label>
<input type="checkbox" id="hotwc3Keycheckbox" onClick="hotwc3KeySelect()" checked="" title="密文输出选择密钥" value="">
<label class="labelred" for="hotwc3Keycheckbox" title="密文输出选择密钥">密钥</label>
<input type="checkbox" id="hotwc3filecheckbox" title="HotWC3密码文件操作" onClick="hotwc3filecheckboxChange()" value="">
<label class="labelred" for="hotwc3filecheckbox" title="HotWC3密码文件操作">文件</label>
<br>
<input type="checkbox" id="hotwc3titlecheckbox" checked="checked" title="HotWC3密码文件操作" onClick="" value="">
<label class="labelblue" for="hotwc3titlecheckbox" onClick="if(hotwc3titlecheckbox.checked) hotwc3titleoutput.value = ''" title="HotWC3密码需要输出标题">标题</label>
<input type="text" id="hotwc3titleoutput" placeholder="HotWC3密码需要输出标题" title="HotWC3密码需要输出标题" value="消息已发送,请查收!!!" size="29" maxlength="128">
</div>
<div id="divhotwc3passtext">
<input type="button" id="SaveClearPasswordTable" title="保存HotWC3密钥CRC16-CRC64,为了安全不保存CRC8密钥" onClick="SaveClearPasswordTable()" value="保存密钥">
<input type="button" id="RemovePasswordTable" title="恢复HotWC3密钥CRC16-CRC64到初始密钥" onClick="RemovePasswordTable()" value="初始密钥">
<input type="button" id="ViewPasswordTable" title="查看HotWC3密钥CRC16-CRC64到初始密钥" onClick="ViewPasswordTable()" value="查看密钥">
<label class="labelblue" for="idbHotWC3TextBoxCount" onClick="ChangeHotWC3TextBoxSet()" title="选择全屏文本12行">全屏</label>
<select id="idbHotWC3TextBoxCount" size="1" onChange="ChangeHotWC3TextBox()" title="选择全屏文本行数">
<option value="2" selected="selected">2</option>
<option value="4"> 4</option>
<option value="8"> 8</option>
<option value="12"> 12</option>
<option value="24"> 24</option>
<option value="48"> 48</option>
</select>
</div>
<div id="divhotwc3passbutton">
<input type="button" id="hotwc3passex" title="HotWC3密码加密过程" onClick="hotwc3passex()" value="明文加密">
<input type="button" id="hotwc3dispassex" title="HotWC3密码解密过程" onClick="hotwc3dispassex()" value="密文解密">
<input type="button" id="idwc3flowchartcilick" title="HotWC3密码流程框图" onClick="BrowseFlowchart()" value="流程图">
</div>
</div>
<label class="wc3input">
<label id="hotwc3passload" style="display:none">
<label class="labelblue" for="wc3fileinput" title="HotWC3密码需要输入的文件名">文件名</label>
<input type="text" id="wc3fileinput" placeholder="HotWC3密码需要输入的文件名" title="HotWC3密码需要输入的文件名" value="" size="46" maxlength="128">
<input type="button" id="hotwc3pass" title="导入HotWC3密码明文文件" onClick="hotwc3pass()" value="导入">
</label>
</label>
<label class="wc3output">
<label id="hotwc3dispassload" style="display:none">
<label class="labelblue" for="wc3fileoutput" title="HotWC3密码需要输出的文件名">文件名</label>
<input type="text" id="wc3fileoutput" placeholder="HotWC3密码需要输出的文件名" title="HotWC3密码需要输出的文件名" value="" size="46" maxlength="128">
<input type="button" id="hotwc3dispass" title="导出HotWC3密码的密文到文件" onClick="hotwc3dispass()" value="导出">
</label>
</label>
</fieldset>
<p>
</p>
<fieldset class="fieldsetwidth" id="hotwc3Analysisfieldset">
<legend onClick="fieldsethelp(1)">HotWC3密码分析</legend>
<div id="idhotwc3passstring">
<label class="labelblue" for="HotWC3LeftTriangleString" title="左侧三角密钥流">左三角</label>
<input type="text" id="HotWC3LeftTriangleString" value="" size="19" onClick="" onChange="" placeholder="左侧三角密钥流" title="左侧三角密钥流">
<label class="labelblue" for="HotWC3RightTriangleString" title="右三角密钥">右三角</label>
<input type="text" id="HotWC3RightTriangleString" value="" size="19" onClick="" onChange="" placeholder="右侧三角密钥流" title="右侧三角密钥流">
<label class="labelblue" for="HotWC3MessageText" onClick="HotWC3MessageText.value=''" title="明文的HEX字">明文字</label>
<input type="text" id="HotWC3MessageText" value="" size="20" maxlength="16" onChange="TestHotWC3MessageText()" placeholder="明文的HEX字" title="明文的HEX字">
<br>
<label class="labelblue" for="HotWC3DateString" title="日期密钥流">日期流</label>
<input type="text" id="HotWC3DateString" value="" size="71" onClick="" onChange="" placeholder="日期密钥流" title="日期密钥流">
<input type="button" id="idHotWC3CRCcalculator" title="加密明文字" onClick="HotWC3CRCcalculator()" value="加密明文字">
<br>
<label class="labelblue" for="HotWC3UserString" title="用户密钥流">用户流</label>
<input type="text" id="HotWC3UserString" value="" size="71" onClick="" onChange="" placeholder="用户密钥流" title="用户密钥流">
<input type="button" id="idHotWC3CRCrevert" title="解密密文字" onClick="HotWC3CRCrevert()" value="解密密文字">
<br>
<label class="labelblue" for="HotWC3TGDZString" title="天地密钥流">天地流</label>
<input type="text" id="HotWC3TGDZString" value="" size="19" onClick="" onChange="" placeholder="天地密钥流" title="天地密钥流">
<label class="labelblue" for="HotWC3WeekString" title="星期密钥流">星期流</label>
<input type="text" id="HotWC3WeekString" value="" size="19" onClick="" onChange="" placeholder="星期密钥流" title="星期密钥流">
<label class="labelblue" for="HotWC3PassText" onClick="HotWC3PassText.value=''" title="密文的HEX字">密文字</label>
<input type="text" id="HotWC3PassText" value="" size="20" maxlength="16" onChange="TestHotWC3PassText()" placeholder="密文的HEX字" title="密文的HEX字">
<br>
<label class="labelblue" for="HotWC3LeftUserExString" title="左侧扩展密钥流">左扩展</label>
<input type="text" id="HotWC3LeftUserExString" value="" size="35" onClick="" onChange="" placeholder="左侧扩展密钥流" title="左侧扩展密钥流">
<label class="labelblue" for="HotWC3RightUserExString" title="右侧扩展密钥流">右扩展</label>
<input type="text" id="HotWC3RightUserExString" value="" size="35" onClick="" onChange="" placeholder="右侧扩展密钥流" title="右侧扩展密钥流">
</div>
<div id="idhotwc3valuetring">
<label class="labelblue" for="HotWC3PolyStringText" onClick="GetPolyStringText()" title="HotWC3密钥流产生的权值HEX字">权值字</label>
<input type="text" id="HotWC3PolyStringText" value="" size="17" maxlength="16" onChange="" placeholder="权值的HEX字" title="HotWC3密钥流产生的权值HEX字">
<br>
<label class="labelblue" for="HotWC3DirStringText" onClick="GetDirStringText()" title="HotWC3密钥流产生的方向HEX字">方向字</label>
<input type="text" id="HotWC3DirStringText" value="" size="17" maxlength="16" onChange="" placeholder="方向的HEX字" title="HotWC3密钥流产生的方向HEX字">
<br>
<label class="labelblue" for="HotWC3InitStringText" onClick="GetInitStringText()" title="HotWC3密钥流产生的初值HEX字">初值字</label>
<input type="text" id="HotWC3InitStringText" value="" size="17" maxlength="16" onChange="" placeholder="初值的HEX字" title="HotWC3密钥流产生的初值HEX字">
<br>
<label class="labelblue" for="HotWC3XorOutStringText" onClick="GetXorOutStringText()" title="HotWC3密钥流产生的出值HEX字">出值字</label>
<input type="text" id="HotWC3XorOutStringText" value="" size="17" maxlength="16" onChange="" placeholder="出值的HEX字" title="HotWC3密钥流产生的出值HEX字">
<br>
<label class="labelblue" for="HotWC3DiffStringText" onClick="GetDiffStringText()" title="HotWC3密钥流产生的差分HEX字">差分字</label>
<input type="text" id="HotWC3DiffStringText" value="" size="17" maxlength="16" onChange="" placeholder="差分的HEX字" title="HotWC3密钥流产生的差分HEX字">
</div>
<div id="idhotwc3crcntest">
<label class="labelblue" for="HotWC3PloyStringText" title="标准CRC多项式字符串">多项式</label>
<input type="text" id="HotWC3PloyStringText" placeholder="标准CRC多项式字符串" title="标准CRC多项式字符串" onChange="TestPloyStringText()" value="CRC8=X8+X2+X+1" size="112">
<br>
<label class="labelblue" onClick="GetPloyNumberText()" for="HotWC3PloyNumberText" title="CRC多项式简写">简写式</label>
<input type="text" id="HotWC3PloyNumberText" placeholder="CRC多项式简写" title="CRC多项式简写" onChange="TestPloyNumberText()" value="CRC8L_07_00_00" size="75">
<input type="checkbox" id="HotWC3DiffCheck" checked="checked" title="差分检测">
<label class="labelblue" for="HotWC3DiffCheck" title="差分检测">差分检测</label>
<input type="button" id="HotWC3CRCPolyArrayEmpty" title="" onClick="HotWC3CRCPolyArrayEmpty()" value="清空密钥">
<input type="button" id="HotWC3CRCPolyArrayRandom" title="" onClick="HotWC3CRCPolyArrayRandom()" value="随机密钥">
<input type="button" id="HotWC3CRCPolyArrayDisturbance" title="" onClick="HotWC3CRCPolyArrayDisturbance();hotwc3dispassex()" value="扰动密钥">
<br>
<label class="labelblue" for="HotWC3MessageStringText" onClick="HotWC3MessageStringText.value=''" title="明文字符串的HEX流">明文流</label>
<input type="text" id="HotWC3MessageStringText" placeholder="明文字符串的HEX流" title="明文字符串的HEX流" onChange="" value="" size="112">
<br>
<label class="labelblue" for="HotWC3PassStringText" onClick="HotWC3PassStringText.value=''" title="密文字符串的HEX流">密文流</label>
<input type="text" id="HotWC3PassStringText" placeholder="密文字符串的HEX流" title="密文字符串的HEX流" onChange="" value="" size="112">
</div>
<p>
</p>
<div id="divHotWC3calculator">
<textarea cols="130" rows="4" id="wc3inputanalysis" onDblClick="ChangeidHotWC3inputTextBoxanalysis();wc3inputanalysisclipboard()" onChange="ChangeidHotWC3inputTextBoxanalysis()" placeholder="HotWC3密码加密明文分析" title="HotWC3密码加密明文分析"></textarea>
<label class="HotWC3inputanalysis">
<label class="labelblue" for="idbHotWC3inputPassCount" onClick="ChangeHotWC3inputTextBoxanalysisSet()" title="选择全屏12行">全屏</label>
<select id="idbHotWC3inputPassCount" size="1" onChange="ChangeHotWC3inputanalysisTextBox()" title="选择全屏表格行数">
<option value="4" selected="selected">4</option>
<option value="8"> 8</option>
<option value="12"> 12</option>
<option value="24"> 24</option>
</select>
<input type="button" id="idhotwc3inputpassanalysis" title="HotWC3密码明文弱密钥分析" onClick="hotwc3inputpassanalysis(1)" value="加密弱密钥">
<input type="button" id="idhotwc3inputpasscheck" title="HotWC3密码明文核验证分析" onClick="hotwc3inputpasscheck()" value="加密核验证">
<input type="button" id="idwc3inputclipboard" title="复制明文核验证到剪切板" onClick="wc3inputanalysisclipboard()" value="复制">
<input type="button" id="btnwc3inputanalysis" title="清空明文分析编辑框" onClick="wc3inputanalysis.value='';" value="清空">
<label class="labelblue" onClick="GetMessageRowStringText()" for="HotWC3MessageRowText" title="明文行号">明文行号</label>
<input type="number" id="HotWC3MessageRowText" onChange="GetMessageRowStringText()" placeholder="行" title="明文行号" min="1" max="1" value="1" size="4">
<label class="labelblue" onClick="GetMessageRowStringText()" for="HotWC3MessagePosText" title="字符位置">字符位置</label>
<input type="number" id="HotWC3MessagePosText" placeholder="位" title="字符位置" onChange="GetMessageRowStringText()" value="0" min="0" max="0" size="4">
<input type="range" id="HotWC3MessageRangeText" onChange="GetMessageRowStringText()" value="0" min="0" max="0" oninput="HotWC3MessagePosText.value=this.value">
<input type="button" id="HotWC3CRCDebugPassRefresh" title="" onClick="HotWC3CRCDebugPassRefresh()" value="刷新★">
<input type="button" id="HotWC3CRCDebugPassSetp" title="" onClick="HotWC3CRCDebugPassSetp()" value="单步▼">
<input type="button" id="HotWC3CRCDebugPassRun" title="" onClick="HotWC3CRCDebugPassRun()" value="连续▲">
</label>
<p>
</p>
<textarea cols="130" rows="4" id="wc3outputanalysis" onDblClick="ChangeidHotWC3outputTextBoxanalysis();wc3outputanalysisclipboard()" onChange="ChangeidHotWC3outputTextBoxanalysis()" placeholder="HotWC3密码解密密文分析" title="HotWC3密码解密密文分析"></textarea>
<label class="HotWC3outputanalysis">
<label class="labelblue" for="idbHotWC3outputPassCount" onClick="ChangeHotWC3outputTextBoxanalysisSet()" title="选择全屏12行">全屏</label>
<select id="idbHotWC3outputPassCount" size="1" onChange="ChangeHotWC3outputanalysisTextBox()" title="选择全屏表格行数">
<option value="4" selected="selected">4</option>
<option value="8"> 8</option>
<option value="12"> 12</option>
<option value="24"> 24</option>
</select>
<input type="button" id="idhotwc3outputpassanalysis" title="HotWC3密码密文弱密钥分析" onClick="hotwc3outputpassanalysis(1)" value="解密弱密钥">
<input type="button" id="idhotwc3outputpassckeck" title="HotWC3密码密文核验证分析" onClick="hotwc3outputpasscheck()" value="解密核验证">
<input type="button" id="idwc3outputclipboard" title="复制密文核验证到剪切板" onClick="wc3outputanalysisclipboard()" value="复制">
<input type="button" id="btnwc3outputanalysis" title="清空密文分析编辑框" onClick="wc3outputanalysis.value='';" value="清空">
<label class="labelblue" onClick="GetPassRowStringText()" for="HotWC3PassRowText" title="密文行号">密文行号</label>
<input type="number" id="HotWC3PassRowText" onChange="GetPassRowStringText()" placeholder="行" title="密文行号" min="1" max="1" value="1" size="4">
<label class="labelblue" onClick="GetPassRowStringText()" for="HotWC3PassPosText" title="字符位置">字符位置</label>
<input type="number" id="HotWC3PassPosText" placeholder="位" title="字符位置" onChange="GetPassRowStringText()" value="0" min="0" max="0" size="4">
<input type="range" id="HotWC3PassRangeText" onChange="GetPassRowStringText()" value="0" min="0" max="0" oninput="HotWC3PassPosText.value=this.value">
<input type="button" id="HotWC3CRCDebugDisPassRefresh" title="" onClick="HotWC3CRCDebugDisPassRefresh()" value="刷新★">
<input type="button" id="HotWC3CRCDebugDisPassSetp" title="" onClick="HotWC3CRCDebugDisPassSetp()" value="单步▼">
<input type="button" id="HotWC3CRCDebugDisPassRun" title="" onClick="HotWC3CRCDebugDisPassRun()" value="连续▲">
</label>
</div>
</fieldset>
<p>
</p>
<fieldset id="CRCSelectworkfieldset">
<legend onClick="fieldsethelp(3)">CRC选择</legend>
<div class="radioli">
<ul>
<li>
<input type="radio" name="radiobutton" id="radiocrc4_itu" onClick="selectStandCRC()" value="crc4_itu" title="">
<label class="labelblue" for="radiocrc4_itu">CRC4_ITU</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc8_pec" onClick="selectStandCRC()" value="crc8_pec" title="主要用于TI的SMBus电池管理系列的CRC8">
<label class="labelblue" for="radiocrc8_pec" title="主要用于TI的SMBus电池管理系列的CRC8">CRC8_PEC</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc8_maxim" onClick="selectStandCRC()" value="crc8_maxim" title="主要用于maxim的1-Wire系列的CRC8">
<label class="labelblue" for="radiocrc8_maxim" title="主要用于maxim的1-Wire系列的CRC8">CRC8_MAXIM</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc8_itu" onClick="selectStandCRC()" value="crc8_itu" title="">
<label class="labelblue" for="radiocrc8_itu">CRC8_ITU</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc8_rohc" onClick="selectStandCRC()" value="crc8_rohc" title="">
<label class="labelblue" for="radiocrc8_rohc">CRC8_ROHC</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc8_rohcx" onClick="selectStandCRC()" value="crc8_rohcx" title="">
<label class="labelblue" for="radiocrc8_rohcx">CRC8_ROHCx</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc12" onClick="selectStandCRC()" value="crc12" title="">
<label class="labelblue" for="radiocrc12">CRC12</label>
</li>
</ul>
<ul>
<li>
<input type="radio" name="radiobutton" id="radiocrc16" onClick="selectStandCRC()" value="crc16" title="">
<label class="labelblue" for="radiocrc16">CRC16</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc16_modbus" onClick="selectStandCRC()" value="crc16_modbus" title="MODBUS协议">
<label class="labelblue" for="radiocrc16_modbus" title="主要用于maxim的1-Wire系列的CRC8">CRC16_MODBUS</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc16_usb" onClick="selectStandCRC()" value="crc16_usb" title="">
<label class="labelblue" for="radiocrc16_usb">CRC16_USB</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc16_ccitt" onClick="selectStandCRC()" value="crc16_ccitt" title="">
<label class="labelblue" for="radiocrc16_ccitt">CRC16_CCITT</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc16_xmodem" onClick="selectStandCRC()" value="crc16_xmodem" title="">
<label class="labelblue" for="radiocrc16_xmodem">CRC16_XMODEM</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc16_zmodem" onClick="selectStandCRC()" value="crc16_zmodem" title="">
<label class="labelblue" for="radiocrc16_zmodem">CRC16_ZMODEM</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc16_ibm" onClick="selectStandCRC()" value="crc16_ibm" title="">
<label class="labelblue" for="radiocrc16_ibm">CRC16_IBM</label>
</li>
</ul>
<ul>
<li>
<input type="radio" name="radiobutton" id="radiocrc16_ibmx" onClick="selectStandCRC()" value="crc16_ibmx" title="">
<label class="labelblue" for="radiocrc16_ibmx">CRC16_IBMx</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc16_x25" onClick="selectStandCRC()" value="crc16_x25" title="">
<label class="labelblue" for="radiocrc16_x25">CRC16_X25</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc16_x25x" onClick="selectStandCRC()" value="crc16_x25x" title="">
<label class="labelblue" for="radiocrc16_x25x">CRC16_X25x</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc16_dnp" onClick="selectStandCRC()" value="crc16_dnp" title="">
<label class="labelblue" for="radiocrc16_dnp">CRC16_DNP</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc24" onClick="selectStandCRC()" value="crc24" title="">
<label class="labelblue" for="radiocrc24">CRC24</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc24" onClick="selectStandCRC()" value="crc24" title="">
<label class="labelblue" for="radiocrc24_ble">CRC24_BLE</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc32" onClick="selectStandCRC()" value="crc32" title="用途很广的CRC32">
<label class="labelblue" for="radiocrc32" title="用途很广的CRC32">CRC32</label>
</li>
</ul>
<ul>
<li>
<input type="radio" name="radiobutton" id="radiocrc32_jamcrc" onClick="selectStandCRC()" value="crc32_jamcrc" title="">
<label class="labelblue" for="radiocrc32_jamcrc">CRC32_JAMCRC</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc32_mpeg2" onClick="selectStandCRC()" value="crc32_mpeg2" title="适应于crc32_stm32">
<label class="labelblue" for="radiocrc32_mpeg2" title="适应于crc32_stm32">CRC32_MPEG2</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc32_bzip2" onClick="selectStandCRC()" value="crc32_bzip2" title="">
<label class="labelblue" for="radiocrc32_bzip2" title="">CRC32_BZIP2</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc32_sctp" onClick="selectStandCRC()" value="crc32" title="">
<label class="labelblue" for="radiocrc32_sctp" title="">CRC32_SCTP</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc48_etcs" onClick="selectStandCRC()" value="crc48_etcs" title="适应于欧洲铁路标准ETCS,用于铁路通信校验">
<label class="labelblue" for="radiocrc48_etcs" title="适应于欧洲铁路标准ETCS,用于铁路通信校验">CRC48_ETCS</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc64" onClick="selectStandCRC()" value="crc64" title="">
<label class="labelblue" for="radiocrc64">CRC64</label>
</li>
<li>
<input type="radio" name="radiobutton" id="radiocrc64_ecma" onClick="selectStandCRC()" value="crc64_ecma" title="">
<label class="labelblue" for="radiocrc64_ecma">CRC64_ECMA</label>
</li>
</ul>
</div>
<p>
</p>
<div>
<input type="radio" name="radiobutton" id="radioHotCRC" onClick="selectHotCRC()" checked="checked" value="radiobutton" title="选择CRC4~CRC64的32种HotCRC">
<label class="labelred" for="radioHotCRC" title="选择CRC4~CRC64的32种HotCRC">HotCRC</label>
<select size="1" id="selemode1" title="CRC左右移动方向快速切换" onChange="selectHotCRC()">
<option value="右移"> 右移</option>
<option value="左移" selected="selected"> 左移</option>
</select>
<select id="select1" onChange="selectHotCRC()" size="1" title="CRC运算位数选择">
<option value="CRC4"> CRC4</option>
<option value="CRC8"> CRC8</option>
<option value="CRC12"> CRC12</option>
<option value="CRC16" selected="selected"> CRC16</option>
<option value="CRC20"> CRC20</option>
<option value="CRC24"> CRC24</option>
<option value="CRC28"> CRC28</option>
<option value="CRC32"> CRC32</option>
<option value="CRC36"> CRC36</option>
<option value="CRC40"> CRC40</option>
<option value="CRC44"> CRC44</option>
<option value="CRC48"> CRC48</option>
<option value="CRC52"> CRC52</option>
<option value="CRC56"> CRC56</option>
<option value="CRC60"> CRC60</option>
<option value="CRC64"> CRC64</option>
</select>
<input type="button" id="savehotcrc" title="保存HotCRC多项式" onClick="SaveHotCRCPolyTable()" value="保存">
<input type="button" id="inithotcrc" title="初始化HotCRC多项式" onClick="LoadHotCRCPolyTable(1)" value="初始化">
<input type="checkbox" id="discheckbox" title="CRC算法可逆/不可逆选择, 系统自动测试" onClick="Changedischeck()" value="" checked="checked">
<label class="labelred" id="discheckboxlabel" for="discheckbox" title="CRC算法可逆/不可逆选择, 系统自动测试">可逆</label>
</div>
<div>
<select size="1" id="idselecodemode" title="文本编码格式,推荐采用HotCode" onChange="selecodemode()">
<option value="HEX" selected="selected">HEX</option>
<option value="" ascii""="">ASCII</option>
<option value="GB2312-80"> GB2312-80</option>
<option value="UniCode"> UniCode</option>
<option value="UTF-8"> UTF-8</option>
<option value="HotCode"> HotCode</option>
<option value="BASE64"> BASE64</option>
<option value="UUEncode"> UUEncode</option>
<option value="XXEncode"> XXEncode</option>
<option value="Quoted-printable"> Quoted-printable</option>
</select>
<label id="crcfiletypesele">
<input type="checkbox" id="crcfilecheckbox" title="CRC文件操作" onClick="crcfilecheckboxChange()" value="">
<label class="labelred" for="crcfilecheckbox" title="CRC文件操作">文件</label>
<select id="languagesele" value="1" size="1" onChange="" title="选择表格或C语言自动生成格式">
<option value=".TAB"> .TAB</option>
<option value=".C" selected="selected"> .C</option>
<option value=".SIM"> .SIM</option>
</select>
</label>
<select id="crctabsele" value="1" size="1" onChange="" title="选择表格格式或移位算法">
<option value="大表" selected="selected"> 大表</option>
<option value="小表"> 小表</option>
</select>
<select id="crcnxsele" value="1" size="1" onChange="" title="选择表格格式或逆向算法">
<option value="单表" selected="selected"> 单表</option>
<option value="双表"> 双表</option>
<option value="算法"> 算法</option>
</select>
</div>
<p>
</p>
<div>
<input type="button" id="strikbit" title="随机CRC碰撞,实际为明文碰撞" onClick="clearstrikbittext()" value="CRC碰撞">
<input type="button" id="polystrikbit" title="权值碰撞" onClick="polystrikbittext()" value="权值碰撞">
<input type="button" id="strikbitx" title="CRC初值碰撞,给定出值计算初值" onClick="startstrikbittext()" value="初值碰撞">
<input type="button" id="strikbity" title="CRC出值碰撞,给定初值计算出值" onClick="stopstrikbittext()" value="出值碰撞">
</div>
<div>
<label class="labelblue" for="idxortextvalue" title="">变异值</label>
<input type="text" id="xortextvalue" placeholder="" title="" onChange="" value="" size="10">
</div>
<div>
<input type="checkbox" id="anticheckbox" title="HotCRC高版本穷举选择明文反序" value="">
<label class="labelred" for="anticheckbox" title="HotCRC高版本穷举选择明文反序">反序</label>
<input type="checkbox" id="invercheckbox" title="HotCRC高版本穷举选择明文和结果倒置" value="">
<label class="labelred" for="invercheckbox" title="HotCRC高版本穷举选择明文和结果倒置">倒置</label>
<input type="checkbox" id="nxbigEndiancheckbox" title="HotCRC高版本穷举选择主编辑框内数据流中CRC校验和的数据存放格式" value="" checked="checked">
<label class="labelred" for="nxbigEndiancheckbox" title="HotCRC高版本穷举选择主编辑框内数据流中CRC校验和的数据存放格式">大端</label>
<input type="checkbox" id="nxknpolycheckbox" title="HotCRC高版本穷举选择可逆的权值穷举" value="">
<label class="labelred" for="nxknpolycheckbox" title="HotCRC高版本穷举选择可逆的权值穷举">可逆</label>
<input type="checkbox" id="nxshiftcheckbox" title="HotCRC高版本穷举选择自定义权值穷举" value="" checked="checked">
<label class="labelred" for="nxshiftcheckbox" title="HotCRC高版本穷举选择自定义权值穷举">自定</label>
<input type="checkbox" id="nxautocheckbox" title="HotCRC高版本穷举选择特定穷举初值出值为全0,5,A,F共8种组合搜索" value="" checked="checked">
<label class="labelred" for="nxautocheckbox" title="HotCRC高版本穷举选择特定穷举初值出值为全0,5,A,F共8种组合搜索">特定</label>
<input type="button" id="idnxcrcstart" title="HotCRC高版本穷举逆向主编辑框内数据流中的CRC多项式" onClick="nxcrcstart()" value="穷举">
</div>
<p>
</p>
<div>
<input type="button" value="功能" onClick="selefunction()" id="selefunction" title="CRC基本运算和CRC算法逆向快速切换">
<select size="1" id="operatorsele" title="HotCRC超级CRC计算器功能选择,所有功能性选择都在此选择后方能完成" onChange="changeoperator()">
<option value="0" selected="selected"> CRC基本运算</option>
<option value="1"> 异 或</option>
<option value="2"> 取 反</option>
<option value="3"> 与运算</option>
<option value="4"> 或运算</option>
<option value="5"> 左 移</option>
<option value="6"> 右 移</option>
<option value="7"> 加 法</option>
<option value="8"> 减 法</option>
<option value="9"> 数据反序</option>
<option value="10"> 数据反转</option>
<option value="11"> 保留功能</option>
<option value="12"> CRC表格或算法逆向</option>
<option value="13"> CRC表格或C语言</option>
<option value="14"> Unicode</option>
<option value="15"> GB2312-80</option>
<option value="16"> HotCode</option>
<option value="17"> ASCII</option>
<option value="18"> BASE64</option>
<option value="19"> UUEncode</option>
<option value="20"> XXEncode</option>
<option value="21"> Quoted-printable</option>
<option value="22"> UTF-8</option>
<option value="23"> 区位码</option>
</select>
</div>
<div>
<select size="1" id="idbsetuphelpsele" title="HotCRC超级CRC计算器帮助" onChange="selesetuphelp()" value="1">
<option value="0" selected="selected"> CRC运算</option>
<option value="1"> CRC表格或算法逆向</option>
<option value="2"> CRC表格或C语言</option>
<option value="3"> CRC手动碰撞</option>
<option value="4"> CRC碰撞</option>
<option value="5"> CRC初值碰撞</option>
<option value="6"> CRC出值碰撞</option>
<option value="7"> CRC表格碰撞</option>
<option value="8"> 特殊直角边口诀</option>
<option value="9"> 菜农星期公式及函数</option>
<option value="10"> 全屏显示操作</option>
<option value="11"> 多种编码</option>
<option value="12"> HotCode编码</option>
<option value="13"> CRC多项式</option>
<option value="14"> CRC多项式穷举</option>
<option value="15"> CRC多项式穷举速度</option>
<option value="16"> CRC多项式穷举规则</option>
<option value="17"> Hex文件CRC运算规则</option>
<option value="18"> 网页转换</option>
</select>
<select size="1" id="idbuttonhelpsele" title="HotCRC超级CRC计算器帮助" onChange="selebuttonhelp()" value="1">
<option value="0" selected="selected"> 名词解释</option>
<option value="1"> CRC运算</option>
<option value="2"> CRC还原</option>
<option value="3"> CRC明文</option>
<option value="4"> CRC密文</option>
<option value="5"> CRC结果</option>
<option value="6"> CRC权值</option>
<option value="7"> CRC初值</option>
<option value="8"> CRC出值</option>
<option value="9"> 初值出值取反</option>
<option value="10"> CRC碰撞</option>
<option value="11"> CRC初值碰撞</option>
<option value="12"> CRC出值碰撞</option>
<option value="13"> 穷举</option>
<option value="14"> 功能</option>
<option value="15"> 清空</option>
<option value="16"> CRC选择框</option>
<option value="17"> 穷举选择框</option>
</select>
</div>
</fieldset>
<p>
</p>
<fieldset class="fieldsetwidth" id="CRCCalculatorworkfieldset">
<legend onClick="fieldsethelp(4);text12.value=''">超级CRC计算器</legend>
<div>
<label class="labelblue" for="text150" title="标准CRC多项式字符串">多项式</label>
<input type="text" id="text150" placeholder="标准CRC多项式字符串" title="标准CRC多项式字符串" onChange="formattext150()" value="CRC16=X16+X12+X5+1" size="116">
<br>
<label class="labelblue" for="text160" title="CRC多项式简写">简写式</label>
<input type="text" id="text160" placeholder="CRC多项式简写" title="CRC多项式简写" onChange="formattext160()" value="CRC16L_1021_FFFF_0000" size="116">
<br>
<label class="labelblue" for="HotWC3DataBuffText" title="清空运算流">运算流</label>
<input type="text" id="HotWC3DataBuffText" onClick="" placeholder="明文在运算前内部存储排列的运算流" title="明文在运算时的运算流" onChange="" value="0123456789ABCDEF" size="116">
</div>
<p>
</p>
<div>
<input type="radio" name="moderadiobutton" id="radioTextMode" onClick="selectTextEditMode()" checked="checked" value="" title="选择明文为单行编辑框">
<label class="labelred" for="radioTextMode" id="labelTextMode" title="选择明文为单行编辑框">单行</label>
<input type="radio" name="moderadiobutton" id="radioHexMode" onClick="selectTextEditMode()" checked="" value="" title="选择明文为多行编辑框">
<label class="labelblue" for="radioHexMode" id="labelHexMode" title="选择明文为多行编辑框">多行</label>
<input type="radio" name="moderadiobutton" id="radioTableMode" onClick="selectTextEditMode()" checked="" value="" title="选择明文为表格编辑框">
<label class="labelblue" for="radioTableMode" id="labelTableMode" title="选择明文为表格编辑框">表格</label>
<input type="checkbox" id="displayout" title="选择在主编辑框内是否显示运行结果" onClick="Changedisplayout()" value="" checked="checked">
<label class="labelred" id="displayoutlabel" for="displayout" title="选择在主编辑框内是否显示运行结果">显示</label>
<label class="labelblue" for="idbTextBoxCount" onClick="ChangeTextBoxSet()" title="选择全屏文本12行">全屏</label>
<select id="idbTextBoxCount" size="1" onChange="ChangeTextBox()" title="选择全屏文本行数">
<option value="4" selected="selected"> 4</option>
<option value="8"> 8</option>
<option value="12"> 12</option>
<option value="24"> 24</option>
<option value="48"> 48</option>
</select>
<input type="button" id="idclearTextBox" title="清空编辑缓冲区" onClick="clearTextBox()" value="清空">
<input type="text" id="crceditcount" value="" size="5" maxlength="6" title="主编辑框字节数">
<label class="labelblue" for="strikbittext" onclick="strikbittext.value='0'" title="CRC明文的尾半字节位域4屏蔽位,数字F时选择3变8,2变C,1变E">明文长度</label>
<input type="text" id="strikbittext" title="CRC明文的CRC位域4碰撞位数(半字节个数)" value="0" size="3">
<label class="labelblue" for="idHexEditBoxCount" onClick="ChangeHexEditBoxSet()" title="选择全屏文本12行">全屏</label>
<select id="idHexEditBoxCount" size="1" onChange="ChangeHexEditBox()" title="选择全屏文本行数">
<option value="4" selected="selected"> 4</option>
<option value="8"> 8</option>
<option value="12"> 12</option>
<option value="24"> 24</option>
<option value="48"> 48</option>
</select>
</div>
<p>
</p>
<div>
<input type="button" id="idhexfilenameclear" title="清空文件名" onClick="" value="文件">
<input type="text" id="idhexfilename" placeholder="Hex文件需要输入的文件名" title="Hex文件需要输入的文件名" value="" size="93" maxlength="128">
<label id="labelHexEditMode" style="display:none">
<input type="button" id="idhexfileopen" title="打开文件" onClick="OpenHexFileName()" value="打开">
<input type="button" id="idhexfileWrite" title="写入文件" onClick="WriteHexFile()" value="写入">
<input type="button" id="idhexfileLoad" title="装载Hex文件到单行明文编辑框" onClick="LoadHexFormatText()" value="装载">
<input type="button" id="idhexfileCRCCalc" title="Hex文件CRC运算" onClick="LoadHexFileCRCCalc()" value="运算">
</label>
</div>
<p>
</p>
<div>
<label id="labelHexEditBox" style="display:none">
<textarea cols="130" rows="8" id="idHexEditBox" onDblClick="DblClickidHexEditBox()" onChange="ChangeidHexEditBox()" placeholder="Hex格式文件多行编辑框" title="Hex格式文件多行编辑框"></textarea>
<br>
</label>
<label id="labelHexCRCBox">
<input type="button" id="idinputtext" title="清空或随机明文" onClick="clearinputtext()" value="明文">
<input type="text" id="text12" autofocus="" value="0123456789ABCDEF" size="112" onChange="Changetext12()" onDblClick="DblClickOpenHexFile()" placeholder="待验证CRC的明文在上面的Hex格式文件多行编辑框内,特别注意:明文必须是Hex文件格式!!!" title="待验证CRC的明文">
<input type="button" id="idbcalculator" title="CRC正运算或生成位域8表格及算法等" onClick="calculator()" value="运算">
<br>
<input type="button" id="idoutputtext" title="清除或随机密文" onClick="clearoutputtext()" value="密文">
<input type="text" id="text13" placeholder="待验证CRC的密文" title="待验证CRC的密文" value="3A3FC39AC475986B" size="112" onChange="Changetext13()">
<input type="button" id="idbrevert" title="CRC逆运算或生成位域4表格及算法等" onClick="revert()" value="还原">
<br>
</label>
<input type="button" id="idresulttext" title="结果反转" onClick="clearresulttext()" value="结果">
<input type="text" id="text140" onChange="Changeresulttext()" placeholder="待验证CRC的结果" title="CRC运算结果输出,即CRC校验和的值" value="986B" size="19" maxlength="16">
<input type="button" value="权值" onClick="clearpolytext()" id="setpolytext" title="反转权值">
<input type="text" id="text130" placeholder="CRC权值" title="CRC权值" onChange="Changepolytext()" onKeyPress="input_onKeyPress()" value="1021" size="19" maxlength="16">
<input type="button" value="初值" onClick="clearinittext()" id="clearinittext" title="赋值初值为全0全F或随机数">
<input type="text" id="text120" placeholder="CRC初值" title="CRC输入XOR值,即CRC初值" onChange="ChangeInittext()" onKeyPress="input_onKeyPress()" value="FFFF" size="19" maxlength="16">
<input type="button" value="取反" onClick="button15()" id="button15" title="取反CRC输入XOR值">
<input type="button" value="出值" onClick="clearstoptext()" id="clearstoptext" title="赋值出值为全0全F或随机数">
<input type="text" id="text170" placeholder="CRC出值" title="CRC输出XOR值,即CRC出值" onChange="ChangeStoptext()" onKeyPress="input_onKeyPress()" value="0000" size="19" maxlength="16">
<input type="button" value="取反" onClick="button16()" id="button16" title="取反CRC输出XOR值">
</div>
</fieldset>
<p>
</p>
<fieldset class="fieldsetwidth" id="webconversionfieldset" style="display:none">
<legend onClick="fieldsethelp(1)">网页转换</legend>
<div class="divwebinputwork">
<textarea cols="65" rows="24" id="webinputconversion" onDblClick="Changeidwebinputconversion();webinputclipboard()" onChange="Changeidwebinputconversion()" placeholder="原始网页" title="原始网页"></textarea>
<label class="labwebinputconversion">
<label class="labelblue" for="idbHotWC3inputPassCount" onClick="ChangeidwebinputconversionSet()" title="选择全屏12行">全屏</label>
<select id="idwebinputconversionCount" size="1" onChange="ChangeidwebinputconversionTextBox()" title="选择全屏表格行数">
<option value="4">4</option>
<option value="8"> 8</option>
<option value="12"> 12</option>
<option value="24" selected="selected"> 24</option>
<option value="48"> 48</option>
</select>
<label class="labelblue" for="idbWebTextRowStartTime" title="开始时间">时间</label>
<input type="text" id="idbWebTextRowStartTime" value="" size="10" maxlength="" onKeyPress="" title="开始行号">
<label class="labelblue" for="idbWebTextRowStart" title="开始行号">开始</label>
<input type="text" id="idbWebTextRowStart" value="" size="6" maxlength="8" onKeyPress="" title="开始行号">
<label class="labelblue" for="idbWebTextRowSize" onClick="idbWebTextRowSize.value='';idbWebTextRowStart.value=''" title="每次需要压缩的行数">间隔数</label>
<input type="text" id="idbWebTextRowSize" value="" size="6" maxlength="8" onKeyPress="" title="每次需要压缩的行数">
<label class="labelblue" for="idbWebTextRowLength" onClick="idbWebTextRowLength.value=Changeidwebinputconversion()" title="压缩前的总行数">总行数</label>
<input type="text" id="idbWebTextRowLength" value="" size="6" maxlength="8" onKeyPress="" title="压缩前的总行数">
<input type="button" value="网页压缩" onClick="WebOnlineCompressor()" id="idWebOnlineCompressor" title="网页压缩">
<input type="button" value="文本转换" onClick="WebOnlineHELPTextCompressor()" id="idWebOnlineHelpText" title="网页文本转换">
<input type="checkbox" id="idWebOnlineMessageText" title="选择网页信息在主编辑框显示重要信息">
<label class="labelblue" for="idWebOnlineMessageText" title="选择网页信息在主编辑框显示重要信息">网页信息</label>
</label>
</div>
<p>
</p>
<div class="divweboutputwork">
<textarea cols="65" rows="24" id="weboutputconversion" onDblClick="Changeidweboutputconversion();weboutputclipboard()" onChange="Changeidweboutputconversion()" placeholder="转换后的网页" title="转换后的网页"></textarea>
<label class="labwebinputconversion">
<label class="labelblue" for="idbHotWC3outputPassCount" onClick="ChangeidweboutputconversionSet()" title="选择全屏12行">全屏</label>
<select id="idweboutputconversionCount" size="1" onChange="ChangeidweboutputconversionTextBox()" title="选择全屏表格行数">
<option value="4" selected="selected">4</option>
<option value="8"> 8</option>
<option value="12"> 12</option>
<option value="24"> 24</option>
<option value="48"> 48</option>
</select>
<label class="labelblue" for="idbWebTextRowTimeCount" title="结束时间">计时</label>
<input type="text" id="idbWebTextRowTimeCount" value="" size="10" maxlength="" onKeyPress="" title="结束时间">
<label class="labelblue" for="idbWebTextRowCount" title="压缩后的行数">行数</label>
<input type="text" id="idbWebTextRowCount" value="" size="6" maxlength="8" onKeyPress="" title="压缩后的行数">
<label class="labelblue" for="idbWebTextRowTotal" onClick="idbWebTextRowTotal.value=Changeidweboutputconversion()" title="压缩后的字节数">字节数</label>
<input type="text" id="idbWebTextRowTotal" value="" size="6" maxlength="8" onKeyPress="" title="压缩后的字节数">
<input type="button" value="文本还原" onClick="WebOnlineHELPTextRestore()" id="idWebOnlineRestore" title="网页文本还原">
<input type="button" value="复制文本" onClick="weboutputclipboard()" id="idWebOnlineCopy" title="复制网页文本">
<input type="checkbox" id="idWebOnlineMessagePackText" checked="checked" title="压缩信息">
<label class="labelblue" for="idWebOnlineMessagePackText" title="压缩信息">压缩信息</label>
</label>
</div>
</fieldset>
<p>
</p>
<fieldset id="EditDisplayworkfieldset">
<legend onClick="clearTextBox()">编辑显示</legend>
<textarea cols="130" rows="8" id="idTextBox" onDblClick="DblClickidTextBox()" onChange="ChangeidTextBox()" placeholder="HotCRC主编辑框,穷举时在此按规则输入!" title="HotCRC主编辑框,请在此输入Hex文件CRC运算终极规则!!!"></textarea>
</fieldset>
<p>
</p>
<fieldset id="triangleworkfieldset">
<legend onClick="fieldsethelp(6)">特定直角三角形</legend>
<div id="triangleleftup">
<table>
<tbody><tr>
<td>
<input type="button" value="明文A" onClick="buttonc1()" id="buttonc1" title="清空或2位随机数的明文A">
</td>
<td>
<input type="text" id="text1" size="3" maxlength="2" onKeyPress="input_onKeyPress()" title="2位16进制数的直角边A的三角密码A">
</td>
<td>
<input type="button" value="加密" onClick="button1()" id="button1" title="由明文A加密得到密文BC">
</td>
<td>
<input type="button" value="密文BC" onClick="buttonc2()" id="buttonc2" title="清空或4位随机数的密文BC">
</td>
<td>
<input type="text" id="text2" size="5" maxlength="4" onKeyPress="input_onKeyPress()" title="4位16进制数的直角边B和斜边C变换后的三角密码BC">
</td>
<td>
<input type="button" value="解密" onClick="button2()" id="button2" title="由密文BC解密出明文A">
</td>
<td>
<label class="labelblue" for="text6" title="10进制数的直角三角形角度">角度</label>
</td>
<td>
<input type="text" id="text6" size="8" maxlength="0" onKeyPress="input_onKeyPress()" title="10进制数的直角三角形角度">
</td>
<td>
<input type="button" value="查表" onClick="gettriangletable()" title="菜农编制的2字节长度三角密码表">
</td>
</tr>
<tr>
<td>
<input type="button" value="短A" onClick="buttonc3()" id="buttonc3" title="清空或7位16进制随机数">
</td>
<td>
<input type="text" id="text3" title="7位16进制的直角三角形中短直角边A" onKeyPress="input_onKeyPress()" size="4" maxlength="7">
</td>
<td>
<input type="button" value="解BC" onClick="button3()" id="button3" title="已知短A求解长B和斜C">
</td>
<td>
<input type="button" value="长B" onClick="buttonc4()" id="buttonc4" title="清空或14位16进制随机数">
</td>
<td>
<input type="text" id="text4" size="6" maxlength="14" onKeyPress="input_onKeyPress()" title="14位16进制的直角三角形中长直角边B">
</td>
<td>
<input type="button" value="解AC" onClick="button4()" id="button4" title="已知长B求解短A和斜C">
</td>
<td>
<input type="button" value="斜C" onClick="buttonc5()" id="buttonc5" title="清空或14位16进制随机数">
</td>
<td>
<input type="text" id="text5" size="8" maxlength="14" onKeyPress="input_onKeyPress()" title="14位16进制的直角三角形中的斜边C">
</td>
<td>
<input type="button" value="解AB" onClick="button5()" id="button5" title="已知斜C求解短A和长B">
</td>
</tr>
</tbody></table>
</div>
<div id="triangleright">
菜农对特殊整数直角边勾股定理进行了归纳与总结如下<br>
当勾3股4弦5时,勾3的平方为9,9=4+5,故有股4弦5。<br>
当勾4股3弦5时,勾4的一半的平方为4,故有股3弦5。<br>
以此类推...<br>
<br>
故有特殊整数直角边勾股定理口诀:<br>
当直角边a(>=3)为奇数时,<br>另一直角边b为a平方砍半取整,斜边c比b大1。<br>
当直角边a(>=3)为偶数时,<br>另一直角边b为a砍半平方减1,斜边c比b大2。
</div>
<div id="triangleleftdn">
<input type="button" value="A问" onClick="ChkclrtextA()" id="btnclrtextA" title="清空或随机8位10进制数">
<input type="text" id="text7" title="8位10进制数的短直角边A=3~99999999" onClick="clrtext10()" value="3" size="8" maxlength="8">
<input type="button" value="B答" onClick="ChkclrtextB()" id="btnclrtextB" title="清空或随机16位10进制数">
<input type="text" id="text8" value="4" onClick="clrtext10()" size="16" maxlength="16" title="16位10进制数的长直角边B=4~4999999900000000">
<input type="button" value="C答" onClick="ChkclrtextC()" id="btnclrtextC" title="清空或随机16位10进制数">
<input type="text" id="text9" value="5" onClick="clrtext10()" size="16" maxlength="16" title="16位10进制数的斜边C=5~4999999900000001">
<br>
<input type="button" value="①" onClick="button61()" id="button61" title="10进制的1位随机数">
<input type="button" value="②" onClick="button62()" id="button62" title="10进制的2位随机数">
<input type="button" value="③" onClick="button63()" id="button63" title="10进制的3位随机数">
<input type="button" value="④" onClick="button64()" id="button64" title="10进制的4位随机数">
<input type="button" value="⑤" onClick="button65()" id="button65" title="10进制的5位随机数">
<input type="button" value="⑥" onClick="button66()" id="button66" title="10进制的6位随机数">
<input type="button" value="⑦" onClick="button67()" id="button67" title="10进制的7位随机数">
<input type="button" value="⑧" onClick="button68()" id="button68" title="10进制的8位随机数">
<input type="button" value="偷看答案" onClick="buttonc6()" id="button6" title="偷看答案,一般人只能算一些简单的,不偷看就是圣人了">
<input type="text" id="text11" value="0" size="2" maxlength="0" title="偷看次数显示">
<input type="button" value="得分" onClick="button7()" id="button7" title="给出得分">
<input type="text" id="text10" value="100" size="3" maxlength="0" title="分数">
</div>
</fieldset>
<p>
</p>
<fieldset id="linkworkfieldset">
<legend onClick="fieldsethelp(7)">友情链接</legend>
<label class="labelred" onClick="WebBrowse(0)" title="网上超级CRC计算器HotCRC">超级CRC计算器</label>
<label class="labelblue" onClick="WebBrowse(1)" title="访问21IC官网">21IC中国电子网</label>
<label class="labelred" onClick="WebBrowse(2)" title="访问21IC官网技术论坛">21ICBBS</label>
<label class="labelblue" onClick="WebBrowse(3)" title="HotWC3密码体系21IC论坛">21IC论坛交流</label>
<label class="labelred" onClick="WebBrowse(4)" title="【HotWC3密码交流QQ群】">QQ交流群</label>
<label class="labelblue" onClick="WebBrowse(5)" title="【微信公众号:菜农工具】">微信公众号</label>
<label class="labelred" onClick="WebBrowse(6)" title="【头条号:雁塔菜农】">头条号</label>
</fieldset>
<script language="VBScript">
<!--
Function AscToHexString(cstr)
dim i, str
str = ""
For i = 1 To Len(cstr)
str = str & Hex(Asc(Mid(cstr, i, 1)))
Next
AscToHexString = str
End Function
Function HexToAscString(cstr)
dim i, str
str = ""
i = 1
Do While i <= Len(cstr)
If Mid(cstr, i, 1) > "9" Then
str = str & Chr(hextoint(Mid(cstr, i, 4)))
i = i + 4
Else
str = str & Chr(hextoint(Mid(cstr, i, 2)))
i = i + 2
End If
Loop
HexToAscString = str
End Function
//EndHide-->
</script>
<script>
<!--Hide
function GetHotVersionCSVFile(str)
{
var ptr, version = "";
var i;
var strArray = new Array();
var varArray = new Array();
strArray = str.split("\r\n");
if(strArray.length >= 2){
str = strArray[0];
ptr = strArray[1];
strArray = str.split(",");
varArray = ptr.split(",");
if(strArray.length == varArray.length){
for(i = 0;i < strArray.length;i++){
if(version != ""){
version += "\n";
}
str = strArray[i];
if(str == "版本号") str = "版 本 号";
else if(str == "邮箱") str = "邮 箱";
else if(str == "微信号") str = "腾讯微信";
else if(str == "QQ号") str = "腾讯 QQ";
version += str + ": " + varArray[i];
}
}
}
return version;
}
function HotWC3AjaxDisplay(CommandId, str)
{
if(CommandId != ""){
if(CommandId != "idTextBox"){
document.getElementById(CommandId).value = str;
}
else{
document.getElementById(CommandId).value = GetHotVersionCSVFile(str);
// document.getElementById(CommandId).value = "晕!!!";
ChangeidTextBox();
}
}
else{
alert(str);
}
}
function GetXmlHttpObject()
{
var xmlhttp = null;
try{
xmlhttp = new XMLHttpRequest();
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxm12.XMLHTTP");
}
catch(e){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlhttp;
}
function HotWC3Ajax(CommandId, CommandName, Value)
{
if(TestWF() && TestOL()){//在线//http://web7363356.sxphp56.badudns.cc/audio/HotWC3_V2.20.htm
var str = CommandName + "-" + Value;
var xmlhttp = GetXmlHttpObject();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
str = this.responseText;
if(str == ""){
HotWC3AjaxDisplay("", "网站Ajax返回空结果!!!");
}
else{
var strArray = new Array();
strArray = str.split("-");
if(strArray.length > 1){//必须有2个内容以上
if(strArray[0] == CommandName){//收到正确命令的回复
if(CommandName == "HotWC3_Count"){
HotWC3AjaxDisplay(CommandId, strArray[1]);
}
else if(CommandName == "HotWC3_ReadFile"){//其它命令
HotWC3AjaxDisplay(CommandId, strArray[1]);
}
}
else{
CommandName = strArray[0];
if(CommandName == "HotWC3_Error"){
CommandName += ":" + strArray[1];//以冒号隔开
HotWC3AjaxDisplay(CommandId, CommandName);
}
}
}
}
}
};
xmlhttp.open("GET", "HotWC3_Ajax.php?q=" + str, true);
xmlhttp.send();
}
}
//EndHide-->
</script>
<script>
<!--Hide
var text140text;
var text140Count = 0;
var datevar = new Date();
var seevalue0 = 0, seevalue1 = 0;
var HotWC3PloyStringTextBack = "CRC8=X8+X2+X+1";
var HotWC3PloyNumberTextBack = "CRC8L_07_00_00";
var HotCRCPolyTableArray = new Array();
var HotWC3CRCTextString = new Array();
var HotWC3CRCWorkString = new Array();
var HotWC3CRCPolyString = new Array();
var setTimeoutID;
var _count_arg, _count_argc, _count_argcx;
var _text_array = new Array();
var g_polyarraystring = new Array();
var g_start, g_length, g_respolystring;
var g_polylstcount, g_formatstring = "";
var g_polystart, g_polystop;
var g_initcount, g_initstart, g_initstop;
var g_xorcount, g_xorstart, g_xorstop;
var g_text120_value;
var initArray = new Array();//初值数组
var xorArray = new Array();//变异数组
var g_textmode = 0;
var HotCRCPolyInitTableArray = new Array();
//多项式的兄弟
HotCRCPolyInitTableArray[0x00] = "CRC8L_07_00_FD";//
HotCRCPolyInitTableArray[0x01] = "CRC8R_8C_00_F7";
HotCRCPolyInitTableArray[0x02] = "CRC12L_80F_000_000";
HotCRCPolyInitTableArray[0x03] = "CRC16R_A001_0000_C001";//MODBUS
HotCRCPolyInitTableArray[0x04] = "CRC16L_1021_0000_F01F";
HotCRCPolyInitTableArray[0x05] = "CRC16L_8005_0000_8003";
HotCRCPolyInitTableArray[0x06] = "CRC16R_8408_0000_F80F";
HotCRCPolyInitTableArray[0x07] = "CRC16L_1021_0000_0000";
HotCRCPolyInitTableArray[0x08] = "CRC16L_1021_0000_F01F";
HotCRCPolyInitTableArray[0x09] = "CRC24L_864CFB_B704CE_000000";
HotCRCPolyInitTableArray[0x0a] = "CRC32R_EDB88320_FFFFFFFF_FFFFFFFF";
HotCRCPolyInitTableArray[0x0b] = "CRC32R_EDB88320_FFFFFFFF_00000000";
HotCRCPolyInitTableArray[0x0c] = "CRC32L_04C11DB7_FFFFFFFF_00000000";
HotCRCPolyInitTableArray[0x0d] = "CRC48L_D28DB3FA4AAD_000000000000_000000000000";
HotCRCPolyInitTableArray[0x0e] = "CRC64R_D800000000000000_0000000000000000_0000000000000000";
HotCRCPolyInitTableArray[0x0f] = "CRC64L_42F0E1EBA9EA3693_FFFFFFFFFFFFFFFF_FFFFFFFFFFFFFFFF";
//EndHide-->
</script>
<script>
<!--Hide
function BrowseFlowchart()
{
var str;
// var ptr = "http://web7363356.sxphp56.badudns.cc/HotPower/HotWC3_V" + (radiohotwc3version1.checked ? "1":"2") + ".0.png";
str = "http://www.21ic.com/tools/HotPower/HotWC3_V" + (radiohotwc3version1.checked ? "1":"2") + ".0.png";
// window.location.target = "_blank";
// window.location.href = str;
if(TestWF()){
window.open(str,"_blank");
}
else{
alert("无网络,不能观看网络图片:\n"+str);
}
hotwc3wificheckbox.checked = TestWF();
// if(!window.open(str,"_blank")) window.open(ptr,"_blank");
}
function WebBrowse(index)
{
//https://jsmin.51240.com/
//var strArray = ["http://www.21ic.com/tools/HotPower/HotWC3.html", "http://www.21ic.com/tools/HotPower/HotCRC.html", "http://www.21ic.com/", "https://bbs.21ic.com/", "https://bbs.21ic.com/forum.php?mod=forumdisplay&fid=137", "http://qm.qq.com/cgi-bin/qm/qr?k=fQreX2IjbBdOaHc9yKHzfashJYuREUEb","http://www.21ic.com/tools/HotPower/HotWC3_CRC.png", "http://m.toutiao.com/profile/3995409288/"];
var strArray = ["http://www.hotcrc.com", "http://www.21ic.com/", "https://bbs.21ic.com/", "https://bbs.21ic.com/forum.php?mod=forumdisplay&fid=137", "http://qm.qq.com/cgi-bin/qm/qr?k=fQreX2IjbBdOaHc9yKHzfashJYuREUEb","http://www.21ic.com/tools/HotPower/HotWC3_CRC.png", "http://m.toutiao.com/profile/3995409288/"];
var str = strArray[index];
if((index < 8) && TestWF()){
window.open(str,"_blank");
}
else{
alert("无网络,不能链接网站:" + str);
}
hotwc3wificheckbox.checked = TestWF();
}
//EndHide-->
</script>
<script>
<!--Hide
function isExitsFunction(funcName)
{
var result = false;
try{
if(typeof(eval(funcName)) == "function"){
result = true;
}
}
catch(e){
// result = false;
}
return result;
}
function nxcrcstart()
{
if(isExitsFunction("nxcrcstartEx")){
nxcrcstartEx();
}
else{
HotWC3_V1_23_exhelp();
}
}
function HotWC3_V1_23_exhelp()
{
var str = "";
EditDisplayworkfieldset.style.display = "";//编辑显示
str += "HotCRC_V1.23版本重点是超级CRC计算器\n";
str += "因为穷举主要是逆向CRC类的通讯协议,已经超出了学习CRC的范畴,故本版本加以取缔。\n";
str += "\n";
str += "如若真有需求,可以通过HotPower@163.com联系菜农\n";
str += "菜农为推广HotWC3密码体系和HotCRC超级CRC计算器,特地组建了QQ群进行交流。\n";
str += "菜农HotWC3密码交流QQ群号:203534415.\n";
str += "菜农技术交流QQ号:1270688699。\n";
str += "\n";
str += "菜农HotPower[url=home.php?mod=space&uid=516618]@163.com[/url] 2023.3.18 于西安雁塔菜地";
idTextBox.value = str;
ChangeidTextBox();
}
function selesetuphelp()
{
var str = "";
if(!displayout.checked) return;
EditDisplayworkfieldset.style.display = "";//编辑显示
switch(idbsetuphelpsele.selectedIndex)
{
case 0://CRC运算
str += "HotCRC本身就是一个超级CRC计算器,它支持常见的26种CRC运算,并且提供支持32种任意CRC运算的HotCRC。\n";
str += "操作非常简单:\n";
str += "1.功能选择\"CRC基本运算\",选择标准的CRC或\"HotCRC\"(需要选择\"左移\"或\"右移\"和\"CRC4-CRC64\",非特殊要求,\"可逆\"请不要干预!!!\n";
str += "2.点击\"运算\"按钮,在\"结果\"编辑框内查看结果即可。\n";
str += "HotWC3超级CRC计算器将为您展示在CRC科目上所有您需要和未知的一切,它绝对超出您的期望!!!\n\n";
str += "菜农HotPower[url=home.php?mod=space&uid=516618]@163.com[/url] 2023.3.18 于西安雁塔菜地";
break;
case 1://CRC逆向
str += "CRC表格或算法逆向,可分为**CRC表格或**第三方CRC计算器。\n";
str += "功能选择\"CRC表格或算法逆向\",选择\"算法\"表示选择\"CRC算法\"逆向。选择\"大表\",\"小表\"和\"双表\"等组合表示选择\"CRC表格\"逆向。\n";
str += "\n";
str += "**CRC表格的CRC多项式步骤:\n";
str += "1.选择\"大表\",\"小表\"和\"双表\"等组合。\n";
str += "2.点击\"采样\",会在主编辑框内生成对应多项式的CRC表格,你可以把第三方的CRC表格复制粘贴上去。\n";
str += "特别注意:\n";
str += "表格逆向时,主编辑框内表格必须用大括号{}包含(可以是双表),内部必须有大表256小表16个数据,数据可以是10进制或16进制混用。\n";
str += "3.点击\"**\",会自动提示**的结果。\n";
str += "\n";
str += "**第三方CRC运算器的CRC多项式步骤:\n";
str += "1.选择HotCRC,CRC4-CRC64,左右移方向不用干预。\n";
str += "2.功能选择\"CRC表格或算法逆向\",选择\"算法\"。\n";
str += "3.点击\"采样\",得到一组明文,将其四等份。分四次在第三方CRC计算器上得到四个结果依次组成字符串并填写到\"密文\"编辑框内。\n";
str += "4.点击\"**\"按钮,结果处会提示逆向是否成功。成功,则第三方CRC计算器是标准的CRC。\n";
str += "5.选择功能\"CRC基本运算\",在明文处任意输入,点击运算,得到CRC结果和第三方CRC运算器比较即可。\n";
str += "特别注意:算法逆向时,**成功但提示发生初值出值碰撞,表示权值**成功,但无法确定初值和出值,需要穷举初值!!!\n";
str += "HotWC3_V1.23以上高版本支持5点攻击,即把明文(前4份明文整个部分)再采样1次的结果填写到密文尾部作为第5个结果\n";
str += "然后点击**,提示逆向成功,但发生初值出值碰撞时再点击穷举!!!\n";
str += "\n";
str += "如果为了穷举初值和出值,但采样为4点时,可以再次点击采样按钮得到第5点结果。然后再点击穷举按钮。";
break;
case 2://CRC表格或C语言
str += "CRC多项式表格或C语言自动生成:\n";
str += "HotWC3支持C语言的CRC表格和完整的表格函数及移位算法等5种C语言源码的自动生成,并且提供源码仿真过程。在IE核浏览器上支持文件操作。\n";
str += "选择\".TAB\"为C语言表格,选择\".C\"为表格加C语言表格函数源码。\n";
str += "选择\".SIM\"为表格加C语言表格函数源码及源码仿真。\n";
str += "CRC移位算法可选择\"算法\"。\n";
str += "CRC表格分为大表,小表和单表,双表等4种组合,它们与CRC的初值和出值无关(初值和出值都默认为零)。\n";
str += "大表每表256个数据,它是当前CRC多项式下明文0x00-0xFF经过CRC运算后256个对应结果集合的表格。\n";
str += "小表每表16个数据,它是当前CRC多项式下,\n";
str += "左移CRC时明文0x00-0x0F,右移CRC时明文0x00,0x10,…0xE0,0xF0经过CRC运算后16个对应结果集合的表格。\n";
str += "大表是小表运行速度的一倍,但表格大了16倍。小表是MCU最佳的选择。\n";
str += "移位运行速度最慢。\n";
str += "特别注意:\n";
str += "CRC查表法的运行速度是CRC移位算法的数倍,例如CRC16,前者是后者的8倍。\n";
str += "双表特别适合单片机,它降低了访问数据类型的宽度。\n";
str += "具体操作步骤:\n";
str += "1.选择标准CRC或HotCRC,左移或右移和CRC4-CRC64。\n";
str += "2.功能选择CRC表格或C语言,格式选择\".TAB\",\".C\"。\n";
str += "3.表格选择\"大表\"或\"小表\",CRC表格数组宽度为256或16。“算法”或“双表”及“单表”决定是否移位或查表算法。\n";
str += "4.点击\"生成\"即可得到对应的CRC表格或完整的C语言表格函数程序。\n";
str += "特别注意:\n";
str += "被校验的数据要填写到明文编辑框内,格式可以16进制数或字符编码如英文或汉字。\n";
str += "HotWC3支持对C语言的表格函数仿真,只要选择\".SIM\"即可,它会列出非常详细的运行步骤。";
break;
case 3://CRC手动碰撞
str += "CRC手动碰撞具体操作步骤:\n";
str += "1.功能选择CRC基本运算,选择标准的CRC或HotCRC自定义,最好非文本方式。\n";
str += "2.在明文处输入一组字符串,权值长度的倍数。例如CRC8为一个字节2个HEX数,CRC16为4个,依此类推。\n";
str += "3.点击\"运算\",得到密文字符串,保留最后一组CRCn(权值长度)不得改写,例如CRC8最后2个HEX不得改写,CRC16为4个。任意改写其它数据。\n";
str += "4.点击\"还原\",明文将会变为新的字符串,即发生了CRC碰撞。\n";
str += "5.再点击\"运算\",结果将不会改变,即验证了是否发生了CRC碰撞。";
break;
case 4://CRC碰撞
str += "CRC碰撞具体操作步骤:\n";
str += "1.功能选择\"CRC基本运算\",选择标准的CRC或HotCRC自定义,最好非文本方式。\n";
str += "2.在明文处输入一组字符串,权值长度的倍数。例如CRC8为一个字节2个HEX数,CRC16为4个,依此类推。\n";
str += "3.点击\"运算\",得到密文字符串。\n";
str += "4.点击\"CRC碰撞\",明文和密文都将会变为新的字符串,但结果不变,即发生了CRC碰撞。\n";
str += "5.再点击\"运算\",结果将不会改变,即验证是否发生了CRC碰撞。";
break;
case 5://CRC初值碰撞
str += "CRC初值碰撞具体操作步骤:\n";
str += "1.功能选择\"CRC基本运算\",选择标准的CRC或HotCRC自定义,最好非文本方式。\n";
str += "2.在明文处输入一组字符串,长度不限。\n";
str += "3.点击\"运算\",得到密文字符串和结果,。\n";
str += "4.给定出值后点击\"CRC初值碰撞\",明文和结果及出值不变,初值变化,即发生了CRC初值碰撞。\n";
str += "5.再点击\"运算\",结果将不会改变,即验证是否发生了CRC初值碰撞。";
break;
case 6://CRC出值碰撞
str += "CRC出值碰撞具体操作步骤:\n";
str += "1.功能选择\"CRC基本运算\",选择标准的CRC或HotCRC自定义,最好非文本方式。\n";
str += "2.在明文处输入一组字符串,长度不限。\n";
str += "3.点击\"运算\",得到密文字符串和结果,。\n";
str += "4.给定初值后点击\"CRC出值碰撞\",明文和结果及出值不变,出值变化,即发生了CRC出值碰撞。\n";
str += "5.再点击\"运算\",结果将不会改变,即验证是否发生了CRC出值碰撞。";
break;
case 7://CRC多项式或表格碰撞
str += "CRC多项式或表格碰撞:\n";
str += "由于CRC归类为单向散列陷门函数,故不同CRC多项式(权值)可能会共有一张CRC表格,即发生了CRC多项式碰撞。\n";
str += "在穷举CRC多项式时,非常容易发生CRC多项式碰撞。\n";
str += "而在逆向CRC表格时,非常容易发生CRC表格碰撞,即大表或小表碰撞。";
break;
case 8://直角三角形
str += "特殊(三个整数直角边)直角边口诀是菜农对特殊整数直角边勾股定理的归纳与总结。\n";
str += "古人云:勾3股4弦5。那么勾4股3弦5肯定也是成立的。\n";
str += "那么:勾5股X弦X,勾6股X弦X,勾7股X弦X,勾8股X弦X...\n";
str += "当勾3股4弦5时,勾的平方为9,4+5=9。而4和5恰巧就是股4弦5\n";
str += "当勾4股3弦5时,勾的一半的平方为4,而4的两旁就是3和5。而3和5恰巧就是股3弦5\n";
str += "我们按照这个规律推导,即可推导归纳全部特殊(三个整数直角边)直角边口诀\n";
str += "故有特殊直角边口诀:\n";
str += "当直角边a(>=3)为奇数时,另一直角边b为a平方砍半取整,斜边c比b大1\n";
str += "当直角边a(>=3)为偶数时,另一直角边b为a砍半平方减1,斜边c比b大2\n";
break;
case 9://菜农星期公式
str += " 星期公式说明:\n";
str += "下拉顶部的星期公式选择,会出现以下6种星期公式(1月2月是去年的13月14月,或5月6月,且年-1):\n";
str += "1.菜农星期公式:星期=((百年&3)*5+年+年/4+(13*月+8)/5+日)%7\n";
str += "2.蔡勒星期公式:星期=(203+百年/4-2*百年+年+年/4+(13*月+8)/5+日)%7\n";
str += "3.基姆拉尔森星期公式:星期=(百年/4+百年*5+年+年/4+(13*月+8)/5+日)%7\n";
str += "4.菜农第二星期公式:星期=((百年*5)%20+年+年/4+(13*月+8)/5+日)%7\n";
str += "5.菜农第三星期公式:(((日期/100)*5)%20+日期%100+(日期%100)4+(13*月+8)/5+日)%7\n";
str += "6.星期月表算法:星期=(百年%4*5+年+年/4+星期月表+日)%7。其中:星期月表=2503514620,3月为基月,3~12月,1,2月查5,6月表\n";
str += "更多说明请用百度或谷歌搜索:菜农星期公式揭秘及蔡勒公式推想\n\n";
str += " 星期公式函数:\n";
str += "function getweek(weeksele, century, year, month, day)\n";
str += "{\n";
str += " var week, dateval, table;\n";
str += " if (month <= 2)//1,2月变为去年的13,14月\n";
str += " {\n";
str += " year --;\n";
str += " if (year < 0)\n";
str += " {\n";
str += " year = 99;\n";
str += " century --;\n";
str += " if (century < 0)\n";
str += " {\n";
str += " century = 99;\n";
str += " }\n";
str += " }\n";
str += " month |= 4;//1,2月查5,6月表\n";
str += " // month += 12;//去年的13,14月\n";
str += " }\n";
str += " switch(weeksele)\n";
str += " {\n";
str += " case 0:\n";
str += " /*\n";
str += " 菜农星期公式\n";
str += " 星期=(百年%4*5+年+年/4+(13*月+8)/5+日)%7\n";
str += " */\n";
str += " week = ((century & 3) * 5 + year + (year >> 2) + Math.floor((13 * month + 8) / 5) + day) % 7;\n";
str += " break;\n";
str += " case 1:\n";
str += " /*\n";
str += " 蔡勒星期公式\n";
str += " 星期=(203+百年/4-2*百年+年+年/4+(13*月+8)/5+日)%7\n";
str += " */\n";
str += " week = (203 + Math.floor(century / 4) - 2 * century + year + (year >> 2) + Math.floor((13 * month + 8) / 5) + day) % 7;\n";
str += " break;\n";
str += " case 2:\n";
str += " /*\n";
str += " 基姆星期公式\n";
str += " 星期=(百年/4+百年*5+年+年/4+(13*月+8)/5+日)%7\n";
str += " */\n";
str += " week = (Math.floor(century / 4) + century * 5 + year + (year >> 2) + Math.floor((13 * month + 8) / 5) + day) % 7;\n";
str += " break;\n";
str += " case 3:\n";
str += " /*\n";
str += " 菜农第二星期公式\n";
str += " 星期=((百年*5)%20+年+年/4+(13*月+8)/5+日)%7\n";
str += " */\n";
str += " week = ((century * 5) % 20 + year + (year >> 2) + Math.floor((13 * month + 8) / 5) + day) % 7;\n";
str += " break;\n";
str += " case 4:\n";
str += " /*\n";
str += " 菜农第二星期公式\n";
str += " 星期=(((日期/100)*5)%20+日期%100+(日期%100)4+(13*月+8)/5+日)%7\n";
str += " */\n";
str += " dateval = century * 100 + year;\n";
str += " week = ((Math.floor(dateval / 100) * 5) % 20 + year + (year >> 2) + Math.floor((13 * month + 8) / 5) + day) % 7;\n";
str += " break;\n";
str += " case 5:\n";
str += " /*\n";
str += " 星期公式月表\n";
str += " 星期=(百年%4*5+年+年/4+星期月表+日)%7\n";
str += " */\n";
str += " table = \"2503514620\";//3月为基月,3~12月,1,2月查5,6月表\n";
str += " week = ((century & 3) * 5 + year + (year >> 2) + parseInt(table.substr(month-3, 1), 10) + day) % 7;\n";
str += " break;\n";
str += " }\n";
str += " return week;\n";
str += "}";
break;
case 10://全屏显示
str += "全屏帮助行任意伸缩主要方便多行帮助信息的查看:\n";
str += "1.选中全屏模式打钩。\n";
str += "2.可以下拉选中行数4,8,12,24,32,48,100.\n\n";
str += "特别注意:";
str += "\n";
str += "\"显示\"选择钮打钩表示运行结果可以输出到最下面的主编辑框内。一般不要干预。";
break;
case 11://Code
str += "HotWC3超级CRC计算器还支持多种编码的编解码运算:\n";
str += "汉字编码:\n";
str += "1.ASCII码。\n";
str += "2.GB2312-80(在IE浏览器上)。\n";
str += "3.区位码(在IE浏览器上)。\n";
str += "4.Unicode。\n";
str += "5.UTF-8。\n";
str += "6.HotCode(菜农自创)。\n";
str += "常用数据编码:\n";
str += "1.BASE64。\n";
str += "2.UUEncode。\n";
str += "3.XXEncode(菜农参见BASE64以=号填充以满足解码的还原)。\n";
str += "4.Quoted-printable。\n";
str += "只要功能选择某种编码即可进行编解码运算";
break;
case 12://HotCode
str += "HotCode汉字编码(V1.0)是菜农对UniCode编码(V5.0)的汉字简化版本:\n";
str += "1.用0080-00ff替换2580-25ff方块元素几何图形。\n";
str += "2.用f900-faff替换2c00-2dff格拉哥里字母等。\n";
str += "3.用fe30-fe4f替换9fc0-9fdf未定义。\n";
str += "4.用ff00-ffff替换2800-28ff盲文点字模型。\n";
str += "HotCode选中unicode2000-9fff为编码范围,\n";
str += "然后加6000,使HotCode编码范围为8000-ffff,ascii码为00-7f。\n";
str += "HotCode编码汉字为两字节,字符为单字节。";
break;
case 13://CRC多项式
str += "HotWC3超级CRC计算器可用下列不同方法给出CRC多项式:\n";
str += "1.选择2种HotWC3支持的标准CRC。\n";
str += "2.选择32种HotCRC,并且选定左移或右移和CRC4-CRC64,然后:\n";
str += "a.直接改写多项式框。\n";
str += "b.直接改写简写框。\n";
str += "c.直接改写权值框。\n";
str += "特别注意:初值和出值与CRC多项式无关。";
break;
case 14://CRC多项式穷举
str += "强烈建议用谷歌浏览器其次是火狐浏览器穷举!!!IE浏览器穷举速度过长!!!\n";
str += "HotWC3超级CRC计算器穷举CRC多项式,即利用CRC多项式碰撞原理来逆向。\n";
str += "1.选择HotCRC,左移或右移,CRC4-CRC64,CRC大小端,自动。\n";
str += "2.点击\"清空\"按钮清空主编辑框。\n";
str += "3.在主编辑框输入待逆向的CRC数据流,最尾部为CRC校验和。放置顺序可打钩或不打钩\"大端\"。\n";
str += "4.打钩\"自定\",权值选择当前权值。不打钩\"自定\",从当前权值开始穷举。\n";
str += "5.打钩\"特定\",初值(出值)选择全0,5,A,F。不打钩\"特定\",取当前初值。\n";
str += "6.点击\"穷举\",穷举结束后,最好取\"可信度高\"的CRC简写式,然后复制粘贴到\"简写式\"编辑框内。\n";
str += "7.点击停止,终止CRC多项式穷举。\n";
str += "\n";
str += "特别注意:\n";
str += "CRC大小端表示CRC值的放置顺序,例如0x1234,大端是1234,小端是3412。\n";
str += "选择\"特定\"是指初值出值全0,5,A,F共8个组合的变化。\n";
str += "不选择\"特定\"则为当前的初值固定不变,出值自动计算。\n";
str += "\n";
str += "CRC多项式穷举便捷操作:\n";
str += "1.先按以上选择。\n";
str += "2.点击清空。\n";
str += "3.点击穷举,在弹出框后选择是。\n";
str += "4.将需要穷举的数据和结果流覆盖前三行。\n";
str += "5.点击穷举,开始穷举。\n";
str += "6.穷举成功后,将CRC简写式覆盖到\"简写式\"编辑框内。\n";
str += "7.在明文处输入数据,点击运算得到结果验算CRC是否穷举正确。";
break;
case 15://CRC多项式穷举速度比较
str += "2FE8D6D45E1D5C24B87A2B6B17F4B1F0\n";
str += "B8ED544F9094B58BD1AD2909F22AB74F3E\n";
str += "0452C9C679D07C5C0B9E6393F7E7\n";
str += "9FF1-A001\n";
str += "0000#\n";
str += "$,,,!,LA\n";
str += "$,,,!,La\n";
str += "$,,,!,RA\n";
str += "$,,,!,Ra\n";
str += "\n";
str += "2345浏览器(谷歌核): 21秒\n";
str += "遨游5浏览器 25秒\n";
str += "谷歌浏览器: 28秒\n";
str += "世界之窗浏览器: 30秒\n";
str += "360极速浏览器: 30秒\n";
str += "火狐浏览器: 72秒\n";
str += "Opera浏览器: 73秒\n";
str += "UC浏览器: 120秒\n";
str += "搜狗高速浏览器: 152秒\n";
str += "360安全浏览器: 202秒\n";
str += "2345浏览器(IE核): 300秒\n";
str += "IE8浏览器: 345秒";
break;
case 16://CRC多项式穷举规则
str += "HotCRC_V1.23以上版本穷举输入规则:\n";
str += "text\n";
str += "poly-poly\n";
str += "init-init#\n";
str += "$start,length,stop,!@Nn,1~9LRAaFDdPpKkYyNT,4~64\n";
str += "其中:\n";
str += "text为明文和结果流或结果和明文流(由stop的-+决定),可以多组,并可不等长。选用三组最佳,可以保证准确和快捷。\n";
str += "特别注意:明文流之间和结果可以用空格隔开。\n";
str += "poly为权值,可以多组多行,长度必须和权值等长。-表示对某段权值穷举(任意间隔运行不会崩溃)。\n";
str += "init为初值(出值),必须以#结尾,可以多组多行。-表示对某段初值的穷举。特别注意出值是由初值而决定的。\n";
str += "特别注意:每行之间可以用空格隔开,但不推荐。\n";
str += "$规则识别符号,可以多组。\n";
str += "start明文起始位置(>=0,从头开始向右)。\n";
str += "length明文长度(<=0,从结果开始向左)。\n";
str += "stop结果的终止位置(<=0,从尾开始向左,即明文和结果流)。\n";
str += "特别注意:\n";
str += "stop以+号开始且>=0,从头开始向右,即倒置,结果+明文流,而一般为明文流+结果。\n";
str += "!为有效明文的排列。\n";
str += "@NnFf有效明文的反序(小端,例如1234表示为0x3412)。\n";
str += "其中:\n";
str += "@表示截取后明文整个长度反序。\n";
str += "N表示和权值等长(CRCn)反序。\n";
str += "n表示数字16,20,...32,36,40,...64等,建议采用N。\n";
str += "特别注意:\n";
str += "!和@Nn是不分次序的(总是先排序后反序,与1.25不同)\n";
str += "1~9是排序步长,CRC4默认为1,其它默认为2,必须在首位。\n";
str += "L强制左移CRC。\n";
str += "R强制右移CRC。\n";
str += "A强制结果大端(例如1234表示为0x1234)。\n";
str += "a强制结果小端(反序,例如1234表示为0x3412)。\n";
str += "F强制结果错位(反转,例如1234表示为0x2C48)。\n";
str += "D显示所有的运行顺序标号和展开的全部数据流。\n";
str += "d只显示穷举成功的运行顺序标号和展开的全部数据流。\n";
str += "P当明文长度不是权值长度的倍数时要求穷举初值(非常耗时)。\n";
str += "p当明文长度不是权值长度的倍数时只要求穷举可信度高的初值(耗时但只做1/4)。\n";
str += "K为只取可逆(左移为奇数,右移为最高位为1)的权值。\n";
str += "k为所有权值(不要可逆的√)。\n";
str += "Y找到权值并可信立即退出穷举。\n";
str += "y只要找到权值立即退出穷举。\n";
str += "N表示对权值反转(特别注意不是反序,例如1021表示为0x8408)。\n";
str += "T表示通过等长明文的初值穷举,例如0000-FFFF#在等长明文时默认只需初值0000#,因为它穷举无意义,T参数取0000-FFFF#\n";
str += "4~64表示CRC4~CRC64。\n";
str += "Q表示穷举CRC简写式验证。\n";
str += "特别注意:\n";
str += "所有字母参数优先级都是先大写后小写,先L后R。\n";
str += "参数P和p都将穷举初值碰撞,对于不可逆CRC且明文长度不是权值长度的整数倍时,一个出值可能对应多组初值碰撞。\n";
str += "所有标注都可以省略,但是位置必须用英文的逗号隔断!";
break;
case 17://Hex文件CRC运算规则
str += "Hex文件CRC运算终极规则(版本V1.1):\n";
str += "本规则为为文件名和工作区域规则两个部分。\n";
str += "1.文件名规则:\n";
str += "filename(filelength16,filelength10,filldata16)\n";
str += "即:\n";
str += "文件名 (文件长度16进制,文件长度10进制,16进制数填充值,默认FF)\n";
str += "其中:\n";
str += "文件名是打开文件系统选择一个文件后自动给出的文件名。\n";
str += "目前版本filelength<0x10000,即64KB范围。\n";
str += "特别注意:\n";
str += "非IE浏览器打开的文件名路径名称可能不是真的文件路径。\n";
str += "文件长度用16进制和10进制两种格式给出,16进制以“0x”或“0X”开始。\n";
str += "填充值默认为FF,即熔丝未烧断。\n";
str += "特别注意:它被填写到“文件名编辑框”内,即原来“密文编辑框”的位置。\n";
str += "2.工作区域规则:\n";
str += "$worktop1-workbottom1,worktop2-workbottom2,checksum,address,crcnum;//text\n";
str += "即:\n";
str += "$工作区域1,工作区域2,校验和及定位地址,CRC运算区域号\n";
str += "其中:worktop1<=workbottom1<=work2top<=workbottom2<filelength\n";
str += "checksum是期望的CRC校验和,即CRC明文碰撞需要的CRC校验和,它在crcnum非0时有效。\n";
str += "例如当crcnum=1是,表示工作区域1被CRC保护,工作区域2为CRC明文碰撞区域。\n";
str += "假如没有发生碰撞,则工作区域2内的数据不会发生变化。\n";
str += "address是CRC运算结果的写入Hex文件的定位地址。\n";
str += "当checksum被省略时,表示将系统CRC运算的结果填入address开始的区域。\n";
str += "当有checksum时,不管系统CRC运算的结果如何,都会用checksum填入address开始的区域。\n";
str += "crcnum=0,同时运算两个工作区域里的CRC,即使两个工作区域不连续。\n";
str += "crcnum=1,表示工作区域1是受CRC保护的,工作区域2为CRC碰撞区域,是会被改写的。\n";
str += "crcnum=2,表示工作区域2是受CRC保护的,工作区域1为CRC碰撞区域,是会被改写的。\n";
str += "crcnum=3,表示工作区域1和工作区域2同时受到保护,CRC碰撞区域在两个工作区域之间,碰撞区域在工作区域1的后面。\n";
str += "crcnum=4,表示工作区域1和工作区域2同时受到保护,CRC碰撞区域在两个工作区域之间,碰撞区域在工作区域2的前面。\n";
str += "特别注意:\n";
str += "CRC运算的范围为worktop1-workbottom2。\n";
str += "CRC碰撞区域由crcnum决定。\n";
str += "\n";
str += "工作区域规则以美元$开始,可以有多行即多个以$开始的不同工作区域规则组成,每个工作区域是独立的。\n";
str += "工作区域1和工作区域2必须成对,不能省略。\n";
str += "校验和及定位地址可以省略。\n";
str += "其中:\n";
str += "每个工作区域由top和bottom组成,即头尾组成,并用“-”分割。\n";
str += "校验和与定位地址用“-”分割。\n";
str += "特别注意:\n";
str += "工作区域规则需要手工填写到主编辑框内。\n";
str += "打开Hex文件后,系统自动生成一条默认工作区域规则。\n";
str += "$0,filesize16;//整个Hex文件进行CRC运算\n";
str += "其中:filesize16=filelength-1。\n";
str += "校验和及定位地址被省略,即结果不会被存储在Hex文件里,而是在“结果编辑框”里。\n";
str += "worktop1<=workbottom1<=worktop2<=workbottom2<filelength\n";
str += "当workbottom1==worktop2时,实际上是一个工作区域。\n";
str += "故规则可以简写为:\n";
str += "$worktop1,workbottom2;checksum-address\n";
str += "或:\n";
str += "$worktop,workbottom;checksum-address\n";
str += "例如系统默认生成的规则:\n";
str += "$0,filesize16\n";
str += "规则结尾可以写注解text,与C语言单行注解用法相同\n";
str += "例如:\n";
str += "CRC16\n";
str += "filelength=0x10000\n";
str += "规则(允许大小写字母混用,10进制和16进制混用,可以不要但需要留位置):\n";
str += "$0,15,,0x0010\n";
str += "$0x100-0x10f,0x110-0x111,0x5555,,1\n";
str += "$0x80-0x81,0x82-0xFF,0xAAAA,,2\n";
str += "$0x2000,0x3ffd,,0x3Ffe\n";
str += "\n";
str += "\n";
str += "特别注意:\n";
str += "hex文件只能由程序区,数据区,垃圾区三部分组成。垃圾区就是程序区和数据区以外的区域。\n";
str += "在烧写芯片时,熔丝烧断即编程为0,熔丝不能再接上为1,即熔丝不能二次编程。\n";
str += "熔丝不烧断为1,可以再次烧断,即可以二次编程熔丝不烧断为1,可以再次烧断,即可以二次编程.\n";
str += "为了延长芯片寿命和擦出次数,故应该默认填充为FF。\n";
str += "\n";
str += "\"编程\"两字是指用烧写器烧写芯片的过程。\n";
str += "\n";
str += "菜农HotPower@163.com 2018.3.30于西安雁塔菜地\n";
str += "";
break;
case 18://网页转换
str += "用于HotWC3帮助文本的格式转换。";
break;
}
idTextBox.value = str;
ChangeidTextBox();
}
function selebuttonhelp()
{
var str = "";
if(!displayout.checked) return;
EditDisplayworkfieldset.style.display = "";//编辑显示
switch(idbuttonhelpsele.selectedIndex)
{
case 0://名词解释
str += "HotPower超级CRC计算器与第三方CRC计算器名词解释与对照及操作:\n";
str += "\n";
str += "权值:Poly,CRC多项式的数字表达。HotPower超级CRC计算器采用最符合内部运算的权值。\n";
str += "初值:Init,CRC初始化预置值。\n";
str += "出值:XorOut,CRC运算后输出前的异或值。\n";
str += "结果:CRC最终的运算结果。\n";
str += "\n";
str += "左移:Refin=False,Refout=False。数据或结果输入和输出都不反转。\n";
str += "右移:Refin=True,Refout=True。数据或结果输入和输出都反转。\n";
str += "\n";
str += "大端:数据或结果输入和输出都不反转。数据或结果按大端排列,例如0x1234,存储顺序为0x12,0x34。\n";
str += "小端:数据或结果输入和输出都反转。数据或结果按小端排列,例如0x1234,存储顺序为0x34,0x12。\n";
str += "\n";
str += "反转:在Refin=True,Refout=True时,数据或结果按小端排列,可以点击“明文”或“结果”快速切换。\n";
str += "反序:在Refin=True,Refout=True时,第三方CRC计算器权值为0x1021,内部运算运算实际反序为0x8408。\n";
str += " 例如:CRC16=X16+X12+X5+1,Poly=0x1021或0x8408。这要和内部运算关联。可以点击“权值”快速切换。\n";
str += "\n";
str += "可逆:当CRC多项式中包含“+1”时,CRC可逆(左移CRC权值最低位为1,右移CRC权值最高位为1),否则不可逆。\n";
str += "\n";
str += "简写式:HotPower超级CRC计算器独特的CRC多项式的简写式,它包含了CRCn、左右移、权值、初值和出值。\n";
str += "例如:CRC16=X16+X12+X5+1,Poly=0x1021,Init=0xFFFF,XorOut=0x0000。Refin=False,Refout=False。\n";
str += "简写式表示为:CRC16L_1021_FFFF_0000\n";
str += "\n";
str += "运算键:HotPower超级CRC计算器支持常见的26种CRC运算,并且提供支持32种任意CRC运算的HotCRC。\n";
str += "选择一种CRC后,将待校验的数据填入“明文”编辑框内,点击“运算”,运算后的校验和会出现在“结果”编辑框中。\n";
str += "还原键:CRC逆运算,可以根据“CRC密文”(CRC运算的中间结果流)还原出“CRC明文”,\n";
str += "这是HotPower超级CRC计算器与第三方CRC计算器最大的不同。\n";
str += "\n";
str += "特别注意:\n";
str += "由于早期CRC的实现由硬件完成,故有左移和右移(反转),权值也有反序之别。\n";
str += "HotPower超级CRC计算器将Refin和Refout的组合用“左移”或“右移”替代。反转和反序内部自动完成。\n";
str += "第三方CRC运算器的权值可能采用反序,这就导致了内部运算的复杂度,故可能和本CRC运算器的权值互为反序。\n";
str += "例如:\n";
str += "CRC16=X16+X12+X5+1,Poly=0x1021,Refin=True,Refout=True。\n";
str += "即右移CRC16,可逆,权值最高位为“1”,故HotPower超级CRC计算器取权值Poly=0x8408(0x1021的反序)\n";
str += "\n";
str += "菜农HotPower@163.com 2023.3.18 于西安雁塔菜地";
break;
case 1://CRC运算
str += "1.在明文编辑框内输入明文,格式可以是非文本的HEX码或其它文本格式(HotWC3支持众多的字符编码)\n";
str += "2.点击\"运算\"按钮,CRC的运算结果会在结果编辑框内显示\n";
str += "特别注意:\n";
str += "密文是CRC正运算的中间结果,每次点击\"运算\"按钮都会得到相应的密文和结果\n";
str += "CRC运算按钮是应用最频繁的按钮之一\n";
str += "它主要完成CRC的正运算,也可以验证CRC还原按钮逆运算的真伪。\n";
str += "在HotWC3中,最能完整表达所有CRC信息的是独特的CRC简写式,它包含了左移或右移、CRC4-CRC64、权值(CRC多项式)、初值和出值。";
break;
case 2://CRC还原
str += "CRC还原按钮主要有三大功能:\n";
str += "1.CRC还原即CRC逆运算\n";
str += "a.在密文处输入密文,长度应该是权值长度的倍数!\n";
str += "b.清空结果(点击几次结果按钮即可清空),或结果XOR出值等于最后一组密文。\n";
str += "c.点击\"还原\"按钮,明文发生变化,即逆运算产生的明文。\n";
str += "2.手动CRC碰撞\n";
str += "a.在知道密文(长度是权值长度的整数倍且至少一倍)后,保持最后一组密文不变。\n";
str += "b.点击\"还原\"按钮,明文发生变化,即明文被篡改。\n";
str += "c.点击\"运算\"按钮,结果没发生变化,即不同的明文会得到相同的结果,即CRC碰撞。\n";
str += "3.手动CRC初值碰撞\n";
str += "a.在明文编辑框内输入明文,特别注意明文长度必须是权值长度的倍数。\n";
str += "b.清空密文(点击密文按钮即可清空)。\n";
str += "c.在结果编辑框输入CRC校验和,在出值编辑框输入指定的出值。\n";
str += "d.点击\"还原\"按钮,初值发生变化,明文、结果和出值都保持不变,即CRC初值碰撞。\n";
str += "当明文长度不是权值长度时,请点击\"CRC初值碰撞\"按钮。";
break;
case 3://CRC明文
str += "CRC明文按钮主要对明文编辑框内的明文做反序排列\n";
str += "例如原明文为12345678,则点击\"明文\"按钮后就被转换为新明文78563412。\n";
str += "如果再点击\"明文\"按钮后又被转换为原明文12345678。\n";
str += "\n";
str += "特别注意:明文编辑框可以输入16进制数或其它字符编码如英文或汉字。";
break;
case 4://CRC密文
str += "CRC密文按钮主要对密文编辑框内的密文进行清空或给一组随机数\n";
str += "特别注意:密文长度在准备还原CRC时,密文长度必须是权值长度的倍数!\n";
str += "密文编辑框在做CRC时只能输入16进制数。";
break;
case 5://CRC结果
str += "CRC结果按钮主要对结果编辑框内的结果进行清空或清零\n";
str += "特别注意:结果编辑框在做CRC时只能输入16进制数(与权值长度等长)或清空。";
break;
case 6://CRC权值
str += "CRC权值按钮只对权值编辑框内的权值进行反转\n";
str += "例如:\n";
str += "原权值为1021,则点击\"权值\"按钮后就被转换为新权值8408。\n";
str += "如果再点击\"权值\"按钮后又被转换为原权值1021。\n";
str += "特别注意:权值编辑框在做CRC时只能输入16进制数(与初值或出值长度等长)。\n";
str += "CRC权值就是CRC的多项式的数学表达式,它还可以构成CRC表格。";
break;
case 7://CRC初值
str += "CRC初值按钮主要对初值编辑框内的初值进行清零,赋值全F或随机数\n";
str += "特别注意:CRC初值与第一个明文是XOR关系,故CRC初值与第一个明文符合交换律。";
break;
case 8://CRC出值
str += "CRC出值按钮主要对出值编辑框内的出值进行清零,赋值全F或随机数\n";
str += "特别注意:CRC出值与最后一个密文是XOR关系。";
break;
case 9://初值出值取反
str += "CRC初值取反按钮或CRC出值取反按钮主要对初值或出值编辑框内的初值或出值进行取反";
break;
case 10://CRC碰撞
str += "当CRC所有参数都固定后,点击\"运算\"按钮,得到结果\n";
str += "记住这个结果。然后点击\"CRC碰撞\"按钮,得到新的明文!\n";
str += "即不同的明文得到了相同的结果,即发生了CRC碰撞。\n";
str += "为了验证CRC碰撞的真伪,再点击\"运算\"按钮,结果保持不变!\n";
str += "\n";
str += "CRC碰撞次数=2^((N-n)*8),其中:N为明文字节数,n为权值字节数。\n";
str += "例如CRC8,明文2个字节,CRC碰撞次数=2^((2-1)*8)=256次\n";
str += "例如CRC16,明文3个字节,CRC碰撞次数=2^((3-2)*8)=256次\n";
str += "例如CRC32,明文5个字节,CRC碰撞次数=2^((5-4)*8)=256次\n";
str += "例如CRC64,明文9个字节,CRC碰撞次数=2^((9-8)*8)=256次";
break;
case 11://CRC初值碰撞
str += "首先声明,CRC初值碰撞被菜农定义为不同的初值会保持原来的CRC状态不变\n";
str += "而只有在CRC不可逆时才会出现CRC初值碰撞。\n";
str += "例如:选择crc16_xmodem,在明文编辑框输入0123456789ABCDEF。\n";
str += "在出值编辑框输入0000(或直接点击\"出值\"按钮),点击\"运算\"按钮,得到结果0794。\n";
str += "再点击\"CRC初值碰撞\"按钮,会得到下面的结果:\n";
str += "穷举初值碰撞时间:下午3:24:18\n";
str += "CRC16R_1021_0000_0000\n";
str += "CRC16R_1021_2043_0000\n";
str += "CRC16R_1021_4086_0000\n";
str += "CRC16R_1021_60C5_0000\n";
str += "CRC16R_1021_810C_0000\n";
str += "CRC16R_1021_A14F_0000\n";
str += "CRC16R_1021_C18A_0000\n";
str += "CRC16R_1021_E1C9_0000\n";
str += "初值碰撞结束时间:下午3:25:02\n";
str += "我们会看到出值为0000时,对应了8个初值,即8对1的关系,即发生了CRC初值碰撞。\n";
str += "特别注意:在CRC初值碰撞运行后,按钮变为\"停止碰撞\",点击\"停止碰撞\"后停止CRC初值碰撞。\n";
str += "这个例子表明制定crc16_xmodem标准的人根本不知道有CRC不可逆的问题。\n";
str += "制定者知道CRC16的多项式有CRC16=X16+X12+X5+1,权值为1021。但这是这对左移CRC16的。\n";
str += "制定者以为权值为1021就是CRC16=X16+X12+X5+1,但为了不抄袭,故采用了右移CRC16。\n";
str += "但右移CRC16,权值为1021的多项式是CRC16=X16+X15+X10+X3。\n";
str += "特别注意多项式最后没有\"+1\",即CRC不可逆!!!\n";
str += "右移CRC16,多项式CRC16=X16+X12+X5+1的权值应该是8408!!!\n";
str += "这时点击\"权值\"按钮就会看见1021和8408来回转换,即权值反转。";
break;
case 12://CRC出值碰撞
str += "首先声明,根本就没有CRC出值碰撞!!!\n";
str += "因为指定初值后,找CRC出值碰撞是CRC正运算,故是1对1的关系,所以不会发生CRC出值碰撞。\n";
str += "设置\"CRC出值碰撞\"按钮,主要是和\"CRC初值碰撞\"按钮对应和给好奇者一个穷举的机会。\n";
str += "特别注意:在CRC出值碰撞运行后,按钮变为\"停止碰撞\",点击\"停止碰撞\"后停止CRC出值碰撞。";
break;
case 13://穷举
str += "HotWC3可以对任意CRC类的通讯协议进行穷举,并且在理论上100%**\n";
str += "HotWC3_V1.23是HotWC3高版本(HotWC3_V1.23以上)的阉割版本,即只能等长穷举和不支持命令行规则。\n";
str += "HotWC3_V1.23也是菜农承诺在网上流传的终结版本,这样做也是为了不使更多人受到伤害!\n";
str += "下载或运行地址:http://www.21ic.com/tools/HotPower/HotCRC.html\n";
str += "菜农HotPower@163.com 2023.3.18 于西安雁塔菜地";
break;
case 14://功能
str += "\"功能\"按钮主要为了快捷地选择功能为\"CRC基本运算\"或\"CRC算法逆向\"\n";
str += "HotWC3的功能很多,主要在左边的帮助里介绍。";
break;
case 15://清空
str += "\"清空\"按钮主要是清空最下面的主编辑框。\n";
str += "主编辑框的高度可以有红色的\"全屏\"控制,打钩全屏,主编辑框可以自动调节,也可以下拉选择行数。\n";
str += "主编辑框的作用:\n";
str += "1.输出一切运算的结果。\n";
str += "2.穷举时,输入待**拦截的通讯协议样本,权值,初值和穷举规则等。\n";
str += "3.输出自动生成的CRC表格及CRC运算的C语言源码。\n";
break;
case 16://CRC选择框
str += "CRC运算类选择框操作(左上方4个选择框):\n";
str += "1.红色的可逆:\n";
str += "CRC运算是有可逆之分的。CRC多项式有\"+1\"时为可逆,否则不可逆!!!\n";
str += "左移CRC权值为奇数时,CRC可逆,为偶数时,CRC不可逆!!!\n";
str += "右移CRC权值最高位为\"1\"时,CRC可逆,最高位为\"0\"时,CRC不可逆!!!\n";
str += "打钩或不打钩\"可逆\",多项式、简写式和权值都会发生相应的变化。\n";
str += "2.红色的文本\n";
str += "HotWC3支持非文本的HEX码和文本的英文和汉字编码和其它编码。\n";
str += "3.蓝色的IE浏览器\n";
str += "它主要是测试IE浏览器的,主要为了选择GB2312-80的汉字编码。\n";
str += "如果我们编程且需要汉字,则必须用IE浏览器打开HotWC3,此时\"IE浏览器\"选择框被打钩。\n";
str += "4.蓝色的显示\n";
str += "它主要是决定是否在最下面的主编辑框内显示,生成表格及C语言源码或穷举时不受其控制。\n";
str += "当不想刷新主编辑框时,可以不打钩\"显示\"。这样进行其它操作结果不会输出到显示框内。";
break;
case 17://穷举选择框
str += "CRC穷举选择框操作(右下方6个选择框):\n";
str += "1.大端:\n";
str += "它表示最下面的主编辑框里的结果给出的排列方式,打钩\"大端\",否则是小端。\n";
str += "例如CRC16,结果是1234,大端是0x1234,小端是0x3412。\n";
str += "如果你给出的规则里没有指定大小端,则默认红色的\"大端\"选择框。\n";
str += "2.可逆:\n";
str += "穷举时,打钩\"可逆\",只选择可逆的权值以加快穷举速度,否则取所有的权值。\n";
str += "3.自定:\n";
str += "穷举时,没有权值列表时,打钩\"自定\"默认面板上的权值,不打钩\"自定\"则从当前权值穷举。\n";
str += "有权值列表时,\"自定\"选择无意义!!!\n";
str += "4.特定:\n";
str += "穷举时,没有初值(出值)列表时,打钩\"特定\"默认权值全(0、5、A、F),不打钩\"特定\"默认面板上的初值(出值)。\n";
str += "有初值(出值)列表时,\"特定\"选择无意义!!!\n";
str += "特别注意:局部穷举初值时,只会运算初值的正运算,不会运算出值的逆运算。\n";
str += "例如:0000#时初值0000正运算一次,出值0000逆运算一次,一共两次。\n";
str += "例如:0000-000F#时初值0000-000F正运算16次,出值0000-000F逆运算0次,一共16次。\n";
str += "5.反序:\n";
str += "穷举时,\"反序\"被打钩,表示主编辑框内的明文是反序的。\n";
str += "特别注意:打钩\"反序\",再点击\"穷举\",再选择\"是\",会在主编辑框内生成反序的明文流。\n";
str += "6.倒置:\n";
str += "穷举时,\"倒置\"被打钩,表示主编辑框内的明文和结果是倒置的。\n";
str += "特别注意:打钩\"倒置\",再点击\"穷举\",再选择\"是\",会在主编辑框内生成倒置的明文和结果流。";
break;
break;
}
idTextBox.value = str;
ChangeidTextBox();
}
function fieldsethelp(index)
{
var str = "";
if(!displayout.checked) return;
EditDisplayworkfieldset.style.display = "";//编辑显示
switch(index){
case -1:
str += "HotPower超级CRC计算器HotCRC是地球上最优秀的CRC计算器,没有之一,不服和菜农PK!\n";
str += "菜农星期公式 =((百年&3)*5+年+(年>>2)+(13*月+8)/5+日)%7\n";
str += "特殊直角边口诀:\n";
str += "当直角边a(>=3)为奇数时,另一直角边b为a平方砍半取整,斜边c比b大1。\n";
str += "当直角边a(>=3)为偶数时,另一直角边b为a砍半平方减1,斜边c比b大2。";
break;
case 1:
str += "HotWC3密码分析";
break;
case 0:
str += "HotWC3密码是菜农HotPower独立发明之作,是十数年菜农钟爱CRC后之结果。\n";
str += "HotWC3由星期(W)、冗余(C)和三角(3)这三种不同密码组合而成。故简称HotWC3密码或WC3密码。俗称“厕所密码”。\n";
str += "HotWC3密码属于传统密码体系中的自同步流加密算法,128位HotWC3密码由:\n";
str += "1字节的8位天地密钥、1字节的8位星期密钥、2字节的16位三角密钥、4字节的32位日期密钥、4字节的32位用户密钥、4字节的32位扩展密钥组成。\n";
str += "\n";
str += "HotWC3密码操作说明:\n";
str += "在日期下拉框依次选择日期密码,立即会得到星期、天数和日期密钥、星期密钥及三角密钥等。\n";
str += "在明文栏内输入需加密的Hex码或汉字码,点击加密按钮,即可在密文栏内得出密文。\n";
str += "在密文栏内输入需解密的Hex码,点击解密按钮,即可在明文栏内得出明文。";
break;
case 2:
str += "CRC设置介绍:\n";
break;
case 3:
str += "CRC选择介绍:\n";
break;
case 4:
str += "超级CRC计算器介绍:\n";
break;
case 5:
// str += "编辑显示介绍:\n";
break;
case 6:
str += "特定直角三角形介绍:\n";
break;
case 7:
WebBrowse(0);
str += "友情链接介绍:\n";
break;
}
idTextBox.value = str;
ChangeidTextBox();
}
function HotWC3ManualLoad()
{//指南键
var str = "";
if(!displayout.checked) return;
EditDisplayworkfieldset.style.display = "";//编辑显示
str += "菜农CRC专题讲座(CRC总结及创新定义)\n";
str += "\n";
str += "1.菜农为CRC多项式找双亲\n";
str += "根据“菜农为CRC找兄弟”的结果分析,得到了两兄弟是XOR关系,即母子关系。只要知道某个CRC多项式的母亲,\n";
str += "那么众多兄弟即非特定初值出值与母亲XOR后,即可找到其孪生兄弟!\n";
str += "公式:\n";
str += "兄弟甲 XOR 兄弟乙 = 母亲\n";
str += "或:\n";
str += "兄弟甲 XOR 母亲 = 兄弟乙\n";
str += "兄弟乙 XOR 母亲 = 兄弟甲\n";
str += "\n";
str += "故:兄弟甲的初值为零时,那么它的兄弟乙就是它们的母亲!\n";
str += "故兄弟甲初值为零的就是它们的父亲!!!\n";
str += "等式:\n";
str += "父亲 XOR 母亲 = 兄弟甲 XOR 兄弟乙\n";
str += "\n";
str += "2.菜农利用5点攻击100%**CRC多项式\n";
str += "a.4点攻击已经100%**了CRC多项式,而且是计算而非穷举,同时100%的得到了特定的初值和出值。\n";
str += "菜农将其归类为**CRC函数即**第三方CRC计算器。\n";
str += "HotWC3_V1.23版本支持4点攻击。\n";
str += "http://www.21ic.com/tools/HotPower/HotCRC.html\n";
str += "b.5点攻击是在前者100%**了CRC多项式即CRC权值的基础上,利用第5组非等长明文,\n";
str += "穷举非特定的初值和出值并且100%的**了初值和出值。\n";
str += "即完成了初值出值碰撞任务,菜农将其归类为**CRC函数即**第三方CRC计算器。\n";
str += "HotWC3_V1.23版本不支持5点攻击,必须为更高版本,但菜农暂时不会发布。\n";
str += "c.非等长明文和结果穷举,它与a和b最大的不同在于无法得到至少4个特定结果。\n";
str += "故无法**其CRC多项式即权值,故必须穷举权值。\n";
str += "而等长明文很难或根本无法**其初值和出值。故必须通过非等长明文来**即穷举初值。\n";
str += "所以本**方法的难度是权值和初值都要穷举,\n";
str += "故运算量巨大!即CRC16相当于CRC32的穷举量。\n";
str += "故一般只能通过经验或猜测标准的CRC权值来忽略对权值的穷举。\n";
str += "\n";
str += "3.菜农对CRC碰撞的创新分类\n";
str += "a.CRC碰撞,这是官方的名称,实际上是明文碰撞,即不同的明文得到相同的结果。\n";
str += "HotWC3的具体操作非常简单,在明文处输入明文,点击“运算”得到结果。\n";
str += "再点击“CRC碰撞”,明文被修改!对吗?点击“运算”,结果没有发生变化!\n";
str += "即不同的明文一样的结果,即发生了CRC碰撞。\n";
str += "特别注意:不能没有密文,且密文长度是权值长度的倍数。\n";
str += "b.CRC初值碰撞,这是菜农的创新。即不同的初值,得到相同的结果。\n";
str += "HotWC3的具体操作也十分简单,同CRC碰撞一样,输入明文,点击“运算”得到结果。\n";
str += "修改指定的出值,点击“CRC初值碰撞”,初值会发生变化!再点击“运算”,结果没有发生变化!\n";
str += "不同的初值一样的结果,即发生了CRC初值碰撞!\n";
str += "特别注意:可以没有密文!\n";
str += "c.CRC出值碰撞,虽然也是菜农的创新,但经过HotWC3的测试,一个初值必然对应一个唯一的出值。\n";
str += "因为最后一个密文就是最后的结果,只是输出时和出值XOR最终得到结果。故勉强认为CRC出值碰撞存在。\n";
str += "特别注意:可以没有密文!\n";
str += "d.CRC初值出值碰撞,这个肯定是菜农的重大创新,因为很久以来,菜农都认为CRC多项式确定后,初值和出值肯定成对出现并且唯一。\n";
str += "但是当HotWC3升级到V1.26后,菜农一片茫然……\n";
str += "经过“菜农为CRC多项式找兄弟”后,又进一步为CRC多项式找到了“母亲”……\n";
str += "特别注意:可以没有密文!\n";
str += "\n";
str += "4.任意CRC多项式表格和C语言源码自动生成\n";
str += "a.大表\n";
str += "CRC大表实际上就是对0-255即前256个明文(即单个字节)进行初值和出值都为零运算后CRC结果的集合即CRC表格。\n";
str += "大表最大的特定是运算速度快,缺点肯定是占用大的空间。\n";
str += "b.小表\n";
str += "CRC小表实际是对CRC大表的抽取16个明文对应的结果的集合即CRC小表格。\n";
str += "小表最大的特定是占用很小的空间,缺点是运行速度比大表慢一倍。\n";
str += "c.C语言源码\n";
str += "HotWC3其中一大特点就是可以自动生成CRC表格和C语言源码。\n";
str += "CRC表格前面已经叙述,而CRC源码就是根据CRC大表或小表对应生成在任何C语言编译器上不经过任何修改即刻运行的代码。\n";
str += "它还有一个特点就是在明文中输入需要验证的非文本的HEX码或文本格式的英文或汉字或其他众多格式的编码,\n";
str += "并且也嵌入到生成的C语言源码中,并且标注了CRC验证值。\n";
str += "HotWC3在生成后提示已经验证通过,放心使用。\n";
str += "若不信可将其全部复制粘贴到C编译器中,编译并运行和验证。\n";
str += "特别提示:\n";
str += "由于一般的C语言编译器汉字只支持GB2312-80标准,故需要明文为汉字时,必须用IE核的浏览器打开HotWC3!\n";
str += "同时选择“文本”和“GB2312-80”编码,否则结果肯定和你运行的不符!切记!\n";
str += "\n";
str += "5.CRC逆运算\n";
str += "HotWC3最大的特点也是它成功之处就是有密文编辑框和还原键按钮。\n";
str += "虽然严格上说CRC不属于单向散列函数,应该属于陷门单向散列函数。\n";
str += "单向散列函数定义:\n";
str += "任意长的输入消息串变化成固定长的输出串且由输出串难以得到输入串的一种函数。这个输出串称为该消息的散列值。\n";
str += "CRC(Cyclic Redundancy Check):循环冗余校验码,CRC校验由于实现简单,检错能力强,被广泛使用在各种数据校验应用中。\n";
str += "占用系统资源少,用软硬件均能实现,是进行数据传输差错检测地一种很好的手段(CRC 并不是严格意义上的散列算法,\n";
str += "但它的作用与散列算法大致相同,所以归于此类)。\n";
str += "\n";
str += "单项陷门函数\n";
str += "所谓单向陷门函数是这样的函数,即除非知道某种附加的信息,否则这样的函数在一个方向上容易计算,而在反方向上要计算是不可行的。\n";
str += "菜农通俗地解释:\n";
str += "任意长度的CRC明文都会被散列为固定长度的CRC结果。\n";
str += "CRC正运算很容易,除非知道了CRC可逆,否则无法逆运算。\n";
str += "在HotWC3上,CRC正运算的操作就是点击运算按钮,CRC逆运算的操作就是点击还原按钮。\n";
str += "菜农总结并给出了CRC可逆的判定方法:\n";
str += "CRC多项式中,包含“+1”的CRC可逆,否则CRC不可逆。\n";
str += "CRC权值中,左移CRC权值最低位为“1”即奇数时,CRC可逆,否则CRC不可逆。\n";
str += "右移CRC权值最高位为“1”即“负数”时,CRC可逆,否则CRC不可逆。\n";
str += "\n";
str += "6.HotWC3自带大量的运算和验证工具\n";
str += "在我们需要运算时,最常见的肯定是XOR运算,其次就是取反(非)运算等。\n";
str += "有些常用编码如UTF-8以及BASE64,UU码等,这些一般计算器都不会或提供的如此多。\n";
str += "实际上HotWC3的CRC运算按钮和还原按钮就是一个编码格式转换工具。\n";
str += "例如字符串“12345678”的HEX码是什么?\n";
str += "a.功能选择“CRC基本运算”。\n";
str += "b.选择“文本”。\n";
str += "c.选择“ascii”编码。\n";
str += "d.将字符串“12345678”输入到明文编辑框。\n";
str += "e.点击“运算”。\n";
str += "f.不选择“文本”即不打勾“文本”。\n";
str += "g.点击“还原”,明文变为“3132333435363738”。\n";
str += "即字符串“12345678”的HEX码为“3132333435363738”\n";
str += "\n";
str += "特别注意:\n";
str += "GB2312-80需要用IE核的浏览器打开HotWC3!\n";
str += "HotWC3有IE核自动检测,选择框“IE浏览器”被打勾表示是用IE核的浏览器打开的HotWC3,否则一定是非IE核的浏览器打开的HotWC3。\n";
str += "\n";
str += "再例如汉字字符串“菜农CRC计算器”的HEX码是什么?\n";
str += "方法一样,只不过字符编码需要选择汉字编码的,如果在WINDOWS上编写程序,应该按上面的选择。\n";
str += "“菜农CRC计算器”的HEX码是\"B2CBC5A9435243BCC6CBE3C6F7\"\n";
str += "菜农-B2CBC5A9\n";
str += "CRC-435243\n";
str += "计算器-BCC6CBE3C6F7\n";
str += "\n";
str += "7.众多的CRC参数编辑框\n";
str += "实际上HotWC3最大的特色就是可以任意CRC。\n";
str += "它也是HotWC3能存活十数年的原因所在。\n";
str += "它有众多的CRC参数(多项式,简写式,权值,左移或右移,CRC4-CRC64,初值和出值)可以任意编辑修改。\n";
str += "你可以任意选择一个标准的CRC,然后对它进行修改,以便得到新的CRC。\n";
str += "HotWC3支持21个标准的CRC,而且可以选择32种HotCRC。\n";
str += "故HotWC3支持CRC4的整数倍的CRCn,即CRC4,CRC8,CRC12,CRC16,CRC20…CRC32…CRC64。\n";
str += "修改“多项式”编辑框,可以直接改写多项式即权值和方向及CRC4-CRC64。\n";
str += "修改“简写式”编辑框,可以直接改写所有CRC参数!\n";
str += "“权值”,“初值”和“出值”编辑框只能修改自己。\n";
str += "特别注意:\n";
str += "点击“权值”按钮,可以使权值“反转”,即数据流移动方向反转。例如1021反转为8408。\n";
str += "\n";
str += "8.非常暴力的CRC穷举\n";
str += "由于HotWC3具备了CRC还原和各种CRC碰撞和**任意第三方CRC计算器的功能积累。\n";
str += "HotWC3采用了灵活多变的命令行方式的穷举规则,做到了理论上100%**任意类CRC通讯协议的能力。\n";
str += "HotWC3只需要用户采集的明文和结果流,不管是任意组合,只要遵从CRC运算法则,则HtWC3将会用比一般**工具更快的方法**。\n";
str += "因为HotWC3内部是在智能运算而非单纯的穷举。\n";
str += "菜农为了不破坏目前工控中大量采用的类CRC通讯协议,故在新版本中废除了CRC穷举的暴力功能。\n";
str += "如果真为了“学习”某个通讯协议,可以联系菜农HotPower@163.com。QQ:1270688699。\n";
str += "\n";
str += "菜农HotPower@163.com 2023.3.18 于西安雁塔菜地";
idTextBox.value = str;
ChangeidTextBox();
}
function HotWC3Readme()
{
var str = "";
if(!displayout.checked) return;
EditDisplayworkfieldset.style.display = "";//编辑显示
switch(idwc3help.selectedIndex){
case 0:
str += "HotWC3密码体系可归类为传统密码,加密密钥和解密密钥是相同的,密钥长度为128-1024位,内核可选CRC8-CRC64。\n";
str += "由于密钥在加密或解密中真随机流动,故可归类为序列密码即流密码,又由于采用了可逆的CRC8内核置换,故也可划归分组(8位)密码。\n";
str += "所以可以认为,HotWC3密码是流密码和传统密码结合的产物。它同时吸收了流密码和分组密码各自的特点和优点。\n";
str += "\n";
str += "HotWC3的128位密钥可分为两大部分:\n";
str += "前者从日期下拉选择设置里用“星期公式”和“特定直角三角形勾股定理”及“天干地支”算法转换为3个密码:“天地密钥”、“星期密钥”及“三角密钥”。\n";
str += "后者由用户自己来设定“用户密钥”和“扩展密钥”及“日期密钥”。\n";
str += "\n";
str += "特别注意:\n";
str += "HotWC3默认当前日期下对应转换的“天地”、“星期”、“三角”这3个密钥,“用户”和“扩展”密钥默认特定日期,“日期”密钥默认开始运行的日期。\n";
str += "\n";
str += "HotWC3密码的操作非常简洁,可通过设置日期并通过算法自动修改为“天地”、“星期”和“三角”这3个密钥。\n";
str += "只需再设置“用户密钥”和“扩展密钥”及“日期密钥”即可。\n";
str += "\n";
str += "请将标题填入“标题编辑框”内并选择“CRC32”及选择“密钥”决定是否将密钥和明文编码序号及密文编码序号写入密文的尾部。\n";
str += "\n";
str += "请选择“明文编码”(默认菜农独创的HotCode编码,其编码非常合理,ASCII为1个字节,其他为2字节。占用空间最小,兼容所有浏览器,强烈推荐使用)\n";
str += "\n";
str += "请选择“密文编码”(默认XXEncode编码,它安全地在QQ等不允许反斜杠“/”的应用程序之中,推荐使用)。\n";
str += "\n";
str += "点击“加密”按钮,密文会出现在“密文编辑框”内。\n";
str += "\n";
str += "密文输出格式由四部分组成:\n";
str += "1. 实际明文加密后产生的密文,特别注意其密文编码。\n";
str += "2. CRC32校验标志,“===”后跟4字节8个字符的CRC32校验和。\n";
str += "3. HotWC3的128位密钥,“***”后CRC并在\"#\"之间跟6个密钥,以“-”隔开,分组以\"_\"隔开。\n";
str += " 最后是明文输入编码序号和密文输出编码序号和HotWC3的版本号(目前为V1.0和V2.0),它们也是以\"-\"隔开。\n";
str += "4. “???”后跟密文标题(未加密),可以任意输入。\n";
str += "\n";
str += "特别注意:密文标题必须选择“CRC32”或“密钥”时才出现在密文中,否则系统无法判断是否为密文标题。\n";
str += "\n";
str += "反之解密雷同,将需要解密的密文(符合HotWC3密码的密文输出格式)填入“密文编辑框”内。\n";
str += "设置和当初加密时的128位密钥和“明文编码”和“密文编码”。\n";
str += "点击“解密”按钮,明文会出现在“明文编辑框”内,特别注意提示警告。\n";
str += "\n";
str += "HotWC3还自带密码分析系统,可以为专家提供HotWC3为“真随机密钥”的数据分析支撑。\n";
str += "使用者也可以通过密码分析系统来查看设置的密钥是否是弱密钥。\n";
str += "\n";
str += "密钥流输出格式由三部分组成:\n";
str += "1. 明文行号和行内字符转换后的字节位置序号,以“#”隔开。\n";
str += "2. HotWC3密码128位密钥流,可细分为:天地、星期、三角、用户、扩展、日期这6个特定密钥,以“-”隔开。\n";
str += "3. 明文编码序号和密文编码序号,以“-”隔开。\n";
str += "\n";
str += "当点击“加密”或“解密”后,对应的明文或密文会被填写到明文分析或密文分析编辑框内,头部为标题(表头)。\n";
str += "0#0*天地-星期-三角-日期-用户-扩展钥-明文编码序号-密文编码序号*CRC8简写式(明文HEX,入口明文HEX,密文HEX,差分检测)\n";
str += "格式同密钥流输出格式,“行号”和“行内字符位置序号”都为0。\n";
str += "\n";
str += "特别注意:\n";
str += "差分检测是对明文输入和密文输出的监测,是两者相异或的结果再混淆天地密钥和星期密钥。\n";
str += "差分检测是HotWC3密码中的密钥流呈现随机的保证和安全的基石!!!\n";
str += "\n";
str += "密码分析功能目前只有:\n";
str += "1. 加密或解密弱密钥测试,主要是分析密钥流(实际是CRC8简写式流)是否是随机无周期变化的。\n";
str += "2. 加密(CRC正运算)或解密(CRC逆运算)核验证测试,主要是分析密钥流输出中的CRC8随机运算(CRC正运算或CRC逆运算)。\n";
str += "\n";
str += "从HotWC自带的密码分析功能的测试结果来看,HotWC3密码的密钥流可以认为是“真随机密钥”。\n";
str += "CRC8内核运算也是“一次一密”运算的,故可以认为HotWC3无法用技术手段来**HotWC3,故是安全的。\n";
str += "\n";
str += "HotWC3内集成了各种最优秀的编码,其中也有菜农HotPower(Hot)独创或简化更新的技术:\n";
str += "菜农星期公式(W),CRC可逆运算(C),特定直角三角形及三角密码(3)。故密码及软件被命名为“HotWC3”。\n";
str += "\n";
str += "HotWC3的密钥流程图终结版本是在2009.8.8完成的,设计它用了至少10年,因为期间主要在完成CRC逆运算后,主要是打造超级CRC计算器。\n";
str += "目前菜农完成了超级CRC计算器的工作,自称其为地球上最优秀的CRC计算器之一。\n";
str += "\n";
str += "由于受网页和字符编码的限制,故HotWC3密码一直没有进步,即无法实际应用。\n";
str += "在菜农独创了字符编码HotCode后,并结合4个“电子邮件编码”(BASE64、UUEncode、XXEncode和Quoted-printable)。\n";
str += "HotWC3密码的传递问题就被完美解决,它可以在任何平台上运行传输压扩比(3:4)最高的可打印字符密文数据流。\n";
str += "\n";
str += "HotWC3的密文流可以选择“日期转换”,即通过设置日期(不是日期密钥)来自动转换为“天地”、“星期”和“三角”这3个不可逆(单向散列)密钥。\n";
str += "\n";
str += "因为早已完成了HotWC3密码的“密码编码”阶段,故即日起进入HotWC3密码的“密码分析”阶段,HotWC3会为专家提供“可视的鉴别环境”。\n";
str += "\n";
str += "菜农个人认为CRC可逆运算颠覆了传统密码体系中的分组密码技术。\n";
str += "它的发散和混淆实际就是对数据流的置换,而CRC可逆运算非常完美地解决了此问题。\n";
str += "若内核采用CRC8实际上就是分组8位即8/8=1个字节,故可归属于流密码,即每次加密一个字节,不需要分组(实际分组了8位)。\n";
str += "若内核采用CRCn实际上就是分组n位即n/8个字节。\n";
str += "\n";
str += "故HotWC3密码体系采用可逆的CRC8-CRC64内核置换实际上是流密码和分组(8-64位)密码的完美结合。\n";
str += "\n";
str += "传统分组密码在置换前如同耍魔术,但在任意CRC可逆置换面前不过儿戏而已……\n";
str += "\n";
str += "呵呵,不是菜农自大,事实就是如此!!!\n";
str += "\n";
str += "本版本开始加入“密码分析学”的内容,HotWC3不但可以做到密码的编码,还要做密码分析,让事实和数据说话。\n";
str += "\n";
str += "敬请密码专家批评指正,欢迎密码高人技术**HotWC3密码!!!\n";
str += "\n";
str += "菜农HotPower@163.com 2023.3.18 于西安雁塔菜地";
break;
case 1:
str += "HotWC3密码分析\n";
str += "\n";
str += "可逆CRC8内核简要说明:\n";
str += "CRC8家族成员一共有7个成员:\n";
str += "1. CRC8权值(Poly),即CRC多项式。它是CRC内核置换算法的核心。\n";
str += "2. CRC8方向(Dir),分左移CRC8L或右移CRC8R运算。\n";
str += "3. CRC8初值(Init),它只对输入明文流的第一个字节做异或(XOR)运算。在运算中由上次密文流输出的最后一个密文字节提供。\n";
str += "4. CRC8出值(XorOut),它只对输出密文流的最后一个密文字节做异或(XOR)运算,在此前无用。\n";
str += "5. 明文,它在运算中只提供需要加密的数据字节流。\n";
str += "6. 密文,它在CRC8运算中,替换下一个字节运算时的初值,或可理解为和下一个字节的明文XOR,即做“差分检测”。\n";
str += "7. 结果,它是CRC8密文流输出最后一个密文字节与出值XOR的结果,在HotWC3密码里,它才是真正每次加密一个字节的密文输出。\n";
str += "\n";
str += "CRC8可逆“定理”的两种表达方式:\n";
str += "1. 多项式\n";
str += "在多项式中包含“+1”时,CRC8可逆,否则不可逆。\n";
str += "2. 移位算法\n";
str += "在左移CRC8L运算时,权值最低位D0为“1”时,CRC8L可逆,否则不可逆。\n";
str += "在右移CRC8R运算时,权值最高位D7为“1”时,CRC8R可逆,否则不可逆。\n";
str += "\n";
str += "CRC8的碰撞问题:\n";
str += "在CRC8运算中,由于权值、方向、初值和出值都保持不变,故一个字节的明文被置换(CRC8正运算运算)为一个字节的密文,即不会发生CRC8碰撞,故明文和密文是置换关系或字典查表的一对一关系,此时的CRC8正运算就是CRC8的加密过程。\n";
str += "但对于明文流是两字节时,就会发生256次CRC8碰撞,故此时CRC8为单向散列函数,即多对一的关系,又因为CRC8运算密文流是下次的初值,将与下次的明文XOR即做差分检测,所以此时CRC8不能作为密码。\n";
str += "同理,对于明文流是三个字节时,将会发生256*256=65536次CRC碰撞,以此类推。\n";
str += "\n";
str += "\n";
str += "多种CRC8碰撞:\n";
str += "菜农将目前流行CRC碰撞的说法命名为“CRC明文碰撞”,即不同的明文得到相同的结果。\n";
str += "在CRC8中,实际还存在其他碰撞: \n";
str += "权值碰撞: 保持其他6个CRC家族成员不变时,不同的权值得到相同的结果\n";
str += "初值碰撞: 保持其他6个CRC家族成员不变时,不同的权值得到相同的结果\n";
str += "出值碰撞: 保持其他6个CRC家族成员不变时,不同的权值得到相同的结果\n";
str += "\n";
str += "由于HotWC3密码的置换内核CRC8被设计成为“一次一密”,即CRC家族成员权值、方向、初值和出值在每次加密或解密一个字节后都必须被全部更换,故可能发生其他成员不停的变化,而明文和密文都不发生变化。\n";
str += "这种“碰撞”就是单向散列函数的表现,故即使知道CRC家族成员的明文、密文和结果,也不可能知道其他CRC家族成员权值、方向、初值和出值。\n";
str += "\n";
str += "所以,像可逆CRC众多家族成员这样的内核确实很难找到。\n";
str += "因为密码的核心就是发散和混淆,故置换是一种玩魔术的技艺,例如目前众多的分组密码,有的需要很多轮置换,“不把人搞晕不是本身”,但是计算机是不会晕的。\n";
str += "而可逆的CRC天生就是置换高手,例如CRC8就有2^8=256组置换表格。\n";
str += "同理,CRCn就有2^n组置换表格,其中n=8,16,24,32,40,48,56,64,…。即作为密码使用,n为8的整数倍。\n";
str += "\n";
str += "HotWC3密码分析可用攻击方法:\n";
str += "1. 唯密文攻击\n";
str += "所谓唯密文攻击是指,攻击者只知道一个或多个需要要攻击的密文(通常包含消息的上下文)。\n";
str += "\n";
str += "注: \n";
str += "这个对HotWC3无能为力,因为它的置换是可逆的CRC8正运算(加密)或逆运算(解密)。\n";
str += "如上分析,只知道密文这一个家族成员,想再知道其他6个家族成员几乎是不可能的。\n";
str += "即使这样变为可能,在HotWC3密码的密钥流的不规则移动和8个XOR的阻拦下,特别是差分检测,它同时与明文和密文都有关系,故有再多个密文也是徒劳,再要想知道128位密钥是绝对不可能的。\n";
str += "\n";
str += "2. 己知明文攻击\n";
str += "所谓己知明文攻击是指,攻击者知道一些明文/密文对,若一个密码系统能够抵抗这种攻击,合法的接收者就不需要销毁己解密的明文。\n";
str += "\n";
str += "注:\n";
str += "由于HotWC3有流密码的特性,故只要明文流某位置上出现一个字节的错误或不同,密文都将被迅速发散,即使明文呈现周期性变化,密文也不会呈现对应的周期性发散。\n";
str += "\n";
str += "3. 选择明文攻击\n";
str += "所谓选择明文攻击是指,攻击者可以选择一些明文及对应的密文(公钥密码体制必需能够抵抗这种攻击)。这个攻击可以假定攻击者可以使用密码机子,选择明文得到相应的密文。\n";
str += "\n";
str += "注:\n";
str += "由于HotWC3的流程框图及算法完全公开,解密者可以使用HotWC3选择一些明文及对应的密文。\n";
str += "而且HotWC3更是为解密者提供了加密过程或解密过程密码分析。\n";
str += "但HotWC3内核CRC8运算时,要想从“入口明文”知道真的明文是非常困难的,因为有8个XOR把关。\n";
str += "\n";
str += "4. 选择密文攻击\n";
str += "所谓选择密文攻击是指,攻击者可以选择一些密文并得到相应的明文。这个攻击可以假定攻击者可以使用密码机子,选择密文得到相应的明文。\n";
str += "\n";
str += "注:\n";
str += "同4分析。\n";
str += "HotWC3同时拥有加密和解密功能,而且具备了一定程度分析加密或解密过程内部的变化规律。\n";
str += "HotWC3密码在设计时,就构造了只能穷举的假设框架结构,参考HotWC3密码流程框图。\n";
str += "\n";
str += "分析类型:\n";
str += "1. 强力攻击\n";
str += "强力攻击包括查表(字典)攻击,时间-存储权衡攻击,字典攻击以及穷举搜索攻击。\n";
str += "由于HotWC3采用“一次一密”,即每次CRC多项式等家族成员都在随机变化,故明文的长度就是长度的容量,故没有此容量的表格(字典)提供给**者。\n";
str += "\n";
str += "2. 线性密码分析\n";
str += "作为一种己知明文攻击方法,线性密码分析方法叫的本质思想在于,通过将一个给定的密码算法有效且线性近似地表示出来以实现破译。\n";
str += "从CRC置换的角度看问题,菜农认为DES的“S盒”“16入4出的置换”也就是CRC4的档次。\n";
str += "而HotWC3的置换内核是CRC8而且是128位密钥。\n";
str += "最重要的是HotWC3可随意扩大置换的内核,即选用更大的CRCn做分组密码,而且增大密钥的长度更不是难事。\n";
str += "\n";
str += "3. 差分密码分析:\n";
str += "差分密码分析的本质思想在于,通过分析相应明文对差值和密文对差值之间的相互影响关系,来得到密钥的一些比特信息。\n";
str += "\n";
str += "当加密或解密内核为异或时,差分攻击是个不错的选择,由于明文对差值和密文对差值都为常数,故可以推导出密钥的差值,所以该设计是不安全的。\n";
str += "但是HotWC3采用CRCn内核,它的密钥实际就是CRC多项式(简写式),而且不是一个简单的异或过程。\n";
str += "在推导CRCn内核时,由于CRCn碰撞和CRC单向散列,故密钥的差值无法确定,即无法差分攻击。\n";
str += "\n";
str += "而且,HotWC3密码在设计时,就建立了明文和密文的“差分检测”,就彻底防止了“差分密码分析”。\n";
str += "\n";
str += "小结菜农对HotWC3密码分析的结论是无法技术解密,即只能用暴力的方法来穷举通过HotWC3加密的密文。\n";
str += "故穷举的时间就和密钥的长度位数及计算机的运算数据处理能力有关联了。\n";
str += "\n";
str += "HotWC3密码的程序运行的效率:\n";
str += "在CRC运算中,大多采用查表法,即每个权值对应一张表格(数组),与初值和出值无关,因为初值只影响明文(XOR),出值只影响密文(XOR)。\n";
str += "因为需要CRC8可逆,故左移CRC8L和右移CRC8R各有128个权值可用,即256个权值256张表格,每张表格里有256个字节的数据。\n";
str += "故总共的表格空间为256*256=65536。\n";
str += "但是对于HotWC3就没什么效率了,CRC8的8次移位是最为快捷的。\n";
str += "再看看HotWC3密码流程框图,它只有异或及移位运算,效率非常高。\n";
str += "\n";
str += "HotWC3密钥流单向散列函数的选取:\n";
str += "在HotWC3的密钥设置中,系统默认了32位的用户密钥和32位的扩展密钥的特定日期。32位的日期密钥默认了打开HotWC3开始工作的日期。\n";
str += "8位的天地密钥、星期密钥及16位的三角密钥这3个密钥是由默认打开HotWC3开始工作的日期进行的单向散列函数的转换。\n";
str += "天地密钥由百年和年通过“天干地支60年一甲子”的单向散列函数组合转换得到。\n";
str += "星期密钥由“菜农星期公式”,“某月的最大天数”的单向散列函数组合转换得到。\n";
str += "在这里菜农公开“某月的最大天数的最佳算法”的答案是: 星期差或周差。\n";
str += "当最小月28天时,下月的今天的星期几一定和今天一样,因为28可以被7(一周)整除,故28天时,星期差为0。\n";
str += "当某月有29天时,下月的星期几就要推后一天,即星期差为1。\n";
str += "同理,30天月差为2,31天星期差为3。\n";
str += "故某月的最大天数=28+星期差。\n";
str += "为了防止出现负数,故完整的“算法”为:28+(7+星期差)%7;\n";
str += "例如今天是周六,下月是周日(0),故星期差为-6。\n";
str += "所以,最大天数=28+(7-6)%=29天\n";
str += "\n";
str += "16位的三角密钥是由一个字节8位的特定直角三角形勾股定理(平方运算,单向散列陷门函数)和三角密码(可逆)扩展为两个字节16位的扩展函数组合转换得到。\n";
str += "\n";
str += "总结:\n";
str += "由于HotWC3密码是流密码和分组(8位)密码结合的产物,而且其CRC8内核的多参数(成员)丰富组合变化,世上很难再找出如此内核!!!\n";
str += "\n";
str += "再参见HotWC3密码流程框图,它将128为密钥分为6大部分:\n";
str += "1. 天地密钥8位,它实际是一个初值密钥,在加密或解密过程中,不断被差分检测XOR,即检测明文和密文。\n";
str += "2. 星期密钥8位,它实际是一个初值密钥,在加密或解密过程中,不断被差分检测XOR,即检测明文和密文。\n";
str += "3. 三角密钥16位,它实际是一个固定周期自身变化的密钥流,不受其他密钥流或差分检测的影响。\n";
str += "4. 用户密钥32位,它被分为两部分,承担三角密钥可能是弱密钥的安全问题。\n";
str += "5.扩展密钥32位,它被分为两部分,承担三角密钥可能是弱密钥的安全问题。\n";
str += "6. 日期密钥32位,它被分为两部分,承担三角密钥可能是弱密钥的安全问题。\n";
str += "7. 虚拟的差分检测密钥8位,它主要承担监测明文和密文,并再与天地密钥和星期密钥XOR。\n";
str += "它可以保证“随机的差分检测”让天地和星期密钥再随机起来,保证了整个密钥流的“真随机”。\n";
str += "而且HotWC3自带弱密钥分析,这样在加密或解密中就杜绝了“伪随机”密钥流的出现概率,即“弱密钥”的出现概率。\n";
str += "\n";
str += "关于HotWC3自带的“密码分析”功能:\n";
str += "1. 弱密钥分析检测\n";
str += "由于CRC运算的特性,权值包含“1”的位数需要进行CRC置换,否则CRC运算就是8位自身的循环移位,即不置换,明文就是密文。\n";
str += "所以,当128位密钥全为0时,明文就是密文,密文就是明文,故无密而言。\n";
str += "所以,当某个密钥全为0时,此密钥就不随机了。\n";
str += "在HotWC3密码流程中,由于三角密钥自身交叉循环,故其绝对不能全为0,否则它就不起任何作用。\n";
str += "此时用户和扩展密钥替代了它们。\n";
str += "天地密钥和星期密钥可以为0,但降低了密钥的长度,差分检测将会替代它们。\n";
str += "\n";
str += "由于HotWC3密码最终的置换由随机的CRC8运算完成,故对密钥流的随机密钥分析就被转化为对随机CRC运算即对CRC8简写式流的分析。\n";
str += "假如在明文或密文长度内,CRC8简写式流不呈现周期性变化,那么就可以认为这128位密钥是安全的,否则就可判定此密钥是“弱密钥”,HotWC3可测试。(加密或解密时,增加弱密钥测试选择功能)\n";
str += "\n";
str += "\n";
str += "差分检测保证了必须100%知道天地密钥和星期密钥它们各自的初始值。才能在同时拥有明文和密文时降低**的难度。\n";
str += "正因为如此,差分检测是HotWC3密钥是“真密钥”的基石,因为再长的密钥,按一定规律的循环移动,理论上无穷时,必然呈现周期性变化,故不可能保证是真随机密钥。\n";
str += "但差分检测就可以保证在明文长度的变化里,明文和密文组成的“随机密钥”必然是真随机,导致了HotWC3密码里的天地密钥和星期密钥的真随机,从而也保证了整个128位密钥的“真随机”。\n";
str += "故解密者必然首先从其下手。\n";
str += "但天地和星期密钥是初始密钥,只用一次,故必然只能采用穷举来**天地和星期密钥。\n";
str += "由于CRC多碰撞原理,故无法单一地穷举天地和星期密钥,最终被迫穷举整个128位密钥。\n";
str += "这就是设计HotWC3密码的初衷和愿望。\n";
str += "\n";
str += "关于HotWC3密码的命名:\n";
str += "菜农在网上“出道”的网名叫“HotPower”,看单词的拼写应该知道菜农是干什么的,有何“功底”,故有“Hot”的密码前缀。\n";
str += "菜农独立推导出了“菜农星期(Week)公式”,故有“W”。\n";
str += "菜农用编写程序的方法,反推导出了CRC的逆运算,故有“C”。\n";
str += "菜农独立数学归纳出了特定整数直角三角形(3)勾股定理,故有“3”。\n";
str += "所以,就有了“HotWC3”的密码命名,特别注意大小写。\n";
str += "\n";
str += "关于HotWC3密码机(HotWC3网页文件):\n";
str += "HotWC3可以在任何平台下运行,即电脑和手机及任何计算操作系统。\n";
str += "它的跨平台的成功主要归功于HotCode字符编码的诞生,在ASCII时为1个字节,其他任何字符编码都为2个字节。\n";
str += "这样就可以做到了字符转换前后字节大小不变,特别适合于密码环境,保证了最高的字符转换后的效率。\n";
str += "HotWC3密文可以选择电子邮件编码: BASE64,UU,XX,QP。\n";
str += "这样就可以保证以最高的编码效率在网络上进行字符传播。\n";
str += "前三个的压扩比是3:4,即明文3个字节,加密后的密文4个字节,效率非常高。\n";
str += "故明文推荐使用用菜农的HotCode字符编码,密文推荐使用UU码。这样的组合效率最高。\n";
str += "HotWC3自带最强大的超级CRC计算器,它具备**CRC的功能,可以100%对CRC类通讯协议进行技术穷举,而非暴力穷举。\n";
str += "它具备对CRC各种碰撞的操作。\n";
str += "HotWC3密码具备基本的加密和解密功能。\n";
str += "它还带有许多实用功能,如明文的CRC32校验,密文功能标题,弱密钥的测试(后续版本)\n";
str += "\n";
str += "\n";
str += "菜农HotPower@163.com 2023.3.18 于西安雁塔菜地\n";
str += "\n";
str += "";
break;
case 2://问答
str += "HotWC3问答\n";
str += "1.什么是CRC\n";
str += "CRC是冗余校验码,专用于数据校验。一般认为CRC是单向散列函数,是不可逆的。如同MD5。\n";
str += "例如数据1,2,3,若用简单的累加和,那么\n";
str += "1+2+3=6\n";
str += "3+2+1=6\n";
str += "…\n";
str += "故结果都是一样的,即发生了“碰撞”。\n";
str += "而CRC内核是移位运算,即左移或右移。\n";
str += "故数据位的变换,就会带来结果的变化,即校验和的不同。\n";
str += "所以CRC比累加和更适合于数据校验。\n";
str += "2.HotWC3密码的特点\n";
str += "例如数据1,2,3,若采用加法,即被加数+加数=和。\n";
str += "1+2=3。\n";
str += "假如不知道加法的逆运算即减法,那么就只能用穷举。\n";
str += "即:\n";
str += "1+2=3。\n";
str += "2+1=3。\n";
str += "发生了“加法碰撞”,即不同的加数得到相同的和。两个只有一个是对的,你只有猜测了。\n";
str += "但若知道加法的逆运算即减法,那么在已知“和”即密文时,若再知道一个加数,那么就很容易得到另外一个加数了。\n";
str += "即加减法有三元,知道其中的两个就可以得到第三个。\n";
str += "以上就是最简单的“加密”和“解密”原理。\n";
str += "而在密码中,流密码的内核就是一个简单的XOR(异或)\n";
str += "运算。分组密码的内核就是布尔函数,即“S盒”,简单说就是查表。\n";
str += "流密码最重要的是要保证密钥流的随机,即在一定长度下,不呈现周期性变化,即能保证“一次一密”。\n";
str += "分组密码的“S盒”起到发散和混淆的作用,但必须保证一定轮次的循环移位,而且构造“S盒”难度很大。由于它只有一个“信号源”,故多少轮次真没多大作用。\n";
str += "而HotWC3密码是流密码+分组的密码体系。\n";
str += "它的密钥流由6大部分的子密钥协同环移并用差分检测来同步随机密钥流的周期,以保证随机的明文和密文反过来控制密钥流的周期。\n";
str += "它的“S盒”就是可逆的CRCn,其中n=8,16,24,32,40,48,56和64。(必要时可以任意扩展)。\n";
str += "例如:\n";
str += "CRC8内核对应128位密钥,每次加密或解密一个字节,即分组8位。\n";
str += "CRC16内核对应256位密钥,每次加密或解密两个字节,即分组16位。\n";
str += "CRC64内核对应1024位密钥,每次加密或解密8个字节,即分组64位。\n";
str += "从HotWC3流程框图观察,其被设计为“一次一密”。\n";
str += "从HotWC3“密码分析”中可以看到最重要的“CRC8简写式”在整个明文长度里是真随机的。\n";
str += "3.HotWC3密码是否安全\n";
str += "由于CRC的特点,从“CRC8简写式”中可以看到,它有多个参数(权值,方向,初值,出值)。\n";
str += "在选择明文攻击中,即知道某特定明文与密文对时的攻击。\n";
str += "在CRC中,由于它的“陷门”即可逆的发生,只要给出4组明文(待校验的数据流)和密文(校验过程的结果流)对,HotWC3会准确地计算出CRC的权值即CRC多项式。这主要是“本次CRC的密文是下次CRC的初值”带来的“漏洞”,它被菜农100%**。\n";
str += "但是HotWC3采用的是“一次一密”,这样就避免了像CRC一样,被“选择明文攻击”而**。\n";
str += "再CRC简写式的多参数,在已知全部明文和密文的情况下,也无法得到加密或解密过程中使用的“CRC简写式”的“流”,即原始的密钥。\n";
str += "故只能穷举,不能技术**。\n";
str += "结论:HotWC3是“设计上安全”的。\n";
str += "4.HotWC3密码的应用场合\n";
str += "由于HotWC3流密码的特点,即每次可加密或解密一个字节。对于二进制而言,加密和解密是1:1的,即明文和密文的长度是一样的。\n";
str += "但为了能在网络上通讯,就必须采用可打印字符编码传输。\n";
str += "HotWC3密文有多种编码选项,推荐采用XXCode编码,它的明文和密文的长度比是3:4。\n";
str += "目前是字符编码中压扩比最高的一种。\n";
str += "由于HotWC3的内核可以任意选择,即密钥长度可以任意扩大且能保证分组时密钥的随机。\n";
str += "结论:\n";
str += "1. 特别适合外交密码和军事密码。\n";
str += "2. 特别适合于社交应用平台上传输密文字符串。因为它的密文编码有多选择,特别是它有不加密的标题醒目提示。\n";
str += "3. 特别适合传输协议通讯。因为HotWC3内核采用的是CRCn,故特别适合于通讯的高速处理,很容易将可逆的CRCn做成芯片,用于工业控制,其经济效益不可限量。\n";
str += "(目前DSP,ARM,MCU都有集成的CRC模块)\n";
str += "在软件处理上,由于只需要做移位和XOR这两种最原始的运算,加密或解密速度会非常快捷,因为HotWC3采用“一次一密”,故无需“多轮循环”。\n";
str += "\n";
str += "\n";
str += "菜农HotPower@163.com 2023.3.18 于西安雁塔菜地\n";
str += "\n";
str += "\n";
str += "";
break
}
idTextBox.value = str;
ChangeidTextBox();
}
function wc3help()
{//版本键
var str = "";
if(!displayout.checked) return;
EditDisplayworkfieldset.style.display = "";//编辑显示
str += " HotCRC超级CRC计算器版本更新说明\n";
str += "\n";
str += "微信公众号:菜农工具。菜农HotPower的QQ号:1270688699。菜农HotWC3密码交流QQ群: 203534415。\n";
str += "\n";
str += "以下是HotWC3高版本(不公开发布)升级日志,V1.23只是废除了CRC穷举,其它功能都具备,同步升级。\n";
str += "HotWC3_V1.26 2017.5.16 实现了理论上100%**类CRC通讯协议,更新完善了帮助信息。\n";
str += "HotWC3_V2.01 2017.6.14 支持所有CRC信息的编辑和联动,支持任意添加和删除第三方CRC计算器,并可直接生成网页文件。\n";
str += "HotWC3_V2.02 2017.6.18 废除CRC运算中的\"大端\"选择框,支持右移CRC4、CRC12、CRC20…CRC60的CRC表格和小表的C语言源码自动生成。\n";
str += " 支持**第三方CRC表格,支持对C语言源码表格函数的仿真。在IE核浏览器下支持文件操作。\n";
str += "HotWC3_V2.03 2017.6.23 支持所有的查表(大表,小表,双表组合)和移位C语言算法和仿真的生成,支持**表格(大表,小表,双表组合)。\n";
str += "HotWC3_V2.06 2017.8.16 开始采用CSS美化网页,废除\"文本\"选择框,优化双表查表C语言算法和仿真的生成以及任意组合方式的表格**。\n";
str += "HotWC3_V2.07 2017.9.6 增加HotWC3密码输出格式,并开始在IE下进行本地文本文件的读写操作。\n";
str += "HotWC3_V2.08 2017.9.13 增加HotWC3密码分析,可以测试弱密钥和核验证。增加了网页转换(网页压缩和网页帮助制作)功能。\n";
str += "HotWC3_V2.09 2017.9.30 根据HotWC3密码流程框图规范化,内核可选CRC8-CRC64,密钥可扩展为1024位,理论上可以无穷扩展。\n";
str += "HotWC3_V2.10 2017.10.1 HotWC3密码分为V1.0和V2.0。对HotWC3密码进行了完善,特别是差分检测,可抗击各种差分攻击。\n";
str += "HotWC3_V2.11 2017.10.13 利用Html5的本地存储,可以任意更改HotWC3初始密钥,更改非标准的HotCRC的CRC简写式。即可以任意扩展克隆CRC(第三方CRC计算器)。\n";
str += "HotWC3_V2.12 2017.10.15 优化。\n";
str += "HotWC3_V2.13 2017.10.18 优化。\n";
str += "HotWC3_V2.15 2017.10.20 将CRC运算内核替换为任意长度的权值(4的倍数)。\n";
str += "HotWC3_V2.16 2017.10.23 采用Ajax与服务器通讯。\n";
str += "HotWC3_V2.17 2017.11.8 苹果手机微信可以复制粘贴。\n";
str += "HotWC3_V2.18 2017.11.9 修复自V2.15优化开始出现的CRC运算的重大bug。\n";
str += "HotWC3_V2.19 2017.11.10 彻底修复自V2.15优化开始出现的CRC运算的所有重大bug\。n";
str += "HotCRC_V2.20 2017.11.19 继续优化和完善HotWC3密码。\n";
str += "HotCRC_V2.21 2018.1.4 修复自动生成双表数据转换的bug。\n";
str += "HotCRC_V2.22 2018.1.10 更新自动生成算法帮助。\n";
str += "HotCRC_V2.25 2018.1.22 修复左移CRC4出错的bug,增加穷举CRC简写式验证。\n";
str += "HotCRC_V2.26 2018.1.31 优化。\n";
str += "HotCRC_V2.27 2018.2.11 HotWC3密码输出增加Base4096编码的汉字输出。\n";
str += "HotCRC_V2.28 2023.3.18 开始支持微软的EDGE。\n";
str += "HotCRC_V2.30 2018.5.16 开始支持变异。\n";
str += "HotCRC_V2.31 2022.7.28 增加CRC24_BLE,高版本开始支持refin和refout不同时的穷举。\n";
str += "HotCRC_V2.33 2023.3.18 开始支持refin和refout的非典型应用,refin和refout相同时为LR,不同时为lr。\n";
str += "\n";
str += "\n";
str += "菜农HotPower@163.com 2023.3.18 于西安雁塔菜地";
idTextBox.value = str;
ChangeidTextBox();
}
//EndHide-->
</script>
<script>
<!--Hide
function HotWC3WindowsMenu(index,checked)
{
var display, displaynot;
display = "";
displaynot = "none";
switch(index){
case 0://主菜单
hotwc3workfieldset.style.display = display;//密码体系
hotwc3Analysisfieldset.style.display = displaynot;//HotWC3密码分析
CRCSelectworkfieldset.style.display = display;//CRC选择
CRCCalculatorworkfieldset.style.display = display;//超级CRC计算器
webconversionfieldset.style.display = displaynot;//网页转换
EditDisplayworkfieldset.style.display = display;//编辑显示
triangleworkfieldset.style.display = display;//特定直角三角形
linkworkfieldset.style.display = display;//友情链接
break;
case 1://HotWC3密码菜单
hotwc3workfieldset.style.display = display;//密码体系
hotwc3Analysisfieldset.style.display = displaynot;//HotWC3密码分析
CRCSelectworkfieldset.style.display = displaynot;//CRC选择
CRCCalculatorworkfieldset.style.display = displaynot;//超级CRC计算器
webconversionfieldset.style.display = displaynot;//网页转换
EditDisplayworkfieldset.style.display = displaynot;//编辑显示
triangleworkfieldset.style.display = displaynot;//特定直角三角形
linkworkfieldset.style.display = display;//友情链接
RefreshCRCTextString();//刷新
break;
case 2://HotWC3密码分析菜单
hotwc3workfieldset.style.display = display;//密码体系
hotwc3Analysisfieldset.style.display = display;//HotWC3密码分析
CRCSelectworkfieldset.style.display = displaynot;//CRC选择
CRCCalculatorworkfieldset.style.display = displaynot;//超级CRC计算器
webconversionfieldset.style.display = displaynot;//网页转换
EditDisplayworkfieldset.style.display = displaynot;//编辑显示
triangleworkfieldset.style.display = displaynot;//特定直角三角形
linkworkfieldset.style.display = display;//友情链接
HotWC3CRCDebugPassRefresh();
HotWC3CRCDebugDisPassRefresh();
GetMessageRowStringText();
break;
case 3://CRC菜单
hotwc3workfieldset.style.display = displaynot;//密码体系
hotwc3Analysisfieldset.style.display = displaynot;//HotWC3密码分析
CRCSelectworkfieldset.style.display = display;//CRC选择
CRCCalculatorworkfieldset.style.display = display;//超级CRC计算器
webconversionfieldset.style.display = displaynot;//网页转换
EditDisplayworkfieldset.style.display = display;//编辑显示
triangleworkfieldset.style.display = displaynot;//特定直角三角形
linkworkfieldset.style.display = display;//友情链接
break;
case 4://三角菜单
hotwc3workfieldset.style.display = displaynot;//密码体系
hotwc3Analysisfieldset.style.display = displaynot;//HotWC3密码分析
CRCSelectworkfieldset.style.display = displaynot;//CRC选择
CRCCalculatorworkfieldset.style.display = displaynot;//超级CRC计算器
webconversionfieldset.style.display = displaynot;//网页转换
EditDisplayworkfieldset.style.display = displaynot;//编辑显示
triangleworkfieldset.style.display = display;//特定直角三角形
linkworkfieldset.style.display = display;//友情链接
break;
case 5://网页菜单
hotwc3workfieldset.style.display = displaynot;//密码体系
hotwc3Analysisfieldset.style.display = displaynot;//HotWC3密码分析
CRCSelectworkfieldset.style.display = displaynot;//CRC选择
CRCCalculatorworkfieldset.style.display = displaynot;//超级CRC计算器
webconversionfieldset.style.display = display;//网页转换
EditDisplayworkfieldset.style.display = displaynot;//编辑显示
triangleworkfieldset.style.display = displaynot;//特定直角三角形
linkworkfieldset.style.display = display;//友情链接
break;
case 6://全部菜单
hotwc3workfieldset.style.display = display;//密码体系
hotwc3Analysisfieldset.style.display = display;//HotWC3密码分析
CRCSelectworkfieldset.style.display = display;//CRC选择
CRCCalculatorworkfieldset.style.display = display;//超级CRC计算器
webconversionfieldset.style.display = display;//网页转换
EditDisplayworkfieldset.style.display = display;//编辑显示
triangleworkfieldset.style.display = display;//特定直角三角形
linkworkfieldset.style.display = display;//友情链接
break;
case 7://帧测试
hotwc3workfieldset.style.display = displaynot;//密码体系
hotwc3Analysisfieldset.style.display = displaynot;//HotWC3密码分析
CRCSelectworkfieldset.style.display = displaynot;//CRC选择
CRCCalculatorworkfieldset.style.display = displaynot;//超级CRC计算器
webconversionfieldset.style.display = displaynot;//网页转换
EditDisplayworkfieldset.style.display = displaynot;//编辑显示
triangleworkfieldset.style.display = displaynot;//特定直角三角形
linkworkfieldset.style.display = display;//友情链接
break;
}
}
function SetHotwc3WeekDisply()
{
var century, year, month, day, week, daycount;
var tiangan, dizhi;//天干,地支
var tgstr, distr;
var value;
//取10进制格式的日期:百年,十年,月日
century = parseInt(year1000.value) * 10 + parseInt(year100.value);//0~99
year = parseInt(year10.value) * 10 + parseInt(year1.value);//0~99
month = parseInt(monthselect.value);//1~12
day = parseInt(dayselect.value);//1~31
/*
1.星期计算(某天对应某星期几,但星期几未知某天,故week是单向散列的)
*/
week = getweek(century, year, month, day);//调用7种星期公式之一
weekselect.selectedIndex = week;//改写星期显示
}
//HotWC3初始密钥推导过程(推导出:日期密钥,天地密钥,星期密钥,三角密钥)
function hotwc3()
{
var century, year, month, day, week, daycount;
var tiangan, dizhi;//天干,地支
var tgstr, distr;
var value;
//下面是从日期(22位密码)中换算出:天地密钥,星期密钥,三角密钥,日期密钥,HotWC3是非标准的86位密码体系
//取10进制格式的日期:百年,十年,月日
century = parseInt(year1000.value) * 10 + parseInt(year100.value);//0~99
year = parseInt(year10.value) * 10 + parseInt(year1.value);//0~99
month = parseInt(monthselect.value);//1~12
day = parseInt(dayselect.value);//1~31
/*
1.星期计算(某天对应某星期几,但星期几未知某天,故week是单向散列的)
*/
week = getweek(century, year, month, day);//调用7种星期公式之一
weekselect.selectedIndex = week;//改写星期显示
/*
2.天数计算(当月实际最大天数daycount+28)
*/
daycount = getweek(century, year, month + 1, day) - week;//取下月(可能为12+1月)的星期和本月的星期差
if (daycount < 0) daycount += 7;//得到星期差即月天数差0~3
//特别注意:当月最大天数为daycount+28
/*
用户密钥
*/
//得到日期密钥HotWC3TextString_0_3.value
/*
3.天差计算(本日到月底的天数)
*/
day = daycount + 28 - day;//错误显示(本日到月底的天数)
if (day < 0)//错误
{
alert('当月选择天数不合法!!!(不会影响WC3加密操作,而且可以增大**难度)');
day = day - (daycount + 28);//本日到月底的天数(天1~31变换为0~30)
}
/*
4.天干地支计算(60年一个甲子年)
*/
year = century * 100 + year - 4;//天干地支年
if (year < 0) year = 60 + year;//天干地支最后4年庚申,辛酉,壬戌,癸亥,再甲子....
// century = Math.floor(year / 60);//天干地支密钥高位0~166
year %= 60;//60年一个甲子年,天干地支年
tiangan = Math.floor(year % 10);//天干0~9
dizhi = Math.floor(year % 12);//地支0~11
tgstr = "甲乙丙丁戊己庚辛壬癸";//天干
distr = "子丑寅卯辰巳午未申酉戌亥";//地支
tgdztext.value = tgstr.substr(tiangan, 1);
tgdztext.value += distr.substr(dizhi, 1);//汉字天干地支年
/*
5. 天地密钥计算(1个字节最重要的密钥之一)
*/
value = ((month % 3) << 6) | (year + (week & 0x03));//推导公式(天干地支年,月,星期)
SetCRCTextString(0, 0, inttohex(value, 2));//天地密钥
/*
6.星期密钥计算(1个字节最重要的密钥之一)
*/
value = ((day + 1) << 3) | (week + 1);//推导公式(天,星期)
SetCRCTextString(0, 1, inttohex(value, 2));//星期密钥
/*
7.三角密钥计算(2个字节最重要的密钥之一)
*/
value = ((month + day) << 3) | (week + 1);//推导公式(月,天,星期),(12+31)*8|7=43|7=0~63
value = password(value);//三角变换,已知勾a求股b,有平方运算
SetCRCTextString(0, 2, inttohex(value, 4));//三角密钥
LoadDateTextString();//装载日期密钥
RefreshCRCTextString();//刷新
}
function TestHotWC3Password(strpass)
{
var result = false;
var str, i, j;
var crcn;
var patrn=/^[0-9a-fA-F]+$/;//正则表达式
var patrn10=/^[0-9]+$/;//正则表达式
var bits = [2, 2, 4, 8, 8, 8];
var strArray = new Array();
var valArray = new Array();
var passArray = new Array();
strArray = strpass.split("#");//CRCn#XX-XX..._XX-XX-XX#5-3-2
if((StringLeft(strpass, 3) == "CRC") && (strArray.length >= 2)){
if(strArray.length >= 3){
str = strArray[2];//5-3-2
if(str != ""){
valArray = str.split("-");//只有一个"-"
if(valArray.length >= 1){
str = valArray[0];
if(!(patrn10.test(str) && (parseInt(str) < idselechnmode.length))){
alert("明文编码序号出错!!!正确为(0-" + (idselechnmode.length - 1) + ")!!!");
return result;
}
}
if(valArray.length >= 2){
str = valArray[1];
if(!(patrn10.test(str) && (parseInt(str) < idseleoutmode.length))){
alert("密文编码序号出错!!!正确为(0-" + (idseleoutmode.length - 1) + ")!!!");
return result;
}
}
if(valArray.length >= 3){
str = valArray[2];
if(!((str >= "1") && (str <= "2"))){
alert("版本号出错!!!正确为(1-2)!!!");
return result;
}
}
}
}
str = strArray[0];
crcn = parseInt(str.substr(3, str.length - 3));//
if((crcn & 7) == 0){
crcn = crcn >>> 3;
if((crcn >=1) && (crcn <= 8)){
str = strArray[1];//XX-XX..._XX-XX
passArray = str.split("_");
if(crcn == passArray.length){
for(i = 0; i < passArray.length;i++){
str = passArray[i];//XX-XX
valArray = str.split("-");
if(valArray.length == 6){//6组密钥
for(j = 0;j < valArray.length;j++){
str = valArray[j];
if(!((str.length == bits[j]) && (patrn.test(str)))){
alert("密钥出错!!!");
return result;
}
}
}
}
}
}
}
}
return true;
}
function setHotWC3Password(strpass)
{
var str, i, j, len, crcn, crcnx, count;
var strArray = new Array();
var valArray = new Array();
var err = false;
strArray = strpass.split("#");//CRCn#XX-XX...#5-3-2
str = strArray[0];
crcn = parseInt(str.substr(3, str.length - 3));//
crcn = (crcn / 8) - 1;
str = strArray[1];//#XX-XX
valArray = str.split("_");
for(i = 0;i <= crcn;i++){//至少一组密钥
if(HotWC3CRCTextString[i] != valArray[i]){
HotWC3CRCTextString[i] = valArray[i];
err = true;
}
}
if(err || (crcn != idselecrcnmode.selectedIndex)){
UpdateCRCTextString(crcn);//替换CRCn
err = true;
}
if(strArray.length >= 3){
str = strArray[2];
if(str != ""){
valArray = str.split("-");//只有一个"-"
if(valArray.length >= 1){
if(idselechnmode.selectedIndex != parseInt(valArray[0])){
idselechnmode.selectedIndex = parseInt(valArray[0]);//明文编码格式
err = true;
}
}
if(valArray.length >= 2){
if(idseleoutmode.selectedIndex != parseInt(valArray[1])){
idseleoutmode.selectedIndex = parseInt(valArray[1]);//密文编码格式
err = true;
}
}
if(valArray.length >= 3){
var version = radiohotwc3version2.checked ? "2":"1";
if(version != valArray[2]){
if(version == "2") radiohotwc3version1.checked = true;
else radiohotwc3version2.checked = true;
err = true;
}
}
}
}
return err;
}
function getHotWC3Password()
{
var str;
var i;
str = idselecrcnmode.value + "#";
for(i = 0;i <= idselecrcnmode.selectedIndex;i++){//CRC8=1个字节,CRC16=2个字节,...CRC64=8个字节
if(i == 0) str += HotWC3CRCTextString[i];
else str += "_" + HotWC3CRCTextString[i];
}
str += "#" + idselechnmode.selectedIndex + "-" + idseleoutmode.selectedIndex + "-" + (radiohotwc3version2.checked ? "2":"1");//明文和密文编码格式
return str;
}
function weekselehelp()
{
var str;
if(!displayout.checked) return;
EditDisplayworkfieldset.style.display = "";//编辑显示
str = "";
idTextBox.value = "";
switch(weeksele.selectedIndex)
{
case 0:
str = "菜农星期公式\n";
str += "星期=((百年%4)*5+年+年/4+(13*月+8)/5+日)%7\n";
str += "其中: 百年=0~99,年=0~99,月=1~12,日=1~28/29/30/31\n当月=1或2时,月=月+12或月=月+4,年=年-1";
break;
case 1:
str = "蔡勒星期公式\n";
str += "星期=(203+百年/4-2*百年+年+年/4+(13*月+8)/5+日)%7\n";
str += "其中: 百年=0~99,年=0~99,月=1~12,日=1~28/29/30/31\n当月=1或2时,月=月+12或月=月+4,年=年-1";
break;
case 2:
str = "基姆拉尔森星期公式\n";
str += "星期=(百年/4+百年*5+年+年/4+(13*月+8)/5+日)%7\n";
str += "其中: 百年=0~99,年=0~99,月=1~12,日=1~28/29/30/31\n当月=1或2时,月=月+12或月=月+4,年=年-1";
break;
case 3:
str = "菜农第二星期公式\n";
str += "星期=((百年*5)%20+年+年/4+(13*月+8)/5+日)%7\n";
str += "其中: 百年=0~99,年=0~99,月=1~12,日=1~28/29/30/31\n当月=1或2时,月=月+12或月=月+4,年=年-1";
break;
case 4:
str = "菜农第三星期公式\n";
str += "星期=(((日期/100)*5)%20+日期%100+(日期%100)/4+(13*月+8)/5+日)%7\n";
str += "其中: 日期=0~9999,月=1~12,日=1~28/29/30/31\n当月=1或2时,月=月+12或月=月+4,日期=日期-1";
break;
case 5:
str = "星期月表算法 月表=[2503514620]其中3月为基月表,1,2月查5,6月表\n";
str += "星期=((百年%4)*5+年+年/4+月表+日)%7\n";
str += "其中: 百年=0~99,年=0~99,月=1~12,日=1~28/29/30/31\n当月=1或2时,月=月+12或月=月+4,年=年-1";
break;
}
SetHotwc3WeekDisply();
idTextBox.value = str;
ChangeidTextBox();
}
function selecodemode() {
switch(idselecodemode.selectedIndex)
{
case 2://gb2312-80
if(!TestIE()){
idselecodemode.selectedIndex = 5;//强行变为文本HotCode
if(displayout.checked) idTextBox.value = "非IE浏览器不得选中!!!";
return;
}
case 0://Hex
case 1://Ascii
case 3://UniCode
case 4://UTF-8
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 5://HotCode
idbsetuphelpsele.selectedIndex = 12;//帮助
selesetuphelp();
break;
case 6://UUEncode
case 7://XXEncode
case 8://base64
case 9://Quoted-printable
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
}
}
function selechnmode() {
switch(idselechnmode.selectedIndex)
{
case 2://gb2312-80
if(!TestIE()){
idselechnmode.selectedIndex = 5;//强行变为文本HotCode
if(displayout.checked) idTextBox.value = "非IE浏览器不得选中!!!";
return;
}
case 0://Hex
case 1://Ascii
case 3://UniCode
case 4://UTF-8
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 5://HotCode
idbsetuphelpsele.selectedIndex = 12;//帮助
selesetuphelp();
break;
case 6://UUEncode
case 7://XXEncode
case 8://base64
case 9://Quoted-printable
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
}
}
function LoadHotWC3CRCTextString(str)
{
if(TestHotWC3CRCTextString(str)){
HotWC3CRCTextString.length++;
HotWC3CRCTextString[HotWC3CRCTextString.length - 1] = str;
}
else{
alert("装载HotWC3CRCTextString[" + "\"" + str + "\"]密钥错误!!!");
}
}
function TestHotWC3CRCTextString(passstr)
{
var len, err, str;
var strArray = new Array();
var patrn = /^[0-9a-fA-F]+$/;//正则表达式
var bits = [2, 2, 4, 8, 8, 8];
strArray = passstr.split("-");//密钥之间用"-"隔开
err = false;
if(strArray.length == 6){//每个密钥六组
for(i = 0;i < 6; i++){
str = strArray[i];
if(!((str.length == bits[i]) && patrn.test(str))){
return false;
}
}
err = true;
}
return err;
}
function LoadHotWC3CRCPolyString(str)
{
if(TestHotWC3CRCPolyString(str)){//权值,初值,出值,方向,差分
HotWC3CRCPolyString.length++;
HotWC3CRCPolyString[HotWC3CRCPolyString.length - 1] = str;
}
else{
alert("装载HotWC3CRCPolyString[" + "\"" + str + "\"]密钥错误!!!");
}
}
function TestHotWC3CRCPolyString(passstr)
{
var len, err, str;
var strArray = new Array();
var patrn = /^[0-9a-fA-F]+$/;//正则表达式
var crcnum = (HotWC3CRCPolyString.length + 1) * 2;//5组
strArray = passstr.split("_");//成员之间用"_"隔开
err = false;
if(strArray.length == 7){//权值,初值,出值,方向,差分
for(i = 0;i < 7; i++){
str = strArray[i];
if(!((str.length == crcnum) && patrn.test(str))){
return false;
}
}
err = true;
}
return err;
}
function LoadHotWC3CRCWorkString(str)
{
if(TestHotWC3CRCWorkString(str)){
HotWC3CRCWorkString.length++;
HotWC3CRCWorkString[HotWC3CRCWorkString.length - 1] = str;
}
else{
alert("装载HotWC3CRCWorkString[" + "\"" + str + "\"]密钥错误!!!");
}
}
function TestHotWC3CRCWorkString(passstr)
{
var len, err, str;
var strArray = new Array();
var patrn = /^[0-9a-fA-F]+$/;//正则表达式
var bits = [2, 8, 2, 4];
var crcnum = (HotWC3CRCWorkString.length >>> 1) + 1;//8组CRC8-CRC64
strArray = passstr.split("-");//密钥之间用"-"隔开
err = false;
if(strArray.length == 4){//密钥流左右各4组
for(i = 0;i < 4; i++){
str = strArray[i];
if(!((str.length == bits[i] * crcnum) && patrn.test(str))){
return false;
}
}
err = true;
}
return err;
}
function TestHotWC3MessageText()
{
var str;
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) * 2;//1个字节2个数据位
str = HotWC3MessageText.value;
if(!patrn.test(str)) {
HotWC3MessageText.value = GetMessageText();
alert("请输入16进制数!!!");
}
else {
HotWC3MessageText.value = str.toUpperCase();
}
}
function TestHotWC3PassText()
{
var str;
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) * 2;//1个字节2个数据位
str = HotWC3PassText.value;
if(!patrn.test(str)) {
HotWC3PassText.value = GetPassText();
alert("请输入16进制数!!!");
}
else {
HotWC3PassText.value = str.toUpperCase();
}
}
function HotWC3CRCcalculator()
{
HotWC3PassText.value = GetHotWC3CRCPolyWorkString(HotWC3PloyNumberText.value, HotWC3MessageText.value, 0);
}
function HotWC3CRCrevert()
{
HotWC3MessageText.value = GetDisHotWC3CRCPolyWorkString(HotWC3PloyNumberText.value, HotWC3PassText.value, 0);
}
function TestPloyStringText()
{
HotWC3PloyStringText.value = HotWC3PloyStringText.value.toUpperCase();//CRC12=X12+X11+X3+X2+X+1
if(TestCRCTableArrayPolyTextString(HotWC3PloyStringText.value)){
SetCRCTableArrayPolyStringText();
HotWC3PloyStringTextBack = HotWC3PloyStringText.value;
}
else{
HotWC3PloyStringText.value = HotWC3PloyStringTextBack;
alert("CRC多项式输入错误!!!");
}
}
function SetCRCTableArrayPolyStringText()
{//150
var i, val, bits, dir, len, crcnum, str, ptr;
var polyh, polyl;
var strArray = new Array();
var valArray = new Array();
var patrn10 = /^[0-9]+$/;//正则表达式
str = HotWC3PloyNumberText.value;//CRC12L_80F_000_000
valArray = str.split("_");
ptr = valArray[0];//CRC12L
dir = (StringRight(ptr, 1) == "R") ? 0:1;
str = HotWC3PloyStringText.value;//CRC12=X12+X11+X3+X2+X+1
strArray = str.split("=");
ptr = strArray[0];//CRC12
bits = parseInt(ptr.substr(3, ptr.length - 3));
crcnum = bits / 4;
str = strArray[1];//X12+X11+X3+X2+X+1
strArray = str.split("+");//X12,X11,X3,X2,X,1
len = strArray.length;
if(strArray[len - 1] == "1"){
strArray[len - 1] = "X0";
if(strArray[len - 2] == "X"){
strArray[len - 2] = "X1";
}
}
else if(strArray[len - 1] == "X"){
strArray[len - 1] = "X1";
}
polyh = 0;
polyl = 0;
for(i = 1;i < len;i++){
val = parseInt(strArray[i].substr(1, strArray[i].length - 1));
if(val < 32){
polyl |= (1 << val);
}
else{
polyh |= (1 << (val - 32));
}
}
str = inttohex(polyh, 8) + inttohex(polyl, 8);
str = str.substr(str.length - crcnum, crcnum);
if(dir == 0) str = StringReversalToString(str);//反转
str = ptr + ((dir == 0) ? "R":"L") + "_" + str;
str += "_" + StringLeft0(valArray[2], crcnum);
str += "_" + StringLeft0(valArray[3], crcnum);
HotWC3PloyNumberText.value = str;
TestPloyNumberText();
}
function TestPloyNumberText()
{
HotWC3PloyNumberText.value = HotWC3PloyNumberText.value.toUpperCase();//CRC12=X12+X11+X3+X2+X+1
if(TestCRCTableArrayPolyArrayString(HotWC3PloyNumberText.value)){
HotWC3PloyStringText.value = GetCRCTableArrayPolyTextString(HotWC3PloyNumberText.value);
HotWC3PloyNumberTextBack = HotWC3PloyNumberText.value;
}
else{
HotWC3PloyNumberText.value = HotWC3PloyNumberTextBack;
alert("CRC简写式输入错误!!!");
}
}
function GetHotWC3CRCPolyWorkStringEx(crcpolystr, crcstr)
{//支持CRC简写式的CRC正运算
var strArray = new Array();
var valArray = new Array();
var str, crcvalue, i, len, ch, cl, strbit, str0;
var bits, crcpoly, crcdir, crcbits, crcinit, crcxorout, crcnum;
crcvalue = "";//密文出错返回空
strArray = crcpolystr.split("_");//分解CRC多项式
if(strArray.length == 4){//简写式必须由4部分组成
if(StringRight(strArray[0], 1) == "R"){//取CRC内核的方向
crcdir = 0;//右移为0
}
else {
crcdir = 1;//左移为1
}
crcpoly = strArray[1];//取CRC权值
crcinit = strArray[2];//取CRC初值
crcxorout = strArray[3];//取CRC出值
crcbits = parseInt(strArray[0].substr(3, strArray[0].length - 4));//CRCn的位数,这里应该从strArray[0]中取
crcnum = crcbits / 4;
str0 = StringLeft0("", crcnum);
bits = crcstr.length * 4;
for(i = 0;i < crcstr.length;i += crcnum){
crctext = crcstr.substr(i, crcnum);
crcvalue = GetHotWC3CRCPolyWorkValue(crctext, crcinit, crcpoly, str0, crcdir, crcbits, bits);
crcinit = crcvalue;
}
crcvalue = StringXORToStringLeft(crcvalue, crcxorout);
}
return crcvalue;//返回CRC结果字符串
}
function GetHotWC3CRCPolyWorkString(crcpolystr, crctext, bits)
{//支持CRC简写式的CRC正运算
var strArray = new Array();
var valArray = new Array();
var str, crcvalue, i, len, ch, cl, strbit;
var crcpoly, crcdir, crcbits, crcinit, crcxorout, crcnum;
crcvalue = "";//密文出错返回空
strArray = crcpolystr.split("_");//分解CRC多项式
if(strArray.length == 4){//简写式必须由4部分组成
if(StringRight(strArray[0], 1) == "R"){//取CRC内核的方向
crcdir = 0;//右移为0
}
else {
crcdir = 1;//左移为1
}
crcpoly = strArray[1];//取CRC权值
crcinit = strArray[2];//取CRC初值
crcxorout = strArray[3];//取CRC出值
crcbits = parseInt(strArray[0].substr(3, strArray[0].length - 4));//CRCn的位数,这里应该从strArray[0]中取
crcvalue = GetHotWC3CRCPolyWorkValue(crctext, crcinit, crcpoly, crcxorout, crcdir, crcbits, bits);
}
return crcvalue;//返回CRC结果字符串
}
function GetHotWC3CRCPolyWorkValue(crctext, crcinit, crcpoly, crcxorout, crcdir, crcbits, bits)
{//支持CRC简写式的CRC正运算
var strArray = new Array();
var valArray = new Array();
var str, crcvalue, i, len, ch, cl, strbit;
var crcnum;
crcvalue = "";//密文出错返回空
crcnum = crcbits / 4;//半字节的长度,即占用数字的多少
if (!((bits == 0) || (bits >= crcbits))){
crcbits = bits % crcbits;
}
crctext = StringLeft0(crctext, crcnum);//补0
if (crcdir == 0)//右移
{
crctext = StringInvertlToString(crctext);//反序
}
crcvalue = StringXORToStringLeft(crctext, crcinit);//开始运算前和初值XOR
for(i = 0;i < crcbits;i++){//运算移位的次数
if(crcdir){//左移CRC正运算
ch = StringANDToStringLeftCut(crcvalue, "8");//左对齐AND ,即左移需要测试CRC的最高位
crcvalue = StringMoveToStringLeft(crcvalue, 1);//左移1位不带进位
if(ch != "0"){//左移前最高位是否为1
crcvalue = StringXORToStringLeft(crcvalue, crcpoly);//和权值左对齐XOR \
}
}
else{//右移CRC正运算
cl = StringANDToStringRightCut(crcvalue, "1");//左对齐AND,右移需要测试 最低位
crcvalue = StringMoveToStringRight(crcvalue, 1);//右移1位不带进位
if(cl != "0"){//右移CRC判断最低位是否为1
crcvalue = StringXORToStringRight(crcvalue, crcpoly);//和权值右对齐XOR
}
}
}
crcvalue = StringXORToStringLeft(crcvalue, crcxorout);//结束运算后和出值XOR得到CRC结果,左对齐XOR
return crcvalue;//返回CRC结果字符串
}
function GetDisHotWC3CRCPolyWorkString(crcpolystr, crctext, bits)
{//支持CRC简写式的CRC逆运算
var strArray = new Array();
var valArray = new Array();
var str, crcvalue, i, len, ch, cl, strbit;
var crcpoly, crcdir, crcbits, crcinit, crcxorout, crcnum;
crcvalue = "";//密文出错返回空
strArray = crcpolystr.split("_");//分解CRC多项式
if(strArray.length == 4){//CRC简写式由4部分组成
if(StringRight(strArray[0], 1) == "R"){//取CRC运算的方向
crcdir = 0;//右移为0
}
else {
crcdir = 1;//左移为1
}
crcpoly = strArray[1];//取CRC权值
crcinit = strArray[2];//取CRC初值
crcxorout = strArray[3];//取CRC出值
crcbits = parseInt(strArray[0].substr(3, strArray[0].length - 4));//CRCn的位数,这里应该从strArray[0]中取
crcvalue = GetDisHotWC3CRCPolyWorkValue(crctext, crcinit, crcpoly, crcxorout, crcdir, crcbits, bits);//逆运算密文和出值XOR
}
return crcvalue;//返回明文
}
function GetDisHotWC3CRCPolyWorkValue(crctext, crcinit, crcpoly, crcxorout, crcdir, crcbits, bits)
{//支持CRC简写式的CRC逆运算
var crcvalue, i;
var crcnum;
crcvalue = "";//密文出错返回空
crcnum = crcbits / 4;//半字节的长度,即占用数字的多少
if (!((bits == 0) || (bits >= crcbits))){
crcbits = bits % crcbits;
}
crcvalue = StringXORToStringLeft(crctext, crcxorout);//逆运算密文和出值XOR
for(i = 0;i < crcbits;i++){//CRCn移位次数
if(crcdir){//左移CRC正运算(实际右移)
if(StringANDToStringRightCut(crcvalue, "1") != "0"){//逆运算左移实际测试最低位
crcvalue = StringXORToStringLeft(crcvalue, crcpoly);//实际的还原,CRC和权值左对齐XOR
crcvalue = StringMoveToStringRight(crcvalue, 1);//右移1位不带进位
crcvalue = StringXORToStringLeft(crcvalue, "8");
}
else{
crcvalue = StringMoveToStringRight(crcvalue, 1);//右移1位不带进位
}
}
else{//右移CRC正运算(实际左移)
if(StringANDToStringLeftCut(crcvalue, "8") != "0"){//逆运算测试最高位
crcvalue = StringXORToStringRight(crcvalue, crcpoly);//和权值左对齐XOR ,得到还原
crcvalue = StringMoveToStringLeft(crcvalue, 1);//左移1位不带进位
crcvalue = StringXORToStringRight(crcvalue, "1");
}
else{
crcvalue = StringMoveToStringLeft(crcvalue, 1);//左移1位不带进位
}
}
}
crcvalue = StringXORToStringLeft(crcvalue, crcinit);//CRC逆运算结果和初值左对齐XOR ,得到明文
if (crcdir == 0)//右移
{
crcvalue = StringDisInvertlToString(crcvalue);//反序
}
crcvalue = crcvalue.substr(0, crcbits / 4);//恢复长度
return crcvalue;//返回明文
}
function MoveHotWC3TriangleWorkString(crcindex)
{//三角密钥交叉错位循环移动,每加密一个字节CRC8移动1次,CRC16移动2次...CRC64移动8次即1个字节
var len, index;
var leftArray = new Array();
var rightArray = new Array();
var strleft, strright, left, right;
var i, j;
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
index = crcindex << 1;
leftArray = HotWC3CRCWorkString[index + 0].split("-");//密钥之间用"-"隔开
rightArray = HotWC3CRCWorkString[index + 1].split("-");//密钥之间用"-"隔开
strleft = leftArray[0];//左边三角密钥流
strright = rightArray[0];//右边三角密钥流
len = strleft.length;//左右相等,特别注意是半字节
for(i = 0;i <= crcindex;i++){//移动次数
left = HexToNumber(strleft[0] )& 8;//左边最高位DH
right = HexToNumber(strright[len - 1]) & 1;//右边最低位DL
//特别注意:下面是错位循环,不能用自环位移函数!!!
strleft = StringMoveToStringLeftCY(strleft, 1, right);//带进位左环移
strright = StringMoveToStringRightCY(strright, 1, left);//带进位右环移
}
leftArray[0] = strleft;//左边三角密钥流
rightArray[0] = strright;//右边三角密钥流
HotWC3CRCWorkString[index + 0] = leftArray.join("-");//写入
HotWC3CRCWorkString[index + 1] = rightArray.join("-");//写入
}
function MoveHotWC3DateWorkString(crcindex)
{//日期密钥流受控天干密钥流D7D6D5右环移1~8次
var len, index, count;
var leftArray = new Array();
var rightArray = new Array();
var dateleft, tgdzleft, left, right;
var i, j;
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
index = crcindex << 1;
leftArray = HotWC3CRCWorkString[index + 0].split("-");//密钥之间用"-"隔开
dateleft = leftArray[1];//左边日期密钥流
len = dateleft.length;
tgdzleft = leftArray[2];//左边天地密钥流
tgdzleft = StringANDToStringLeftCut(tgdzleft, "E");//取最高4位
count = HexToNumber(tgdzleft) >>> 1;//高3位控制1~8次
for(i = 0;i <= crcindex;i++){//crc8一个循环,crc16两个...
for(j = 0;j <= count;j++){//移动次数
dateleft = StringMoveToStringRightSelf(dateleft, 1);//自环右移动1次
}
}
leftArray[1] = dateleft;//左边日期密钥流
HotWC3CRCWorkString[index + 0] = leftArray.join("-");//写入
return dateleft;
}
function MoveHotWC3UserWorkString(crcindex)
{//用户密钥流受控星期密钥流D2D1D0左环移1~8次
var len, index, count;
var leftArray = new Array();
var rightArray = new Array();
var userright, weekright, left, right;
var i, j;
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
index = crcindex << 1;
rightArray = HotWC3CRCWorkString[index + 1].split("-");//密钥之间用"-"隔开
userright = rightArray[1];//用户密钥流
len = userright.length;
weekright = rightArray[2];//星期密钥流
weekright = StringANDToStringRightCut(weekright, "7");//取最低3位
count = HexToNumber(weekright) & 7;//低3位控制1~8次???pwy
for(i = 0;i <= crcindex;i++){//
for(j = 0;j <= count;j++){//移动次数
userright = StringMoveToStringLeftSelf(userright, 1);//自环左移动1次
}
}
rightArray[1] = userright;//用户密钥流
HotWC3CRCWorkString[index + 1] = rightArray.join("-");//写入
return userright;
}
function MakeHotWC3InitDirPolyString(crcindex)
{//生成初值,方向,权值
var polyArray = new Array();
var leftArray = new Array();
var rightArray = new Array();
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var index = crcindex << 1;
leftArray = HotWC3CRCWorkString[index + 0].split("-");//密钥之间用"-"隔开
rightArray = HotWC3CRCWorkString[index + 1].split("-");//密钥之间用"-"隔开
polyArray = HotWC3CRCPolyString[crcindex].split("_");//权值,初值,出值,方向,明文,密文,差分,用"_"隔开
var LeftTriangle, Date;
LeftTriangle = leftArray[0];//左边三角密钥流
var RightTriangle, User;
RightTriangle = rightArray[0];//右边三角密钥流
Date = leftArray[1];//日期密钥流
polyArray[1] = StringXORToStringRightCut(LeftTriangle, Date);//得到初值,左对齐取短的XOR
User = rightArray[1];//用户密钥流
polyArray[0] = StringXORToStringLeftCut(RightTriangle, User);//得到权值,左对齐取短的XOR
var crcnum = (crcindex + 1) * 2;
Date = Date.substr(crcnum, crcnum);//日期的D23-D16
User = User.substr(crcnum + crcnum, crcnum );//用户的D15-D8
polyArray[3] = StringXORToStringLeftCut(Date, User);//得到方向,左对齐取短的XOR
HotWC3CRCPolyString[crcindex] = polyArray.join("_");//写入
}
function MoveHotWC3TgdzWorkString(crcindex)
{//天地密钥流受控方向D7左环移1次
var index;
var leftArray = new Array();
var polyArray = new Array();
var tgdzleft, dir;
var i, j;
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
index = crcindex << 1;
leftArray = HotWC3CRCWorkString[index + 0].split("-");//密钥之间用"-"隔开
polyArray = HotWC3CRCPolyString[crcindex].split("_");//权值,初值,出值,方向,明文,密文,差分,用"_"隔开
tgdzleft = leftArray[2];//天地密钥流
dir = polyArray[3];//取方向
count = HexToNumber(dir[0]) & 8;//D7
for(i = 0;i <= crcindex;i++){//
for(j = 0;j <= count;j++){
tgdzleft = StringMoveToStringLeftSelf(tgdzleft, 1);//自环左移动1次
}
}
leftArray[2] = tgdzleft;//用户密钥流
HotWC3CRCWorkString[index + 0] = leftArray.join("-");//写入
return tgdzleft;
}
function MoveHotWC3WeekWorkString(crcindex)
{//星期密钥流受控方向D0右环移1次
var index;
var rightArray = new Array();
var polyArray = new Array();
var weekright, dir;
var i, j;
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
index = crcindex << 1;
rightArray = HotWC3CRCWorkString[index + 1].split("-");//密钥之间用"-"隔开
polyArray = HotWC3CRCPolyString[crcindex].split("_");//权值,初值,出值,方向,明文,密文,差分,用"_"隔开
weekright = rightArray[2];//星期密钥流
dir = polyArray[3];//取方向
count = HexToNumber(dir[dir.length - 1]) & 1;//D0
for(i = 0;i <= crcindex;i++){//
for(j = 0;j <= count;j++){
weekright = StringMoveToStringRightSelf(weekright, 1);//自环右移动1次
}
}
rightArray[2] = weekright;//用户密钥流
HotWC3CRCWorkString[index + 1] = rightArray.join("-");//写入
return weekright;
}
function MoveHotWC3UserExWorkString(crcindex)
{//扩展密钥流受控方向
var index;
var leftArray = new Array();
var rightArray = new Array();
var polyArray = new Array();
var userexleft, userexright, dir;
var i, j, count;
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
index = crcindex << 1;
leftArray = HotWC3CRCWorkString[index + 0].split("-");//密钥之间用"-"隔开
rightArray = HotWC3CRCWorkString[index + 1].split("-");//密钥之间用"-"隔开
polyArray = HotWC3CRCPolyString[crcindex].split("_");//权值,初值,出值,方向,明文,密文,差分,用"_"隔开
userexleft = leftArray[3];//左侧扩展密钥流
userexright = rightArray[3];//右侧扩展密钥流
dir = polyArray[3];//取方向
count = HexToNumber(dir[0]) & 3;//D5D4
for(i = 0;i <= crcindex;i++){//
for(j = 0;j <= count;j++){
userexleft = StringMoveToStringRightSelf(userexleft, 1);//自环右移动1次
}
}
leftArray[3] = userexleft;//左侧扩展密钥流
count = HexToNumber(dir[dir.length - 1]) >>> 2;//D3D2
for(i = 0;i <= crcindex;i++){//
for(j = 0;j <= count;j++){
userexright = StringMoveToStringLeftSelf(userexright, 1);//自环左移动1次
}
}
rightArray[3] = userexright;//右侧扩展密钥流
HotWC3CRCWorkString[index + 0] = leftArray.join("-");//写入
HotWC3CRCWorkString[index + 1] = rightArray.join("-");//写入
return userexleft + "_" + userexright;
}
function MakeHotWC3InitXoroutString(crcindex)
{//扩展密钥流受控方向
var polyArray = new Array();
var leftArray = new Array();
var rightArray = new Array();
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var index = crcindex << 1;
leftArray = HotWC3CRCWorkString[index + 0].split("-");//密钥之间用"-"隔开
rightArray = HotWC3CRCWorkString[index + 1].split("-");//密钥之间用"-"隔开
polyArray = HotWC3CRCPolyString[crcindex].split("_");//权值,初值,出值,方向,明文,密文,差分,用"_"隔开
var tgdzleft, weekright;
var userexleft, userexright;
tgdzleft = leftArray[2];//天地密钥流
weekright = rightArray[2];//星期密钥流
userexleft = leftArray[3];//左侧扩展密钥流
userexright = rightArray[3];//右侧扩展密钥流
//特别注意:下面合并了初值。
var Xorin = StringXORToStringRightCut(tgdzleft, userexleft);
polyArray[1] = StringXORToStringLeft(Xorin, polyArray[1]);//得到明文字控制(输入控制,与初值不同),明文字=Xorin XOR 实际明文
var XorOut = StringXORToStringLeftCut(weekright, userexright);
polyArray[2] = XorOut;//得到出值(输出控制,与出值相同),密文字=Xorout XOR 实际密文
HotWC3CRCPolyString[crcindex] = polyArray.join("_");//写入
}
function GetHotWC3CRCPolyString(crcindex)
{
//构造CRC简写式
var polyArray = new Array();
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var index = crcindex << 1;
polyArray = HotWC3CRCPolyString[crcindex].split("_");//权值,初值,出值,方向,明文,密文,差分,用"_"隔开
var dir, d6, d1, poly;
var strArray = new Array();
var crcbits = (crcindex + 1) * 8;
dir = polyArray[3];//取方向字
d6 = StringANDToStringLeftCut(dir, "40");
d1 = StringANDToStringRightCut(dir, "02");
dir = StringORToStringLeft(d6, d1);
poly = polyArray[0];
if((dir == "00")||(dir == "42")){//R
poly = StringORToStringLeft(poly, "8");
dir = "R";
}
else{//L
poly = StringORToStringRight(poly, "1");
dir = "L";
}
polyArray[0] = poly;//改写权值
HotWC3CRCPolyString[crcindex] = polyArray.join("_");//写入
strArray[0] = "CRC" + crcbits + dir;
strArray[1] = poly;
strArray[2] = polyArray[1];//初值
strArray[3] = polyArray[2];//出值
str = strArray.join("_");//polyArray[]排序不太合理
return str;//返回CRC简写式
}
function HotWC3CRCDebugPassRefresh()
{
HotWC3MessageRowText.value = "1";
HotWC3MessagePosText.value = "0";
HotWC3MessageRangeText.value = "0";
RefreshCRCTextString();
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
LoadHotWC3WorkStringToText(crcindex);//加密解密分析时,装载密钥流编辑框
HotWC3MessageStringText.value = GetMessageRowStringText();//取1行明文流
HotWC3PassStringText.value = "";//清空密文编辑框
wc3inputanalysis.value = "0#0*CRCn简写式(明文HEX,密文HEX,差分检测HEX)";
}
function HotWC3CRCDebugDisPassRefresh()
{
HotWC3PassRowText.value = "1";
HotWC3PassPosText.value = "0";
HotWC3PassRangeText.value = "0";
RefreshCRCTextString();
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
LoadHotWC3WorkStringToText(crcindex);//加密解密分析时,装载密钥流编辑框
HotWC3PassStringText.value = GetPassRowStringText();//取1行密文流
HotWC3MessageStringText.value = "";//清空明文编辑框
wc3outputanalysis.value = "CRCn简写式(明文HEX,密文HEX,差分检测HEX)";
}
function DisplayHotWC3WorkStringToText(crcindex)
{//显示中间结果
var leftArray = new Array();
var rightArray = new Array();
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
index = crcindex << 1;
leftArray = HotWC3CRCWorkString[index + 0].split("-");//密钥之间用"-"隔开
rightArray = HotWC3CRCWorkString[index + 1].split("-");//密钥之间用"-"隔开
HotWC3LeftTriangleString.value = leftArray[0];//左边三角密钥流
HotWC3RightTriangleString.value = rightArray[0];//右边三角密钥流
HotWC3DateString.value = leftArray[1];//日期密钥流
HotWC3UserString.value = rightArray[1];//用户密钥流
HotWC3TGDZString.value = leftArray[2];//天地密钥流
HotWC3WeekString.value = rightArray[2];//星期密钥流
HotWC3LeftUserExString.value = leftArray[3];//左侧扩展密钥流
HotWC3RightUserExString.value = rightArray[3];//右侧扩展密钥流
var polyArray = new Array();
polyArray = HotWC3CRCPolyString[crcindex].split("_");//权值,初值,出值,方向,明文,密文,差分,用"_"隔开
HotWC3PolyStringText.value = polyArray[0];
HotWC3InitStringText.value = polyArray[1];
HotWC3XorOutStringText.value = polyArray[2];
HotWC3DirStringText.value = polyArray[3];
HotWC3MessageText.value = polyArray[4];
HotWC3PassText.value = polyArray[5];
HotWC3DiffStringText.value = polyArray[6];
HotWC3PloyNumberText.value = GetHotWC3CRCPolyString(crcindex);
TestPloyNumberText();//写入多项式
}
function HotWC3CRCDebugPassRun()
{
HotWC3CRCDebugPassRefresh();
while(HotWC3CRCDebugPassSetp());
}
function HotWC3CRCDebugDisPassRun()
{
HotWC3CRCDebugDisPassRefresh();
while(HotWC3CRCDebugDisPassSetp());
}
function HotWC3CRCDebugPassSetp()
{//单步加密调试
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) << 1;
var pos = parseInt(HotWC3MessagePosText.value);//明文位置
var str, len, mess, pass;
var strArray = new Array();
var result = true;
var diffcheck = HotWC3DiffCheck.checked;
str = HotWC3MessageStringText.value;//取明文流文本
len = str.length;
if(pos < len){
mess = str.substr(pos, crcnum);//分组明文
// mess = StringLeft0(mess, crcnum);//不够长度补"0"
pass = GetHotWC3PassWorkFunction(crcindex, mess, diffcheck);//取密文
DisplayHotWC3WorkStringToText(crcindex);
HotWC3PassStringText.value += pass;
HotWC3MessagePosText.value = (pos + crcnum);
str = "\n" + HotWC3MessageRowText.value + "#"+ pos + "*" + HotWC3PloyNumberText.value + "(";
str += StringLeft0(mess, crcnum) + "," + pass + "," + HotWC3DiffStringText.value +")";
wc3inputanalysis.value += str;
ChangeidHotWC3inputTextBoxanalysis();
}
else{
str = wc3input.value;//取明文流
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
var row = parseInt(HotWC3MessageRowText.value);//明文行号
HotWC3MessageRowText.value = (row + 1);
str = GetMessageRowStringText();
if(str != ""){
HotWC3MessageStringText.value = str;
HotWC3MessageRowText.value = row + 1;
HotWC3MessagePosText.value = "0";
}
else{
HotWC3MessageRowText.value = row;
result = false;
alert("抱歉,单步加密调试已经结束或越界!!!");
}
}
return result;
}
function HotWC3CRCDebugDisPassSetp()
{//单步解密调试
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) << 1;
var pos = parseInt(HotWC3PassPosText.value);//明文位置
var str, ptr, len, mess, pass;
var strArray = new Array();
var result = true;
var diffcheck = HotWC3DiffCheck.checked;
str = HotWC3PassStringText.value;//取密文流文本
len = str.length;
if(pos < len){
pass = str.substr(pos, crcnum);//分组明文
mess = GetHotWC3DisPassWorkFunction(crcindex, pass, diffcheck);//取明文
DisplayHotWC3WorkStringToText(crcindex);
HotWC3MessageStringText.value += mess;
HotWC3PassPosText.value = (pos + crcnum);
str = "\n" + HotWC3PassRowText.value + "#" + pos + "*" + HotWC3PloyNumberText.value + "(";
str += mess + "," + StringLeft0(pass, crcnum) + "," + HotWC3DiffStringText.value +")";
wc3outputanalysis.value += str;
ChangeidHotWC3outputTextBoxanalysis();
}
else{
str = wc3output.value;//取密文流
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
var row = parseInt(HotWC3PassRowText.value);//密文行号
HotWC3PassRowText.value = (row + 1);
str = GetPassRowStringText();
if(str != ""){
HotWC3PassStringText.value = str;
HotWC3PassRowText.value = row + 1;
HotWC3PassPosText.value = "0";
}
else{
HotWC3PassRowText.value = row;
result = false;
alert("抱歉,单步加密调试已经结束或越界!!!");
}
}
return result;
}
function GetHotWC3PassWorkFunction(crcindex, messhex, diffcheck)
{//加密工作函数
var crcnum = (crcindex + 1) << 1;
var str, mess, pass, passhex, crcpolystr;
MoveHotWC3TriangleWorkString(crcindex);//三角密钥交叉错位循环移动
MoveHotWC3DateWorkString(crcindex);//日期密钥流受控天干密钥流D7D6D5右环移1~8次
MoveHotWC3UserWorkString(crcindex);//用户密钥流受控星期密钥流D2D1D0左环移1~8次
MakeHotWC3InitDirPolyString(crcindex);//生成初值,方向,权值
MakeHotWC3InitXoroutString(crcindex);//制造输入和输出
crcpolystr = GetHotWC3CRCPolyString(crcindex);//取多项式简写式
SetHotWC3PolyArrayString(crcindex, 4, messhex);//写入明文字
passhex = GetHotWC3CRCPolyWorkString(crcpolystr, messhex, 0);//正运算
SetHotWC3PolyArrayString(crcindex, 5, passhex);//写入密文字
MakeHotWC3DiffString(crcindex, messhex, passhex, diffcheck);//生成差分字并且XOR天地和星期密钥(V2.0差分后取反,而且要再XOR日期、用户和扩展)
MoveHotWC3TgdzWorkString(crcindex);//天地密钥流受控方向D7左环移1次
MoveHotWC3WeekWorkString(crcindex);//星期密钥流受控方向D0右环移1次
MoveHotWC3UserExWorkString(crcindex);//扩展密钥流受控方向
return passhex;
}
function GetHotWC3DisPassWorkFunction(crcindex, passhex, diffcheck)
{//解密工作函数
var crcnum = (crcindex + 1) << 1;
var str, mess, pass, messhex, crcpolystr;
MoveHotWC3TriangleWorkString(crcindex);//三角密钥交叉错位循环移动
MoveHotWC3DateWorkString(crcindex);//日期密钥流受控天干密钥流D7D6D5右环移1~8次
MoveHotWC3UserWorkString(crcindex);//用户密钥流受控星期密钥流D2D1D0左环移1~8次
MakeHotWC3InitDirPolyString(crcindex);//生成初值,方向,权值
MakeHotWC3InitXoroutString(crcindex);//制造输入和输出
crcpolystr = GetHotWC3CRCPolyString(crcindex);//取多项式简写式
SetHotWC3PolyArrayString(crcindex, 5, passhex);//写入密文字
messhex = GetDisHotWC3CRCPolyWorkString(crcpolystr, passhex, 0);//逆运算
SetHotWC3PolyArrayString(crcindex, 4, messhex);//写明入文字
MakeHotWC3DiffString(crcindex, messhex, passhex, diffcheck);//生成差分字并且XOR天地和星期密钥(V2.0差分后取反,而且要再XOR日期、用户和扩展)
MoveHotWC3TgdzWorkString(crcindex);//天地密钥流受控方向D7左环移1次
MoveHotWC3WeekWorkString(crcindex);//星期密钥流受控方向D0右环移1次
MoveHotWC3UserExWorkString(crcindex);//扩展密钥流受控方向
return messhex;
}
function GetHotWC3PolyArrayString(crcindex, index)
{//读取密钥流中间结果
var polyArray = new Array();
var str = "";
polyArray = HotWC3CRCPolyString[crcindex].split("_");//权值,初值,出值,方向,明文,密文,差分,用"_"隔开
if(index < polyArray.length){
str = polyArray[index];
}
return str;
}
function SetHotWC3PolyArrayString(crcindex, index, str)
{//改写密钥流中间结果
var polyArray = new Array();
var crcnum = (crcindex + 1) << 1;
var len = str.length;
if(len < crcnum) str = StringLeft0(str);
else str = StringLeft(str, crcnum);
polyArray = HotWC3CRCPolyString[crcindex].split("_");//权值,初值,出值,方向,明文,密文,差分,用"_"隔开
if(index < polyArray.length){
polyArray[index] = str;
HotWC3CRCPolyString[crcindex] = polyArray.join("_");//写入
}
}
function MakeHotWC3DiffString(crcindex, mess, pass, diffcheck)
{//生成差分字
/*
混合
*/
var leftArray = new Array();
var rightArray = new Array();
index = crcindex << 1;
diff = StringXORToStringLeft(mess, pass);//差分
leftArray = HotWC3CRCWorkString[index + 0].split("-");//密钥之间用"-"隔开
rightArray = HotWC3CRCWorkString[index + 1].split("-");//密钥之间用"-"隔开
if(diffcheck){//差分检测
if(radiohotwc3version2.checked){//版本2.0
diff=StringNot(diff);
leftArray[1] = StringXORToStringLeft(diff, leftArray[1]);//日期密钥流
rightArray[1] = StringXORToStringRight(diff, rightArray[1]) ;//用户密钥流
leftArray[3] = StringXORToStringLeft(diff, leftArray[3]);//左扩展密钥流
rightArray[3] = StringXORToStringRight(diff, rightArray[3]) ;//右扩展密钥流
}
//版本1.0时只对天地和星期密钥流进行差分
leftArray[2] = StringXORToStringLeft(diff, leftArray[2]);//天地密钥流
rightArray[2] = StringXORToStringRight(diff, rightArray[2]) ;//星期密钥流
HotWC3CRCWorkString[index + 0] = leftArray.join("-");//写入
HotWC3CRCWorkString[index + 1] = rightArray.join("-");//写入
}
SetHotWC3PolyArrayString(crcindex, 6, diff);//写入差分字
return;
}
function LoadHotWC3WorkStringToText(crcindex)
{//装载密钥流到密码分析编辑框
var len;
var leftArray = new Array();
var rightArray = new Array();
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
index = crcindex << 1;
leftArray = HotWC3CRCWorkString[index + 0].split("-");//密钥之间用"-"隔开
rightArray = HotWC3CRCWorkString[index + 1].split("-");//密钥之间用"-"隔开
HotWC3LeftTriangleString.value = leftArray[0];//左边三角密钥流
HotWC3RightTriangleString.value = rightArray[0];//右边三角密钥流
HotWC3DateString.value = leftArray[1];//日期密钥流
HotWC3UserString.value = rightArray[1];//用户密钥流
HotWC3TGDZString.value = leftArray[2];//天地密钥流
HotWC3WeekString.value = rightArray[2];//星期密钥流
HotWC3LeftUserExString.value = leftArray[3];//左侧扩展密钥流
HotWC3RightUserExString.value = rightArray[3];//右侧扩展密钥流
return;
}
function GetMessageRowStringText()
{//取1行明文流
var str, len;
var strArray = new Array();
str = wc3input.value;//取明文流
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
var row = parseInt(HotWC3MessageRowText.value);//明文行号
str = "";
if(row <= strArray.length){
str = strArray[row - 1];//取1行明文
str = CodeStringToHex(str, idselechnmode.selectedIndex);//把明文转换为HEX
len = str.length;
HotWC3MessageStringText.value = str;
HotWC3MessagePosText.value = "0";
HotWC3MessageRangeText.max
HotWC3MessagePosText.max = len;
HotWC3MessageRangeText.max = len;
}
return str;
}
function GetPassRowStringText()
{
var str, ptr, len;
var strArray = new Array();
str = wc3output.value;//取密文流
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
var row = parseInt(HotWC3PassRowText.value);//密文行号
str = "";
if(row <= strArray.length){
str = strArray[row - 1];//取1行明文
ptr = str.substr(0, 3);
if((ptr == "===") ||(ptr == "***") ||(ptr == "???")){
return "";
}
if(idseleoutmode.selectedIndex > 0) str = AsciiToHex(str);
str = HexToCodeExString(str, idseleoutmode.selectedIndex);//把密文转换为~~~
len = str.length;
HotWC3PassStringText.value = str;
HotWC3PassPosText.value = "0";
HotWC3PassRangeText.max
HotWC3PassPosText.max = len;
HotWC3PassRangeText.max = len;
}
return str;
}
function GetPloyNumberText()
{//简写式
var str, dir, d6, d1;
var strArray = new Array();
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcbits = (crcindex + 1) * 8;
dir = GetDirStringText();
d6 = StringANDToStringLeft(dir, "40");
d1 = StringANDToStringLeft(dir, "02");
dir = StringORToStringLeft(d6, d1);
strArray[0] = "CRC" + crcbits + ((dir == "00") ? "R": "L");
strArray[1] = GetPolyStringText();
strArray[2] = GetInitStringText();
strArray[3] = GetXorOutStringText();
HotWC3PloyNumberText.value = strArray.join("_");
HotWC3PloyStringText.value = GetCRCTableArrayPolyTextString(HotWC3PloyNumberText.value);
GetDiffStringText();
HotWC3MessageText.value = GetMessageText();
HotWC3PassText.value = GetPassText();
return HotWC3PloyNumberText.value;
}
function GetMessageText()
{
var str = "";
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) * 2;//1个字节2个数据位
str = GetMessageRowStringText();
str = StringLeft(str, crcnum);
return str;
}
function GetPassText()
{
var str = "";
str = GetHotWC3CRCPolyWorkString(HotWC3PloyNumberText.value,HotWC3MessageText.value, 0);
return str;
}
function GetPolyStringText()
{//取权值
var RightTriangle, User;
RightTriangle = HotWC3RightTriangleString.value;
User = HotWC3UserString.value;
HotWC3PolyStringText.value = StringXORToStringLeftCut(RightTriangle, User);//左对齐取短的XOR
return HotWC3PolyStringText.value;
}
function GetDirStringText()
{//取方向
var Date, User;
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) * 2;
Date = HotWC3DateString.value;
Date = Date.substr(crcnum, crcnum);
User = StringLeft(HotWC3UserString.value, crcnum);
HotWC3DirStringText.value = StringXORToStringLeftCut(Date, User);//左对齐取短的XOR
return HotWC3DirStringText.value;
}
function GetInitStringText()
{//取初值
var LeftTriangle, Date;
LeftTriangle = HotWC3LeftTriangleString.value;
Date = HotWC3DateString.value;
HotWC3InitStringText.value = StringXORToStringRightCut(LeftTriangle, Date);//左对齐取短的XOR
return HotWC3InitStringText.value;
}
function GetXorOutStringText()
{//取出值
var RightUserEx;
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) * 2;
RightUserEx = HotWC3RightUserExString.value;
HotWC3XorOutStringText.value = StringLeft(RightUserEx, crcnum);//
return HotWC3XorOutStringText.value;
}
function GetDiffStringText()
{//取差分
var str = "";
if((HotWC3MessageText.value != "") && (HotWC3PassText.value != "")){
str = StringXORToStringLeftCut(HotWC3MessageText.value, HotWC3PassText.value);//左对齐取短的XOR
HotWC3DiffStringText.value = str;
}
return str;
}
function hotwc3KeySelect()
{
if(hotwc3Keycheckbox.checked){
hotwc3Keycheckbox.checked = confirm("加密选择了密钥非常危险!!!\n请确认是否在密文中出现密钥???");
}
}
var HotWC3_CRCXXXXLPolyTextString;
function MakeCRCXXXXLPolyTextString()
{
var polystr, initstr, xoroutstr, i ,j, k=0;
var initpass = "19591119";
var xoroutpass = "19790413";
polystr = "";
initstr = "";
xoroutstr = "";
polystr = GetPasswordTableString(0);///取全部1024位密钥
HotWC3_CRCXXXXLPolyTextString = "CRC" + (polystr.length * 4) + "L_";
for(i = 0;i < 256/8;i ++){
for(j = 0;j < 8;j++){
initstr += StringXORToStringLeftCut(polystr[k], initpass[j]);
xoroutstr += StringXORToStringLeftCut(polystr[k], xoroutpass[j]);
k++;
}
}
HotWC3_CRCXXXXLPolyTextString += polystr + "_" + initstr + "_" + xoroutstr;
}
function GetPasswordTableString(index)
{
var strArray = new Array();
var str, i, j;
str = "";
for(i = index;i < 8;i++){
strArray = HotWC3CRCTextString[i].split("-");
for(j = 0;j < 6;j++){
str += strArray[j];
}
}
return str;
}
function SetPasswordTableString(password)
{
var strArray = new Array();
var i, j, k, len;
var bits = [2, 2, 4, 8, 8, 8];
k = 0;
strArray.length = 0;
for(i = 1;i < 8;i++){
for(j = 0;j < 6;j++){
len = bits[j];
strArray[j] = password.substr(k, len);
k += len;
}
HotWC3CRCTextString[i] = strArray.join("-");
}
}
function LoadPasswordTable()
{
if(TestLS()){
var passwordstr = GetPasswordTableString(1);//取内存896位密码
var polystr = HotWC3_CRCXXXXLPolyTextString;//1024位CRC权值
var lsname = "HotWC3_PasswordString";
var password = localStorage[lsname];//取本地1024位密码
if(password && (password.length == (passwordstr.length + 32))){//已保存了1024位陷门散列密码
password = GetDisHotWC3CRCPolyWorkString(polystr, password, passwordstr.length * 4);//将1024位密钥解密为896位密钥(压缩)
SetPasswordTableString(password);//从本地读出896位密钥
}
else{//生成1024位陷门散列密码
passwordstr = GetHotWC3CRCPolyWorkString(polystr, passwordstr, passwordstr.length * 4);//加密896位密钥,散列为1024位密钥在内存里。
localStorage[lsname] = passwordstr;//写入
if(localStorage[lsname] != passwordstr){
alert("首次保存初始密钥C16-C64的本地存储失败!!!");
}
else{
alert("首次保存初始密钥C16-C64的本地存储成功!!!");
}
}
}
}
function ViewPasswordTable()
{
if(TestLS()){
var lsname = "HotWC3_PasswordString";
var passwordstr = localStorage[lsname];//取出1024位密钥
var strArray = new Array();
var str, ptr, i,j,k, len;
var bits = [2, 2, 4, 8, 8, 8];
str = "1024位本地存储已经加密的密钥:";
k = 0;
for(i = 0;i < 8;i++){
strArray.length = 0;
for(j = 0;j < 6;j++){
len = bits[j];
strArray[j] = passwordstr.substr(k, len);
k += len;
}
str += "\n" + strArray.join("-");
}
/*
EditDisplayworkfieldset.style.display = "";//编辑显示
idTextBox.value = str;
ChangeidTextBox();
*/
alert(str);//显示密钥
}//ls
}//func
function SaveClearPasswordTable()
{
if(TestLS()){
if(confirm("请您确认是否保存密钥C16-C64的本地存储???")){
var passwordstr = GetPasswordTableString(1);//取内存896位密码
var polystr = HotWC3_CRCXXXXLPolyTextString;//1024位权值
var passwordstr = GetHotWC3CRCPolyWorkString(polystr, passwordstr, passwordstr.length * 4);//加密896位密钥,散列为1024位密钥在内存里。
var lsname = "HotWC3_PasswordString";
localStorage[lsname] = passwordstr;//将1024位密钥写入存盘
if(localStorage[lsname] != passwordstr){
alert("保存密钥C16-C64的本地存储失败!!!");
}
else{
alert("保存密钥C16-C64的本地存储成功!!!");
}
}
}
else{
alert("您使用的浏览器不支持Html5的本地存储!!!");
}
}
function RemovePasswordTable()
{
var str, i;
if(TestLS()){
if(hotwc3titlecheckbox.checked && (hotwc3titleoutput.value == "250")){//清除
if(confirm("请您确认是否清空所有的本地存储???")){
localStorage.clear();//清除一切
location.reload();//刷新页面,重新启动
}//ifcon
}
else{
if(confirm("请您确认是否恢复初始密钥C16-C64的本地存储???")){
var lsname = "HotWC3_PasswordString";
localStorage.removeItem(lsname);//删除
location.reload();//刷新页面,重新启动
}
}
}
else{
alert("您使用的浏览器不支持Html5的本地存储!!!");
}
}//func
var gCRCPolyArrayDisturbance="";
function HotWC3CRCPolyArrayDisturbance()
{//扰动密钥
var strArray = new Array();
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var bits = [2, 2, 4, 8, 8, 8];
var i, j, k, len, str, ptr, count;
if(gCRCPolyArrayDisturbance != ""){
str = gCRCPolyArrayDisturbance;
strArray = str.split("_");//参数之间用"_"隔开
i = strArray[0];
j = strArray[1];
str = strArray[2];//需要恢复的原始数据
strArray = HotWC3CRCTextString[i].split("-");//密钥之间用"-"隔开
strArray[j] = str;//直接改写
HotWC3CRCTextString[i] = strArray.join("-");//写入
}
count = Math.floor(Math.random() * ((crcindex + 1) * 6));
i = Math.floor(count / 6);
j = count % 6;
k = Math.floor(Math.random() * bits[j] * 2);
str = StringLeft0("1", bits[j]);
str = StringMoveToStringRight(str, k);
strArray = HotWC3CRCTextString[i].split("-");//密钥之间用"-"隔开
ptr=strArray[j];//原始数据
strArray[j] = StringXORToStringLeft(str, strArray[j]);
HotWC3CRCTextString[i] = strArray.join("-");//写入
RefreshCRCTextString(crcindex);
DisplayHotWC3WorkStringToText(crcindex);
k = Math.floor((k + 1) / 4);
str =i + "_" + j + "_" + ptr;//原始数据
gCRCPolyArrayDisturbance = str;//备份本次数据
str = "HotWC3TextString_X_" + j;
var obj=document.getElementById(str);
alert(idselecrcnmode[i].value + "_" + obj.value + "_第" + (k + 1) + "位数字密钥被改写1位");
return;//???
//为何下面的程序不运行????
for(i = 0;i <= crcindex; i++){
strArray = HotWC3CRCTextString[i].split("-");//密钥之间用"-"隔开
for(j = 0;j < HotWC3CRCTextString.length; j++){
str = inttohex(Math.floor(Math.random() * 0xffffffff), bits[j]);
strArray[j] = str;
}
HotWC3CRCTextString[i] = strArray.join("-");//写入
}
RefreshCRCTextString(crcindex);
DisplayHotWC3WorkStringToText(crcindex);
}
function HotWC3CRCPolyArrayRandom()
{
var strArray = new Array();
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var bits = [2, 2, 4, 8, 8, 8];
var i, j, len, str;
for(i = 0;i <= crcindex; i++){
strArray = HotWC3CRCTextString[i].split("-");//密钥之间用"-"隔开
for(j = 0;j < HotWC3CRCTextString.length; j++){
str = inttohex(Math.floor(Math.random() * 0xffffffff), bits[j]);
strArray[j] = str;
}
HotWC3CRCTextString[i] = strArray.join("-");//写入
}
RefreshCRCTextString(crcindex);
DisplayHotWC3WorkStringToText(crcindex);
}
function HotWC3CRCPolyArrayEmpty()
{
var strArray = new Array();
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var bits = [2, 2, 4, 8, 8, 8];
var i, j, len, str;
for(i = 0;i <= crcindex; i++){
strArray = HotWC3CRCTextString[i].split("-");//密钥之间用"-"隔开
for(j = 0;j < HotWC3CRCTextString.length; j++){
strArray[j] = StringLeft0("", bits[j]);
}
HotWC3CRCTextString[i] = strArray.join("-");//写入
}
RefreshCRCTextString(crcindex);
DisplayHotWC3WorkStringToText(crcindex);
}
function LoadHotWC3CRCTextToWorkString(crcindex)
{
var len, str, ptr;
var leftArray = new Array();
var rightArray = new Array();
// var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
index = crcindex << 1;
leftArray = HotWC3CRCWorkString[index + 0].split("-");//密钥之间用"-"隔开
rightArray = HotWC3CRCWorkString[index + 1].split("-");//密钥之间用"-"隔开
str = GetCRCTextStringCols(crcindex, 2);//取三角密钥
len = str.length >>> 1;
leftArray[0] = StringLeft(str, len);
rightArray[0] = StringRight(str, len);
str = GetCRCTextStringCols(crcindex, 3);//取日期密钥
leftArray[1] = str;
ptr = GetCRCTextStringCols(crcindex, 4);//取用户密钥
rightArray[1] = ptr;
str = GetCRCTextStringCols(crcindex, 0);//取天地密钥
leftArray[2] = str;
ptr = GetCRCTextStringCols(crcindex, 1);//取星期密钥
rightArray[2] = ptr;
str = GetCRCTextStringCols(crcindex, 5);//取扩展密钥
len = str.length >>> 1;
leftArray[3] = StringLeft(str, len);
rightArray[3] = StringRight(str, len);
HotWC3CRCWorkString[index + 0] = leftArray.join("-");
HotWC3CRCWorkString[index + 1] = rightArray.join("-");
return;
}
function SetCRCTextValue(passindex, passhex)
{
return SetCRCTextString(idselecrcnmode.selectedIndex, passindex, passhex);
}
function SetCRCTextString(crcindex, passindex, passhex)
{
var patrn = /^[0-9a-fA-F]+$/;//正则表达式
var bits = [2, 2, 4, 8, 8, 8];//长度
var strArray = new Array();
var err = false;
var str;
if((crcindex >= 0) && (crcindex <= 7) && (passindex >= 0) && (passindex <= 5) && (passhex.length == bits[passindex]) && patrn.test(passhex)){
strArray = HotWC3CRCTextString[crcindex].split("-");//密钥之间用"-"隔开
strArray[passindex] = passhex;//填写
HotWC3CRCTextString[crcindex] = strArray.join("-");
err = true;
}
return err;
}
function GetCRCTextValue(passindex)
{
return GetCRCTextString(idselecrcnmode.selectedIndex, passindex);
}
function GetCRCTextString(crcindex, passindex)
{
var strArray = new Array();
var passhex = "";//失败返回空
if((crcindex >= 0) && (crcindex <= 7) && (passindex >= 0) && (passindex <= 5)){
strArray = HotWC3CRCTextString[crcindex].split("-");//密钥之间用"-"隔开
passhex = strArray[passindex];//读出
}
return passhex;
}
function GetCRCTextStringCols(crcindex, index)
{
/*
index=CRCn
天地密钥:GetCRCTextStringCols(crcindex, 0),长度=2*(idselecrcnmode.selectedIndex+1)
星期密钥:GetCRCTextStringCols(crcindex, 1),长度=2*(idselecrcnmode.selectedIndex+1)
三角密钥:GetCRCTextStringCols(crcindex, 2),长度=4*(idselecrcnmode.selectedIndex+1)
日期密钥:GetCRCTextStringCols(crcindex, 3),长度=8*(idselecrcnmode.selectedIndex+1)
用户密钥:GetCRCTextStringCols(crcindex, 4),长度=8*(idselecrcnmode.selectedIndex+1)
扩展密钥:GetCRCTextStringCols(crcindex, 5),长度=8*(idselecrcnmode.selectedIndex+1)
*/
var strArray = new Array();
var i, str, passhex = "";//失败返回空
if((index >= 0) && (index <= 5)){
for(i = 0;i <= crcindex;i++) {
strArray = HotWC3CRCTextString[i].split("-");//密钥之间用"-"隔开
str = strArray[index];//读出,CRC8在最前面,即按大端排列
passhex += str;
}
}
return passhex;
}
function RefreshCRCTextString()
{//刷新,不替换CRCn
LoadCRCTextString(idselecrcnmode.selectedIndex);
}
function UpdateCRCTextString(crcindex)
{//替换CRCn
idselecrcnmode.selectedIndex=crcindex;
LoadCRCTextString(crcindex);
}
function LoadCRCTextString(crcindex)
{
//转载不改变CRCn
/*
天地密钥:SetCRCTextValue(0, passhex)
星期密钥:SetCRCTextValue(1, passhex)
三角密钥:SetCRCTextValue(2, passhex)
日期密钥:SetCRCTextValue(3, passhex)
用户密钥:SetCRCTextValue(4, passhex)
扩展密钥:SetCRCTextValue(5, passhex)
CRC8内核,crcindex=0
天地:HotWC3TextString_0_0:wc3pass
星期:HotWC3TextString_0_1:weekpass
三角:HotWC3TextString_0_2:trianglepass
日期:HotWC3TextString_0_3:datepass
用户:HotWC3TextString_0_4:userpass
扩展:HotWC3TextString_0_5:userexpass
CRC16内核,crcindex=1
天地:HotWC3TextString_1_0:wc3pass
星期:HotWC3TextString_1_1:weekpass
三角:HotWC3TextString_1_2:trianglepass
日期:HotWC3TextString_1_3:datepass
用户:HotWC3TextString_1_4:userpass
扩展:HotWC3TextString_1_5:userexpass
CRC64内核,crcindex=7
天地:HotWC3TextString_7_0:wc3pass
星期:HotWC3TextString_7_1:weekpass
三角:HotWC3TextString_7_2:trianglepass
日期:HotWC3TextString_7_3:datepass
用户:HotWC3TextString_7_4:userpass
扩展:HotWC3TextString_7_5:userexpass
*/
var i, j, str, ptr, obj;
var bits = [2, 2, 4, 8, 8, 8];//长度
if(crcindex >= 8){
for(i = 0; i < 7;i++){//天地密钥…扩展密钥以及内核
str = "HotWC3TextString_X_" + i;
obj=document.getElementById(str);
obj.readOnly = true;
obj.style.color = "blue";
obj.style.backgroundColor = "#ddd";
obj.style.textAlign = "center";
}
for(i = 0; i < 8;i++){//CRC8-CRC64
str = "HotWC3TextString_" + i + "_X";
obj=document.getElementById(str);
obj.readOnly = true;
obj.style.color = "blue";
obj.style.backgroundColor = "#ddd";
}
for(i = 0;i < 8;i++){
for(j = 0;j < 6;j++){
str = "HotWC3TextString_" + i + "_"+j;
obj = document.getElementById(str);
obj.onchange = SetCRCTextValueChange;//安装输入验证回调函数
obj.maxlength = bits[j];
}
str = "HotWC3TextString_" + i + "_X";
obj=document.getElementById(str);
obj.onclick = SeleCRCnselectedIndex;//安装选择CRCn回调函数
}
}
else{
LoadHotWC3CRCTextToWorkString(crcindex);//加密解密时,装载密钥流
// gCRCPolyArrayDisturbance="";
for(i = 0; i <= crcindex;i++){//开放CRCn
for(j = 0; j < 6;j++){//6个密钥
str = "HotWC3TextString_" + i + "_" + j;
obj=document.getElementById(str);
obj.readOnly = false;
obj.value = GetCRCTextString(i, j);
obj.style.backgroundColor = "powderblue";
obj.onclick = "";//删除回调函数
obj.onfocus=SeleTextFocusColor;//安装选择聚焦颜色回调函数
obj.onblur=SeleTextBlurColor;//安装选择聚焦颜色回调函数
}
}
for(; i < 8;i++){
for(j = 0; j < 6;j++){
str = "HotWC3TextString_" + i + "_" + j;
obj=document.getElementById(str);
ptr = obj.value;
obj.readOnly = true;
SetCRCTextString(i, j, ptr);
obj.value = "";
obj.style.backgroundColor = "#ddd";
obj.onclick = SeleCRCnselectedIndex;//安装选择CRCn回调函数
}
}
}
}
function SeleTextFocusColor()
{
//安装选择聚焦颜色回调函数
this.style.backgroundColor = "white";
this.style.Color="black";
}
function SeleTextBlurColor()
{
//安装选择聚焦颜色回调函数
this.style.backgroundColor = "powderblue";
this.style.Color="black";
}
function StringTest0(str)
{
var len = str.length;
for(var i=0;i<len;i++){
if(str[i] != "0") {
return false;
}
}
return true;
}
function SetCRCTextValueChange()
{//输入验证回调函数
var crcindex, passindex;
var strArray = new Array();
var patrn = /^[0-9a-fA-F]+$/;//正则表达式
var str;
str = this.id;
strArray = str.split("_");
crcindex = parseInt(strArray[1]);
passindex = parseInt(strArray[2]);
str = this.value;
if((str.length == this.maxlength) && (patrn.test(str))){
if(StringTest0(str)){
alert("请注意: 您输入了一个弱密钥!!!");
}
else{
str = str.toUpperCase();
this.value = str;
}
SetCRCTextString(crcindex, passindex, str);//写入
return;
}
this.value = GetCRCTextString(crcindex, passindex);//恢复原来的密钥
if(str.length != this.maxlength){
alert("输入长度错误!!!\n正确一个输入" + this.maxlength + "个16进制数!!!");
}
else{
alert("请输入16进制数!!!");
}
}
function SeleCRCnselectedIndex()
{//选择CRCn回调函数
var crcindex;
var strArray = new Array();
var str,ptr;
ptr=this.value;
str = this.id;
strArray = str.split("_");
crcindex = parseInt(strArray[1]);
UpdateCRCTextString(crcindex);
if(ptr==""){
this.style.backgroundColor = "white";
this.style.Color="black";
this.onblur = SeleTextBlurColor;//安装选择失去焦点颜色回调函数
}
}
function hotwc3filecheckboxChange() {
if(hotwc3filecheckbox.checked) {
if(!(TestIE() || TestFILE())){
hotwc3filecheckbox.checked = false;
if(displayout.checked) idTextBox.value = "本浏览器浏览器不支持文件操作!!!";
}
}
if(hotwc3filecheckbox.checked) {
hotwc3passload.style.display = "";
hotwc3dispassload.style.display = "";
if(idbHotWC3TextBoxCount.selectedIndex < 3) {
idbHotWC3TextBoxCount.selectedIndex = 3;
wc3input.rows = parseInt(idbHotWC3TextBoxCount.value);
wc3output.rows = parseInt(idbHotWC3TextBoxCount.value);
}
}
else {
hotwc3passload.style.display = "none";
hotwc3dispassload.style.display = "none";
}
}
function crcfilecheckboxChange() {
if(crcfilecheckbox.checked) {
if(!(TestIE() || TestFILE())){
crcfilecheckbox.checked = false;
if(displayout.checked) idTextBox.value = "本浏览器浏览器不支持文件操作!!!";
return;
}
}
}
function filecheckboxChange() {
if(filecheckbox.checked) {
if(!(TestIE() || TestFILE())){
filecheckbox.checked = false;
if(displayout.checked) idTextBox.value = "本浏览器浏览器不支持文件操作!!!";
return;
}
}
else{
filecheckbox.checked = TestIE() || TestFILE();
}
}
function HotwclocalStorage()
{
if(localStoragecheckbox.checked){
if(!TestLS()){
alert("不能本地存储!!!");
}
}
else{
if(TestLS()){
alert("可以本地存储!!!");
}
}
localStoragecheckbox.checked = TestLS();
}
function hotwc3wifi()
{
if(hotwc3wificheckbox.checked){
if(!TestWF()){
alert("没有发现网络!!!");
}
}
else{
if(TestWF()){
alert("有网络!!!");
}
}
hotwc3wificheckbox.checked = TestWF();
}
function hotwc3online()
{
if(hotwc3onlinecheckbox.checked){
if(!TestOL()){
alert("无网络,离线状态!!!");
}
}
else{
if(TestOL()){
alert("有网络,在线状态!!!");
}
}
hotwc3onlinecheckbox.checked = TestOL();
}
function iecheckboxChange() {
if(iecheckbox.checked) {
if(!TestIE()){
iecheckbox.checked = false;
if(displayout.checked) idTextBox.value = "非IE浏览器不得选中!!!";
return;
}
else{
alert("您使用的是IE浏览器!!!");
}
}
else{
if(!TestIE()){
alert("您使用的不是IE浏览器!!!");
}
}
selecodemode();
}
function wincheckboxChange() {
if(wincheckbox.checked) {
if(!TestWIN()){
alert("您使用的不是Windows操作系统!!!");
}
else{
alert("您使用的是Windows操作系统!!!");
}
}
wincheckbox.checked = TestWIN();
}
function ioscheckboxChange() {
if(ioscheckbox.checked) {
if(!TestiOS()){
alert("您使用的不是苹果Safari浏览器!!!");
}
else{
alert("您使用的是苹果Safari浏览器!!!");
}
}
ioscheckbox.checked = TestiOS();
}
function adrcheckboxChange() {
if(adrcheckbox.checked) {
if(!TestAdr()){
alert("您使用的不是安卓手机!!!");
}
else{
alert("您使用的是安卓手机!!!");
}
}
adrcheckbox.checked = TestAdr();
}
function TestIE()
{
return (navigator.userAgent.indexOf('Trident') > 0) || ((navigator.userAgent.indexOf('MSIE') > 0) && (navigator.userAgent.indexOf('Opera') < 0));
}
function TestEdge()
{
//Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299
return (navigator.userAgent.indexOf('Edge') > 0);
}
function TestAdr()
{
return !TestWIN() && !TestiOS() && ((navigator.userAgent.indexOf('Android') > 0) || (navigator.userAgent.indexOf('Adr')));
}
function TestiOS()
{
return (navigator.userAgent.match(/(iphone|iPod|iPad);?/i));
}
function TestWIN()
{
return (navigator.userAgent.indexOf('Windows NT') > 0);
}
function TestSS()
{//
try {
// return !TestIE() && 'sessionStorage' in window && window['sessionStorage'] !== null;
return window.sessionStorage != null;
} catch (e) {
return false;
}
}
function TestLS()
{//
// return window.localStorage != null;
try {
// return !TestIE() && 'localStorage' in window && window['localStorage'] !== null;
return window.localStorage != null;
} catch (e) {
return false;
}
}
function TestFILE() {
// return (window.File && Window.FileList && window.FileReader && window.Blob);
try {
return (window.File && window.FileReader && window.Blob) && !TestEdge();
} catch (e) {
return false;
}
}
function TestOL()
{
var url = location.href;//http://www.21ic.com/tools/HotPower/HotCRC.html
return (url.substr(0, 7) == "http://");
}
function TestWF()
{
return (navigator && navigator.onLine !== false);
}
var g_text12_Storage = "0123456789ABCDEF";
function Changetext12()
{
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
switch(operatorsele.selectedIndex)
{
case 0://CRC运算
if(idselecodemode.selectedIndex == 0) text12.value = HexStringFormat(text12.value);
if(text12.value != "") g_text12_Storage = text12.value;
break;
case 13://
if(idselecodemode.selectedIndex == 0) text12.value = HexStringFormat(text12.value);
break;
case 1://^
case 2://!
case 3://&
case 4://|
case 5://"<<"
case 6://">>"
case 7://+
case 8://-
case 9://$大小端
case 10://"@反转
case 12://CRC算法逆向
text12.value = HexStringFormat(text12.value);
break;
case 11://HTML压缩
break;
case 14://Unicode编码
break;
case 15://GB2312-80编码
break;
case 16://HotCode
break;
case 17://ASCII
break;
case 18://BASE64
break;
case 19://UUEncode编码
break;
case 20://XXEncode编码
break;
case 21://Quoted-printable
break;
case 22://UTF-8
break;
case 23://区位码
break;
}
}
function Changetext13()
{
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
switch(operatorsele.selectedIndex)
{
case 0://CRC运算
case 1://^
case 3://&
case 4://|
case 5://"<<"
case 6://">>"
case 7://+
case 8://-
case 12://CRC算法逆向
case 15://GB2312-80编码
case 16://HotCode
case 17://ASCII
case 22://UTF-8
case 23://区位码
text13.value = HexStringFormat(text13.value);
break;
}
}
function HexStringFormat(str)
{
//var patrn = /^[\r 0-9a-fA-F]+$/;//正则表达式
var patrn = /[0-9a-fA-F]/;//正则表达式
var i, ptr, ch;
ptr = "";
for(i = 0;i < str.length;i ++)
{
ch = str.substr(i, 1);
if(patrn.test(ch)){
ptr += ch;
}
}
return ptr.toUpperCase();
}
function ChangeidTextBox()
{
var str, strArray = new Array();
var i, k, str, row, len, cols, count;
if(TestIE()) strArray = idTextBox.value.split("\r\n");
else strArray = idTextBox.value.split("\n");
cols = idTextBox.cols;
count = 0;
row = 0;
for(i = 0; i < strArray.length; i++){
str = strArray[i];
if(str == "") row++;
else{
str = CodeStringToHex(str, 5);//采用HotCode编码
len = str.length >>> 1;//用HotCode测试长度
count += len;
k = len % cols;
len = Math.floor(len / cols);
row += len + ((k == 0) ? 0 : 1);
}
}
for(i = 0; i < idbTextBoxCount.length; i++){
str = idbTextBoxCount.options[i].value;
if(row <= parseInt(str)){
i++;
break;
}
}
idbTextBoxCount.selectedIndex = i - 1;
idTextBox.rows = parseInt(idbTextBoxCount.options[i - 1].value);
crceditcount.value = count;
return count;//
}
function idclipboard(id)
{
if(TestWIN()){
id.focus();
id.select();
}
else {
var n=id.hasAttribute("readonly");
n||id.setAttribute("readonly",""),id.select(),id.setSelectionRange(0,id.value.length),n||id.removeAttribute("readonly");
}
return document.execCommand("copy");
}
function wc3inputclipboard()
{
if(idclipboard(wc3input)) alert("明文编辑框的内容已经被全部复制,请在其它地方用Ctrl+V粘贴过去!!!");
else alert("该浏览器不支持自动复制,请手工复制粘贴!!!");
}
function wc3outputclipboard()
{
if(idclipboard(wc3output)) alert("密文编辑框的内容已经被全部复制,请在其它地方用Ctrl+V粘贴过去!!!");
else alert("该浏览器不支持自动复制,请手工复制粘贴!!!");
}
function wc3inputanalysisclipboard()
{
if(idclipboard(wc3inputanalysis)) alert("明文分析编辑框的内容已经被全部复制,请在其它地方用Ctrl+V粘贴过去!!!");
else alert("该浏览器不支持自动复制,请手工复制粘贴!!!");
}
function wc3outputanalysisclipboard()
{
if(idclipboard(wc3outputanalysis)) alert("密文分析编辑框的内容已经被全部复制,请在其它地方用Ctrl+V粘贴过去!!!");
else alert("该浏览器不支持自动复制,请手工复制粘贴!!!");
}
function webinputclipboard()
{
if(idclipboard(webinputconversion)) alert("网页源编辑框的内容已经被全部复制,请在其它地方用Ctrl+V粘贴过去!!!");
else alert("该浏览器不支持自动复制,请手工复制粘贴!!!");
}
function weboutputclipboard()
{
if(idclipboard(weboutputconversion)) alert("网页目的编辑框的内容已经被全部复制,请在其它地方用Ctrl+V粘贴过去!!!");
else alert("该浏览器不支持自动复制,请手工复制粘贴!!!");
}
function texteditclipboard()
{
if(idclipboard(idTextBox)) alert("主编辑框的内容已经被全部复制,请在其它地方用Ctrl+V粘贴过去!!!");
else alert("该浏览器不支持自动复制,请手工复制粘贴!!!");
}
function ChangeidinputHotWC3TextBox()
{
var str, strArray = new Array();
var i, k, str, row, len, cols, count;
if(TestIE()) strArray = wc3input.value.split("\r\n");
else strArray = wc3input.value.split("\n");
cols = wc3input.cols;
count = 0;
row = 0;
for(i = 0; i < strArray.length; i++){
str = strArray[i];
if(str == "") row++;
else{
str = CodeStringToHex(str, 5);//采用HotCode编码
len = str.length >>> 1;//用HotCode测试长度
count += len;
k = len % cols;
len = Math.floor(len / cols);
row += len + ((k == 0) ? 0 : 1);
}
}
for(i = 0; i < idbHotWC3TextBoxCount.length; i++){
str = idbHotWC3TextBoxCount.options[i].value;
if(row <= parseInt(str)){
i++;
break;
}
}
idbHotWC3TextBoxCount.selectedIndex = Math.max(i - 1, idbHotWC3TextBoxCount.selectedIndex);
ChangeHotWC3TextBox();
wc3inputcount.value = count;//最大字节数
// HotWC3MessageRangeText.max = count;//最大位置
// HotWC3MessagePosText.max = count;//最大位置
HotWC3MessageRowText.max = strArray.length;//最大行数
return count;//
}
function ChangeidoutputHotWC3TextBox()
{
var str, strArray = new Array();
var i, k, str, row, len, cols, count;
if(TestIE()) strArray = wc3output.value.split("\r\n");
else strArray = wc3output.value.split("\n");
cols = wc3output.cols;
count = 0;
row = 0;
for(i = 0; i < strArray.length; i++){
str = strArray[i];
if(str == "") row++;
else{
str = CodeStringToHex(str, 5);//采用HotCode编码
len = str.length >>> 1;//用HotCode测试长度
count += len;
k = len % cols;
len = Math.floor(len / cols);
row += len + ((k == 0) ? 0 : 1);
}
}
for(i = 0; i < idbHotWC3TextBoxCount.length; i++){
str = idbHotWC3TextBoxCount.options[i].value;
if(row <= parseInt(str)){
i++;
break;
}
}
idbHotWC3TextBoxCount.selectedIndex = Math.max(i - 1, idbHotWC3TextBoxCount.selectedIndex);
ChangeHotWC3TextBox();
wc3outputcount.value = count;
return count;//
}
function ChangeidHotWC3inputTextBoxanalysis()
{
var str, strArray = new Array();
var i, k, str, row, len, cols, count;
if(TestIE()) strArray = wc3inputanalysis.value.split("\r\n");
else strArray = wc3inputanalysis.value.split("\n");
cols = wc3inputanalysis.cols;
count = 0;
row = 0;
for(i = 0; i < strArray.length; i++){
str = strArray[i];
if(str == "") row++;
else{
str = CodeStringToHex(str, 5);//采用HotCode编码
len = str.length >>> 1;//用HotCode测试长度
count += len;
k = len % cols;
len = Math.floor(len / cols);
row += len + ((k == 0) ? 0 : 1);
}
}
for(i = 0; i < idbHotWC3inputPassCount.length; i++){
str = idbHotWC3inputPassCount.options[i].value;
if(row <= parseInt(str)){
i++;
break;
}
}
idbHotWC3inputPassCount.selectedIndex = i - 1;
wc3inputanalysis.rows = parseInt(idbHotWC3inputPassCount.options[i - 1].value);
return count;//
}
function ChangeidHotWC3outputTextBoxanalysis()
{
var str, strArray = new Array();
var i, k, str, row, len, cols, count;
if(TestIE()) strArray = wc3outputanalysis.value.split("\r\n");
else strArray = wc3outputanalysis.value.split("\n");
cols = wc3outputanalysis.cols;
count = 0;
row = 0;
for(i = 0; i < strArray.length; i++){
str = strArray[i];
if(str == "") row++;
else{
str = CodeStringToHex(str, 5);//采用HotCode编码
len = str.length >>> 1;//用HotCode测试长度
count += len;
k = len % cols;
len = Math.floor(len / cols);
row += len + ((k == 0) ? 0 : 1);
}
}
for(i = 0; i < idbHotWC3outputPassCount.length; i++){
str = idbHotWC3outputPassCount.options[i].value;
if(row <= parseInt(str)){
i++;
break;
}
}
idbHotWC3outputPassCount.selectedIndex = i - 1;
wc3outputanalysis.rows = parseInt(idbHotWC3outputPassCount.options[i - 1].value);
return count;//
}
function Changeidwebinputconversion()
{
var str, strArray = new Array();
var i, k, str, row, len, cols, count;
if(TestIE()) strArray = webinputconversion.value.split("\r\n");
else strArray = webinputconversion.value.split("\n");
if(idWebOnlineCompressor.value == "网页压缩"){//https://jsmin.51240.com/
idbWebTextRowStart.value = "1";
idbWebTextRowSize.value = strArray.length;
idbWebTextRowLength.value = strArray.length;
}
cols = webinputconversion.cols;
count = 0;
row = 0;
for(i = 0; i < strArray.length; i++){
str = strArray[i];
if(str == "") row++;
else{
str = CodeStringToHex(str, 5);//采用HotCode编码
len = str.length >>> 1;//用HotCode测试长度
count += len;
k = len % cols;
len = Math.floor(len / cols);
row += len + ((k == 0) ? 0 : 1);
}
}
for(i = 0; i < idwebinputconversionCount.length; i++){
str = idwebinputconversionCount.options[i].value;
if(row <= parseInt(str)){
i++;
break;
}
}
idwebinputconversionCount.selectedIndex = i - 1;
webinputconversion.rows = parseInt(idwebinputconversionCount.options[i - 1].value);
return count;//
}
function Changeidweboutputconversion()
{
var str, strArray = new Array();
var i, k, str, row, len, cols, count;
if(TestIE()) strArray = weboutputconversion.value.split("\r\n");
else strArray = weboutputconversion.value.split("\n");
cols = weboutputconversion.cols;
count = 0;
row = 0;
for(i = 0; i < strArray.length; i++){
str = strArray[i];
if(str == "") row++;
else{
str = CodeStringToHex(str, 5);//采用HotCode编码
len = str.length >>> 1;//用HotCode测试长度
count += len;
k = len % cols;
len = Math.floor(len / cols);
row += len + ((k == 0) ? 0 : 1);
}
}
for(i = 0; i < idweboutputconversionCount.length; i++){
str = idweboutputconversionCount.options[i].value;
if(row <= parseInt(str)){
i++;
break;
}
}
idweboutputconversionCount.selectedIndex = i - 1;
weboutputconversion.rows = parseInt(idweboutputconversionCount.options[i - 1].value);
return count;//
}
function Changeidframeverifytext()
{
var str, strArray = new Array();
var i, k, str, row, len, cols, count;
if(TestIE()) strArray = frameverifytext.value.split("\r\n");
else strArray = frameverifytext.value.split("\n");
cols = frameverifytext.cols;
count = 0;
row = 0;
for(i = 0; i < strArray.length; i++){
str = strArray[i];
if(str == "") row++;
else{
str = CodeStringToHex(str, 5);//采用HotCode编码
len = str.length >>> 1;//用HotCode测试长度
count += len;
k = len % cols;
len = Math.floor(len / cols);
row += len + ((k == 0) ? 0 : 1);
}
}
for(i = 0; i < frameverifytextCount.length; i++){
str = frameverifytextCount.options[i].value;
if(row <= parseInt(str)){
i++;
break;
}
}
frameverifytextCount.selectedIndex = i - 1;
frameverifytext.rows = parseInt(frameverifytextCount.options[i - 1].value);
return count;//
}
function Changeidframeverifyresult()
{
var str, strArray = new Array();
var i, k, str, row, len, cols, count;
if(TestIE()) strArray = frameverifyresult.value.split("\r\n");
else strArray = frameverifyresult.value.split("\n");
cols = frameverifyresult.cols;
count = 0;
row = 0;
for(i = 0; i < strArray.length; i++){
str = strArray[i];
if(str == "") row++;
else{
str = CodeStringToHex(str, 5);//采用HotCode编码
len = str.length >>> 1;//用HotCode测试长度
count += len;
k = len % cols;
len = Math.floor(len / cols);
row += len + ((k == 0) ? 0 : 1);
}
}
for(i = 0; i < frameverifyresultCount.length; i++){
str = frameverifyresultCount.options[i].value;
if(row <= parseInt(str)){
i++;
break;
}
}
frameverifyresultCount.selectedIndex = i - 1;
frameverifyresult.rows = parseInt(frameverifyresultCount.options[i - 1].value);
return count;//
}
function clearinittext()
{//初值
var str, crcbits, val, crcnum;
var tabArray = new Array(2);
tabArray[0] = "0000000000000000";
tabArray[1] = "FFFFFFFFFFFFFFFF";
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
if(text120.value == tabArray[0].substr(0, crcnum)){
text120.value = tabArray[1].substr(0, crcnum);
}
else if(text120.value == tabArray[1].substr(0, crcnum)){
text120.value = getrandomnum(crcnum);
}
else text120.value = tabArray[0].substr(0, crcnum);
SetCRCTableArrayInitString(text120.value);
WriteCRCTableArrayTextString();
}
function ChangeInittext()
{
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
if(!patrn.test(text120.value)) {
alert("请输入16进制数!!!");
text120.value = GetCRCTableArrayInitString();
}
else {
text120.value = text120.value.toUpperCase();
if (text120.value.length == GetCRCTableArrayBitsInt() / 4)
{
SetCRCTableArrayInitString(text120.value);
WriteCRCTableArrayTextString();
}
else
{
alert("出值位数不对!!!");
text120.value = GetCRCTableArrayInitString();
text120.value.focus();
text120.value.select();
}
}
}
function button15()
{//取反
var str, crcbits, val, crcnum;
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
if (crcbits <= 32)
{
val = hextoint(text120.value);
val ^= 0xffffffff;
text120.value = inttohex(val, crcnum);
}
else
{
crcnum -= 8;
val = hextoint(text120.value.substr(0, crcnum));
val ^= 0xffffffff;
str = inttohex(val, crcnum);
val = hextoint(text120.value.substr(crcnum, 8));
val ^= 0xffffffff;
text120.value = str + inttohex(val, 8);
}
SetCRCTableArrayInitString(text120.value);
WriteCRCTableArrayTextString();
}
function clearstoptext()
{//出值
var str, crcbits, val, crcnum;
var tabArray = new Array(2);
tabArray[0] = "0000000000000000";
tabArray[1] = "FFFFFFFFFFFFFFFF";
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
if(text170.value == tabArray[0].substr(0, crcnum)){
text170.value = tabArray[1].substr(0, crcnum);
}
else if(text170.value == tabArray[1].substr(0, crcnum)){
text170.value = getrandomnum(crcnum);
}
else text170.value = tabArray[0].substr(0, crcnum);
SetCRCTableArrayStopString(text170.value);
WriteCRCTableArrayTextString();
}
function ChangeStoptext()
{
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
if(!patrn.test(text170.value)) {
alert("请输入16进制数!!!");
text170.value = GetCRCTableArrayStopString();
}
else {
text170.value = text170.value.toUpperCase();
if (text170.value.length == GetCRCTableArrayBitsInt() / 4)
{
SetCRCTableArrayStopString(text170.value);
WriteCRCTableArrayTextString();
}
else
{
alert("出值位数不对!!!");
text170.value = GetCRCTableArrayStopString();
text170.value.focus();
text170.value.select();
}
}
}
function button16()
{//取反
var str, crcbits, val, crcnum;
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
if (crcbits <= 32)
{
val = hextoint(text170.value);
text170.value = inttohex(~val, crcnum);
}
else
{
crcnum -= 8;
val = hextoint(text170.value.substr(0, crcnum));
val ^= 0xffffffff;
str = inttohex(val, crcnum);
val = hextoint(text170.value.substr(crcnum, 8));
val ^= 0xffffffff;
text170.value = str + inttohex(val, 8);
}
SetCRCTableArrayStopString(text170.value);
WriteCRCTableArrayTextString();
}
function selefunction()
{//功能
if (operatorsele.selectedIndex == 0)
{
operatorsele.selectedIndex = 12;//CRC算法逆向
}
else if (operatorsele.selectedIndex == 12)
{
operatorsele.selectedIndex = 13;//CRC源码
}
else
{
operatorsele.selectedIndex = 0;//CRC基本运算
}
changeoperator();
}
function ChangeTextBox()
{
if (parseInt(idbTextBoxCount.value) > 0)
idTextBox.rows = parseInt(idbTextBoxCount.value);
}
function ChangeTextBoxSet()
{
idbTextBoxCount.selectedIndex = 2;
idTextBox.rows = parseInt(idbTextBoxCount.value);
}
function ChangeHotWC3TextBox()
{
if (parseInt(idbHotWC3TextBoxCount.value) > 0){
wc3input.rows = parseInt(idbHotWC3TextBoxCount.value);
wc3output.rows = parseInt(idbHotWC3TextBoxCount.value);
}
}
function ChangeHotWC3inputanalysisTextBox()
{
if (parseInt(idbHotWC3inputPassCount.value) > 0){
wc3inputanalysis.rows = parseInt(idbHotWC3inputPassCount.value);
}
}
function ChangeHotWC3outputanalysisTextBox()
{
if (parseInt(idbHotWC3outputPassCount.value) > 0){
wc3outputanalysis.rows = parseInt(idbHotWC3outputPassCount.value);
}
}
function ChangeidwebinputconversionTextBox()
{
if (parseInt(idwebinputconversionCount.value) > 0){
webinputconversion.rows = parseInt(idwebinputconversionCount.value);
}
}
function ChangeidweboutputconversionTextBox()
{
if (parseInt(idweboutputconversionCount.value) > 0){
weboutputconversion.rows = parseInt(idweboutputconversionCount.value);
}
}
function ChangeframeverifytextCount()
{
if (parseInt(frameverifytextCount.value) > 0){
frameverifytext.rows = parseInt(frameverifytextCount.value);
}
}
function ChangeframeverifyresultCount()
{
if (parseInt(frameverifyresultCount.value) > 0){
frameverifyresult.rows = parseInt(frameverifyresultCount.value);
}
}
function ChangeHotWC3inputTextBoxanalysisSet()
{
idbHotWC3inputPassCount.selectedIndex = 2;
wc3inputanalysis.rows = parseInt(idbHotWC3inputPassCount.value);
}
function ChangeHotWC3outputTextBoxanalysisSet()
{
idbHotWC3outputPassCount.selectedIndex = 2;
wc3outputanalysis.rows = parseInt(idbHotWC3outputPassCount.value);
}
function ChangeidwebinputconversionSet()
{
idwebinputconversionCount.selectedIndex = 2;
webinputconversion.rows = parseInt(idwebinputconversionCount.value);
}
function ChangeidweboutputconversionSet()
{
idweboutputconversionCount.selectedIndex = 2;
weboutputconversion.rows = parseInt(idweboutputconversionCount.value);
}
function ChangeframeverifytextSet()
{
frameverifytextCount.selectedIndex = 2;
frameverifytext.rows = parseInt(frameverifytextCount.value);
}
function ChangeidframeverifyresultSet()
{
frameverifyresultCount.selectedIndex = 2;
frameverifyresult.rows = parseInt(frameverifyresultCount.value);
}
function ChangeHotWC3TextBoxSet()
{
idbHotWC3TextBoxCount.selectedIndex = 3;
idTextBox.rows = parseInt(idbHotWC3TextBoxCount.value);
wc3input.rows = parseInt(idbHotWC3TextBoxCount.value);
wc3output.rows = parseInt(idbHotWC3TextBoxCount.value);;
}
function clearTextBox()
{//清空键
idTextBox.value = "";
ChangeidTextBox();
}
function ChnToNumString(cstr)
{
var i, str, hexstr, ascii;
hexstr = AscToHexString(cstr);
str = "";
for (i = 0; i < hexstr.length; i+=2)
{
ascii = hextoint(hexstr.substr(i, 2));
if (ascii > 0x7f)
{
ascii -= 0xa0;
if (ascii <= 0) str += "XX";
else
{
if (ascii < 10) str += "0";
str += ascii;
}
}
}
return str;
}
function NumToChnString(cstr)
{
var i, str, hexstr, number;
hexstr = "";
for (i = 0; i < cstr.length; i+=2)
{
number = parseInt(cstr.substr(i, 2), 10);
hexstr += inttohex(number + 0xa0, 2);
}
str = HexToAscString(hexstr);
return str;
}
function input_onKeyPress()
{
var patrn = /[\b\r\da-fA-F]/;//正则表达式
var ch = String.fromCharCode(event.keyCode);//
var result = patrn.test(ch);
if (!result)
{
event.keyCode = 0;
}
else
{
ch = ch.toUpperCase();
event.keyCode = ch.charCodeAt(0);
}
window.event.returnValue = result;
return result;
}
function buttonc1()
{
if (text1.value != '') text1.value = '';
else text1.value =getrandomnum(2);
}
function buttonc2()
{
if (text2.value != '') text2.value = '';
else text2.value =getrandomnum(4);
}
function buttonc3()
{
if (text3.value != '') text3.value = '';
else text3.value =getrandomnum(4);
}
function buttonc4()
{
if (text4.value != '') text4.value = '';
else text4.value =getrandomnum(4);
}
function buttonc5()
{
if (text5.value != '') text5.value = '';
else text5.value =getrandomnum(4);
}
function buttonc6()
{
var a, b, c;
a = parseInt(text7.value);
if(a >= 3){
if(a > 258){
b = getb(a);
c = getc(a);
text1.value = '';
text2.value = '';
text3.value = '';
text4.value = '';
text5.value = '';
text8.value = b;
text9.value = c;
text6.value = Math.asin(a / c) * 180 / Math.PI;
}
else{
text3.value = inttohex(a, 4);
button3();
text8.value = hextoint(text4.value);
text9.value = hextoint(text5.value);
}
if(seevalue0 != seevalue1){
if(text11.value == '') text11.value = 0;
text11.value = eval(text11.value) + 1;
seevalue0 = seevalue1;
alert("要诚实!!!");
}
}
else {
alert("A>=3!!!");
}
}
function ChkclrtextA()
{
text7.value = '250';
text8.value = '';
text9.value = '';
}
function ChkclrtextB()
{
text7.value = '';
text8.value = '250';
text9.value = '';
}
function ChkclrtextC()
{
text7.value = '';
text8.value = '';
text9.value = '250';
}
function clrtext10()
{
text10.value = '';
}
function button1()
{
var passa;
var a, b, c;
passa = hextoint(text1.value);
if(passa <= 255){
text1.value = inttohex(passa, 2);
text2.value = inttohex(password(passa), 4);//取密码BC
a = passa + 3;
b = getb(a);
c = getc(a);
text3.value = inttohex(a, 4);
text4.value = inttohex(b, 4);
text5.value = inttohex(c, 4);
text6.value = Math.asin(a / c) * 180 / Math.PI;
}
else{
text1.value = '';
text2.value = '';
text3.value = '';
text4.value = '';
text5.value = '';
text6.value = '';
}
text10.value = '';
}
function button2()
{
var passba, passbc, str1;
var a, b, c;
passbc = hextoint(text2.value);
if(passbc >=3){
passa = dispassword(passbc);
a = passa + 3;
b = getb(a);
c = getc(a);
text1.value = inttohex(passa, 2);
text2.value = inttohex(passbc, 4);
text3.value = inttohex(a, 4);
text4.value = inttohex(b, 4);
text5.value = inttohex(c, 4);
text6.value = Math.asin(a / c) * 180 / Math.PI;
}
else{
text1.value = '';
text2.value = '';
text3.value = '';
text4.value = '';
text5.value = '';
text6.value = '';
}
text10.value = '';
}
function button3()
{
var a, b, c;
a = hextoint(text3.value);
if((a >= 3) && (a <= 258)){//直角边a>=3,在a<=258时可加密解密
b = getb(a);
c = getc(a);
text1.value = inttohex(a - 3, 2);
text2.value = inttohex(password(a - 3), 4);//取密码BC
text3.value = inttohex(a, 4);
text4.value = inttohex(b, 4);
text5.value = inttohex(c, 4);
text6.value = Math.asin(a / c) * 180 / Math.PI;
}
else{
text1.value = '';
text2.value = '';
if(a >= 3){
b = getb(a);
c = getc(a);
text3.value = inttohex(a, 4);
text4.value = inttohex(b, 4);
text5.value = inttohex(c, 4);
text6.value = Math.asin(a / c) * 180 / Math.PI;
}
else{
text3.value = '';
text4.value = '';
text5.value = '';
text6.value = '';
}
}
text10.value = '';
}
function button4()
{
var a, b, c;
b = hextoint(text4.value);
a = getab(b);
if((a >= 3) && (a <= 258)){//直角边a>=3,在a<=258时可加密解密
c = getc(a);
text1.value = inttohex(a - 3, 2);
text2.value = inttohex(password(a - 3), 4);
text3.value = inttohex(a, 4);
text4.value = inttohex(b, 4);
text5.value = inttohex(c, 4);
text6.value = Math.asin(a / c) * 180 / Math.PI;
}
else{
text1.value = '';
text2.value = '';
if(a >= 3){
c = getc(a);
text3.value = inttohex(a, 4);
text4.value = inttohex(b, 4);
text5.value = inttohex(c, 4);
text6.value = Math.asin(a / c) * 180 / Math.PI;
}
else{
text3.value = '';
text4.value = '';
text5.value = '';
text6.value = '';
}
}
text10.value = '';
}
function button5()
{
var a, b, c;
c = hextoint(text5.value);
a = getac(c);
if((a >= 3) && (a <= 258)){//直角边a>=3,在a<=258时可加密解密
b = getb(a);
text1.value = inttohex(a - 3, 2);
text2.value = inttohex(password(a - 3), 4);
text3.value = inttohex(a, 4);
text4.value = inttohex(b, 4);
text5.value = inttohex(c, 4);
text6.value = Math.asin(a / c) * 180 / Math.PI;
}
else{
text1.value = '';
text2.value = '';
if(a >= 3){
b = getb(a);
text3.value = inttohex(a, 4);
text4.value = inttohex(b, 4);
text5.value = inttohex(c, 4);
text6.value = Math.asin(a / c) * 180 / Math.PI;
}
else{
text3.value = '';
text4.value = '';
text5.value = '';
text6.value = '';
}
}
text10.value = '';
}
function button61()
{
var k;
k = 88888;
while((k <3) || (k > 9)){
k = Math.floor(Math.random() * 10);
}
text6.value = '';
text7.value = k;//3<=k<=9
text8.value = '';
text9.value = '';
text10.value = '';
seevalue1 = k;
}
function button62()
{
var k;
k = 88888;
while((k <10) || (k > 99)){
k = Math.floor(Math.random() * 100);
}
text6.value = '';
text7.value = k;//10<=k<=99
text8.value = '';
text9.value = '';
text10.value = '';
seevalue1 = k;
}
function button63()
{
var k;
k = 88888;
while((k <100) || (k > 999)){
k = Math.floor(Math.random() * 1000);
}
text6.value = '';
text7.value = k;//100<=k<=999
text8.value = '';
text9.value = '';
text10.value = '';
seevalue1 = k;
}
function button64()
{
var k;
k = 88888;
while((k <1000) || (k > 9999)){
k = Math.floor(Math.random() * 10000);
}
text6.value = '';
text7.value = k;//1000<=k<=9999
text8.value = '';
text9.value = '';
text10.value = '';
seevalue1 = k;
}
function button65()
{
var k;
// k = 88888;
k = 888;
while((k <10000) || (k > 99999)){
k = Math.floor(Math.random() * 100000);
}
text6.value = '';
text7.value = k;//1000<=k<=9999
text8.value = '';
text9.value = '';
text10.value = '';
seevalue1 = k;
}
function button66()
{
var k;
k = 88888;
while((k <100000) || (k > 999999)){
k = Math.floor(Math.random() * 1000000);
}
text6.value = '';
text7.value = k;//1000<=k<=9999
text8.value = '';
text9.value = '';
text10.value = '';
seevalue1 = k;
}
function button67()
{
var k;
k = 88888;
while((k <1000000) || (k > 9999999)){
k = Math.floor(Math.random() * 10000000);
}
text6.value = '';
text7.value = k;//1000<=k<=9999
text8.value = '';
text9.value = '';
text10.value = '';
seevalue1 = k;
}
function button68()
{
var k;
k = 88888;
while((k <10000000) || (k > 99999999)){
k = Math.floor(Math.random() * 100000000);
}
text6.value = '';
text7.value = k;//1000<=k<=9999
text8.value = '';
text9.value = '';
text10.value = '';
seevalue1 = k;
}
function button7()
{
var a, b, c;
if(text7.value == '') return;
if((text8.value == '') || (text9.value == '')){
text10.value = "";
alert("请自做题!!!");
return;
}
a = parseInt(text7.value);
if(a >= 3) {
b = parseInt(text8.value);
c = parseInt(text9.value);
if((Math.pow(a, 2) + Math.pow(b, 2)) == Math.pow(c, 2)) {
text10.value = '100';
alert("答案正确!!!");
}
else {
if(b == getb(a) && c == getc(a)) {
text10.value = '100';
alert("答案正确,可能是JavaScript计算错误,请用计算器验算!!!");
}
else {
text10.value = '0';
alert("答案错误,请用计算器验算!!!");
}
}
}
else {
alert("A>=3!!!");
}
}
function DblClick10()
{
var a;
if(text7.value == '') text7.value = 3;
else{
a = parseInt(text7.value);
text7.value = a + 1;
}
}
function getcrcpolyhexstr(crcstr, crcbits, crcdir)
{
var str, cstr, i, len, start, count, val, bitlow, bithigh;
len = crcstr.length;
str = "";
start = 0;
count = 0;
bitlow = 0;
bithigh = 0;
if(crcstr.substr(len - 2, 2) == "+1") {
if ((crcdir & 1) == 0)//右移
{
if (crcbits > 32)
{
bithigh = (1 << (crcbits - 1));//可逆
}
else
{
bitlow |= (1 << (crcbits - 1));//可逆
}
}
else//左移
{
bitlow = 1;//可逆
}
len --;
}
else {
crcstr += "+";
len ++;
}
for (i = 0; i < len; i ++)
{
cstr = crcstr.substr(i, 1);
if (cstr == 'X')//位开始
{
start = i + 1;//**数字位置
count = 0;
}
else if (cstr == '+')//位结束
{
if (start > 0)
{
if (count == 0) val = 1;//X1
else val = parseInt(crcstr.substr(start, count));
if ((crcdir & 1) == 0)//右移
{
val = crcbits - val - 1;
}
if (val >= 32)
{
bithigh |= 1 << val;
}
else
{
bitlow |= 1 << val;
}
}
start = 0;
count = 0;
}
else if (cstr >= '0'&& cstr <= '9')
{
if (start) count ++;
}
}
if (crcbits > 32)//CRC36~CRC64
{
str = inttohex(bithigh, (crcbits - 32) / 4) + inttohex(bitlow, 8);
}
else//CRC4~CRC32
{
str = inttohex(bitlow, crcbits / 4);
}
return str;
}
function password(passa)
{//三角变换加密,已知勾a求弦c,股b也未知。
var passbc;//将勾a加密为股b(弦c)
passbc = eval(passa) + 3;//特殊整数直角三角形最小直角边勾a从3开始
if(passbc & 1){//勾a为奇数时,先平方
passbc = Math.pow(passbc,2);//平方运算
passbc >>>= 1;//除2(砍半),得到股b
passbc = (passbc >>> 1) | 0x8000;//右环移1位,为解密提供标志。
}
else{//勾股a为偶数时,先砍半后再平方
passbc = (passbc >>> 1);//除2(砍半)
passbc = Math.pow(passbc,2);//平方运算
passbc --;//减1为股b,返回股b
}
return passbc;//返回压缩密码bc
}
function dispassword(passbc)
{//三角变换解密
var passba, passb, passc;
if(passbc >= 0x8000){//数据变换还原
passb = (passbc & 0x7fff) * 2;
passc = passb + 1;
}
else{
passb = passbc;
passc = passb + 2;
}
passa = Math.pow(passc, 2) - Math.pow(passb, 2);//计算直角边a
passa = Math.sqrt(passa) - 3;//转换为原码A
return passa;//返回原码A
}
//直角三角形计算另一直角边公式
function getb(a)//a>=3,且为整数
{
var b;
if(a & 1){//三角边a为奇数
b = Math.pow(a, 2);//直接取平方
b = b / 2 - 0.5;//得到另一直角边
}
else{
b = Math.pow(a / 2, 2);//砍半后取平方
b = b - 1;//得到另一直角边
}
return b;//返回另一直角边
}
//直角三角形计算斜边公式
function getc(a)//a>=3,且为整数
{
var b,c;
if(a & 1){//三角边a为奇数
b = Math.pow(a, 2);//直接取平方
b = b / 2 - 0.5;//得到另一直角边
c = b + 1;//得到斜边
}
else{
b = Math.pow(a / 2, 2);//砍半后取平方
b = b - 1;//得到另一直角边
c = b + 2;//得到斜边
}
return c;//返回斜边
}
function getab(b)
{
var a, c;
c = b + 1;
a = Math.pow(c, 2) - Math.pow(b, 2);
a = Math.sqrt(a);
if(a == Math.floor(a))
return a;
c = b + 2;
a = Math.pow(c, 2) - Math.pow(b, 2);
a = Math.sqrt(a);
if(a == Math.floor(a))
return a;
return 0;
}
function getac(c)
{
var a, b;
b = c - 1;
a = Math.pow(c, 2)- Math.ppow(b, 2);
a = Math.sqrt(a);
if(a == Math.floor(a))
return a;
b = c - 2;
a = Math.pow(c, 2) - Math.pow(b, 2);
a = Math.sqrt(a);
if(a == Math.floor(a))
return a;
return 0;
}
//建立函数
function inttohex(num, size)
{
var str, ptr, len, i,j, s;
if(num >= 0) str = num.toString(16);
else{
num = -num;
i = num >> 16;
j = num & 0xffff;
i ^= 0xffff;
j ^= 0xffff;
j ++;
if(j > 0xffff){
j = 0;
i ++;
}
str = i.toString(16);
ptr = j.toString(16);
j = ptr.length;
if(j < 4) while(4 > j++) ptr = '0' + ptr;
str = str + ptr;
}
len = str.length;
if(len >= size) str = str.substr(len - size, size);
else{
while(size > len++) str = '0' + str;
}
return str.toUpperCase();
}
function StringReversalToString(str)
{//反转
var i, j, len;
var sstr, val, ibit, val;
sstr = "";
len = str.length;
for (i = len - 1; i >= 0; i --)
{
val = hextoint(str.substr(i, 1));
ibit = 0;
for (j = 0; j < 4; j ++)
{
ibit <<= 1;
if (val & (1 << j)) ibit ++;
}
sstr += inttohex(ibit, 1);
}
return sstr;
}
function StringDisInvertlToString(str)
{//反序的还原
var i, s, ch,size;
s = "";
ch = "";
size =str.length;
if(size & 1){
size--;
ch = str.substr(size, 1);
}
for (i = 0; i < size; i += 2)
{
s += str.substr(size - 2 - i, 2);
}
str = ch + s;
return str.toUpperCase();
}
function StringInvertlToString(str)//反序
{//反序的运算
var i, s, ch ,len;
len = str.length;
s = '';
ch = "";
if (len & 1)//CRC12
{
len --;
ch = str.substr(0, 1);
str= str.substr(1, len);
}
for (i = 0; i < len; i += 2)
{
s += str.substr(len - 2 - i, 2);
}
s += ch;
return s;
}
function StringTestInvertlToString(str)
{//带测试的反序运算
if (!selemode1.selectedIndex)
return StringInvertlToString(str);
else
return str.toUpperCase();
}
function StringTestDisInvertlToString(num, size)
{//带测试的反序还原
var str;
str = inttohex(num, size);
if (!selemode1.selectedIndex)
return StringDisInvertlToString(str);
else
return str.toUpperCase();
}
function StringQjDisInvertlToString(str)
{
if (!nxbigEndiancheckbox.checked)
return StringDisInvertlToString(str);
else
return str.toUpperCase();
}
function StringQjInvertlToString(str)
{
if (!nxbigEndiancheckbox.checked)
return StringInvertlToString(str);
else
return str.toUpperCase();
}
function hextoint(string)
{
return parseInt(string, 16);
}
function GetText12StringLen()
{
var str, len;
str = CodeStringToHex(text12.value, idselecodemode.selectedIndex);
len = str.length;
return len;
}
function polystrikbittext()
{
var str, ptr, crcbits, crcnum, len;
var stopvalue, val;
var strArray = new Array();
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
if(idnxcrcstart.value == "穷举") {
displayout.checked = true;
displayoutlabel.style.color = "red";
}
if(polystrikbit.value == "停止碰撞") {
clearTimeout(setTimeoutID);
polystrikbit.value = "权值碰撞";
return;
}
operatorsele.selectedIndex = 0;
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
len = GetText12StringLen();
// calculator();//运算
hotcrc();//运算
if(patrn.test(text140.value) && (text140.value.length == crcnum)){
_text140_value = text140.value;//保护结果
_text130_value = text130.value;//起始权值
_text160_value = text160.value;//起始权值
text130.value = StringINCToString(text130.value);
SetCRCTableArrayPolyString(text130.value);
strArray = text160.value.split("_");
str = strArray[0];
ptr = str.substr(0,str.length-1);
str = (StringRight(str,1)=="R")?"L":"R";
strArray[0]=ptr+str;
text160.value=strArray.join("_");
formattext160();
displayout.checked = false;
displayoutlabel.style.color = "blue";
if(idnxcrcstart.value == "穷举") {
idTextBox.value = "";
}
polystrikbit.value = "停止碰撞";
var d = new Date();
idTextBox.value += "穷举权值碰撞时间:" + d.toLocaleTimeString();
setTimeoutID = setTimeout(polystrikbittexttimeout, 5);
}
else {
if(crcnum != text140.value.length) {//检查结果
alert("结果长度必须等于权值长度!!!");
return;
}
if(!patrn.test(text140.value)) {
alert("结果请输入16进制数!!!");
return;
}
}
}
function polystrikbittexttimeout()
{
var str, crcbits, crcnum;
var stopvalue, val;
var strArray = new Array();
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
do {
// calculator();//运算
hotcrc();//运算
if(_text140_value == text140.value) {//找到权值
if(_text160_value != text160.value) {
idTextBox.value += "\n" + text160.value + ((discheckbox.checked) ? "(可逆)":"(不可逆)");
ChangeidTextBox();
}
}
text130.value = StringINCToString(text130.value);
SetCRCTableArrayPolyString(text130.value);
if(text130.value.substr(crcnum - 1, 1) == "0") {
break;
}
}while(_text130_value != text130.value);
if(_text130_value != text130.value) {
setTimeoutID = setTimeout(polystrikbittexttimeout, 5);
}
else {
if(_text160_value != text160.value) {
text160.value=_text160_value;
formattext160();
setTimeoutID = setTimeout(polystrikbittexttimeout, 5);
}
else{
text140.value = _text140_value;
if(idnxcrcstart.value == "穷举") {
displayout.checked = true;
displayoutlabel.style.color = "red";
polystrikbit.value = "权值碰撞";
var d = new Date();
idTextBox.value += "\n" + "权值碰撞结束时间:" + d.toLocaleTimeString();
}
}
}
}
function stopstrikbittext()
{
var str, crcbits, crcnum, len;
var stopvalue, val;
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
if(idnxcrcstart.value == "穷举") {
displayout.checked = true;
displayoutlabel.style.color = "red";
}
if(strikbity.value == "停止碰撞") {
clearTimeout(setTimeoutID);
strikbity.value = "出值碰撞";
return;
}
operatorsele.selectedIndex = 0;
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
len = GetText12StringLen();
if(patrn.test(text140.value) && (text140.value.length == crcnum)){
_text140_value = text140.value;
// calculator();//运算
hotcrc();//运算
stopvalue = StringXORToString(text140.value, text170.value);
stopvalue = StringXORToString(stopvalue,_text140_value);
SetCRCTableArrayStopString(stopvalue);
text140.value = _text140_value;
if(discheckbox.checked) {
idTextBox.value = "找到唯一出值碰撞:" + "\n" + text160.value + "(可逆)";
strikbity.value = "出值碰撞";
var d = new Date();
idTextBox.value += "\n穷举出值碰撞时间:" + d.toLocaleTimeString();
}
else {
_text140_value = text140.value;//保护结果
_text170_value = text170.value;//起始出值
displayout.checked = false;
displayoutlabel.style.color = "blue";
if(idnxcrcstart.value == "穷举") {
idTextBox.value = "";
}
strikbity.value = "停止碰撞";
var d = new Date();
idTextBox.value += "穷举出值碰撞时间:" + d.toLocaleTimeString();
setTimeoutID = setTimeout(stopstrikbittexttimeout, 5);
}
}
else {
if(crcnum != text140.value.length) {//检查结果
alert("结果长度必须等于权值长度!!!");
return;
}
if(!patrn.test(text140.value)) {
alert("结果请输入16进制数!!!");
return;
}
}
}
function stopstrikbittexttimeout()
{
var str, crcbits, crcnum;
var stopvalue, val;
var strArray = new Array();
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
do {
// calculator();//运算
hotcrc();//运算
if(_text140_value == text140.value) {//找到出值
idTextBox.value += "\n" + text160.value + ((discheckbox.checked) ? "(可逆)":"(不可逆)");
ChangeidTextBox();
}
text170.value = StringINCToString(text170.value);
SetCRCTableArrayStopString(text170.value);
if(text170.value.substr(crcnum - 1, 1) == "0") {
break;
}
}while(_text170_value != text170.value);
if(_text170_value != text170.value) {
setTimeoutID = setTimeout(stopstrikbittexttimeout, 5);
}
else {
text140.value = _text140_value;
if(idnxcrcstart.value == "穷举") {
displayout.checked = true;
displayoutlabel.style.color = "red";
strikbity.value = "出值碰撞";
var d = new Date();
idTextBox.value += "\n" + "出值碰撞结束时间:" + d.toLocaleTimeString();
}
}
}
var _text130_value, _text160_value, _text140_value, _text120_value, _text170_value;
var g_czpzcount = 0;
function startstrikbittext()
{
var str, crcbits, crcnum, len;
var startvalue, val;
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
if(idnxcrcstart.value == "穷举") {
displayout.checked = true;
displayoutlabel.style.color = "red";
}
if(strikbitx.value == "停止碰撞") {
clearTimeout(setTimeoutID);
strikbitx.value = "初值碰撞";
return;
}
operatorsele.selectedIndex = 0;
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
len = GetText12StringLen();
if (discheckbox.checked && text140.value.length == crcnum && (len > 0) && (crcnum == 0 || (text140.value == text170.value)))
{
text13.value = "";//清空密文,要求计算初值,明文不变
revert();//算出初值
idTextBox.value = "找到唯一初值碰撞:" + "\n" + text160.value + "(可逆)";
strikbitx.value = "初值碰撞";
var d = new Date();
idTextBox.value += "\n穷举初值碰撞时间:" + d.toLocaleTimeString();
}
else {
if(crcnum != text140.value.length) {//检查结果
alert("结果长度必须等于权值长度!!!");
return;
}
if(!patrn.test(text140.value)) {
alert("结果请输入16进制数!!!");
return;
}
strikbittext.value = GetText12StringLen();//???PWY???
_text140_value = text140.value;//保护结果
_text120_value = text120.value;//起始初值
displayout.checked = false;
displayoutlabel.style.color = "blue";
if(idnxcrcstart.value == "穷举") {
idTextBox.value = "";
}
strikbitx.value = "停止碰撞";
g_czpzcount = 0;
var d = new Date();
idTextBox.value += "穷举初值碰撞时间:" + d.toLocaleTimeString();
setTimeoutID = setTimeout(startstrikbittexttimeout, 5);
}
}
function startstrikbittexttimeout()
{
var str, crcbits, crcnum;
var startvalue, val;
var strArray = new Array();
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
do {
// calculator();
hotcrc();//运算
if(_text140_value == text140.value) {//找到初值
g_czpzcount++;
if(discheckbox.checked){//可逆非等长
displayout.checked = false;
displayoutlabel.style.color = "blue";
str = idTextBox.value;
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
if(strArray.length == 1) {
idTextBox.value += "找到唯一初值碰撞:" + "\n" + text160.value + "(可逆)";
var d = new Date();
idTextBox.value += "\n" + "唯一初值碰撞结束时间:" + d.toLocaleTimeString();
if(!confirm("已经找到唯一的初值碰撞了,还要继续折腾吗???")) {
displayout.checked = true;
displayoutlabel.style.color = "red";
strikbitx.value = "初值碰撞";
return;
}
var d = new Date();
idTextBox.value += "\n" + "折腾初值碰撞时间:" + d.toLocaleTimeString();
}
else {
idTextBox.value += "\n" + text160.value;
ChangeidTextBox();
}
}
else{//不可逆
if(idTextBox.value == "") idTextBox.value = "找到几个初值碰撞:\n" + text160.value + "(不可逆)";
else idTextBox.value += "\n" + text160.value;
ChangeidTextBox();
}
}
text120.value = StringINCToString(text120.value);
SetCRCTableArrayInitString(text120.value);
if(text120.value.substr(crcnum - 1, 1) == "0") {
break;
}
}while(_text120_value != text120.value);
if(_text120_value != text120.value) {
setTimeoutID = setTimeout(startstrikbittexttimeout, 5);
}
else {
text140.value = _text140_value;
if(idnxcrcstart.value == "穷举") {
displayout.checked = true;
displayoutlabel.style.color = "red";
strikbitx.value = "初值碰撞";
var d = new Date();
idTextBox.value += "\n" + "初值碰撞结束时间:" + d.toLocaleTimeString();
if(discheckbox.checked){//可逆
if(g_czpzcount <= 1) {
alert("不相信菜农的后果,瞎折腾!!!");
}
else {
alert("菜农认栽,算你狠!!!");
}
}
}
}
}
function WriteHexFile()
{
if(!radioTextMode.checked){//非多行
if(!TestIE()){
alert("非IE浏览器不支持文件写入!!!");
return;
}
g_hexfilenamecount = 0;//本次调用不写文件名
if(TestHexFileFormat()){
filename = GetHexFormatFileName();
var write = true;
if(FileExists(filename)){
write = confirm("文件:\n" + filename + "\n已存在,覆盖吗?");
}
if(write){
WriteFile(filename, idTextBox.value);
alert("文件:\n" + filename +"\n写入成功!!!");
}
}
}
else{
alert("明文单行模式不支持文件操作,请选择多行或表格模式!!!");
}
}
function dishotcrc()
{
var i, len, str, ptr, ctr;
var crcdir, crcbits, crcnumh, crcnum, crcbitcount;
var strdata, strcrc, strdata0;
var strdata00, strcrcpoly, strcrcinit, strcrcstop;
crcdir = GetCRCTableArrayDirInt();
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
crcnumh = crcnum - 8;
ptr = text13.value;
if (text130.value.length == crcnum && text130.value.length == text120.value.length && text130.value.length == text170.value.length)
{
if(text12.value == "" && text13.value == "" && text140.value.length == crcnum){
text13.value = StringXORToStringLeft(text140.value, text170.value);
ptr = text13.value;
}
len = ptr.length;
if ((len > 0) && (len % crcnum)) alert("不满足CRC碰撞条件,密文长度必须是权值长度的倍数!!!");
else if(len == 0){//密文为空,只有结果。初值碰撞。
str = CodeStringToHex(text12.value, idselecodemode.selectedIndex);
len = str.length;
strdata00 = "0000000000000000";
strdata00 = strdata00.substr(0, crcnum);
if (text140.value.length == crcnum && (len > 0) && (crcnum == 0 || (text140.value == text170.value))) {
strcrcpoly = text130.value; strcrcinit = text140.value;
strcrcstop = text170.value;
ctr = StringXORToString(strcrcinit, strcrcstop);
strcrcinit = ctr;
var size = len % crcnum ;
if(size > 0){//非整数倍
ptr = str.substr(len - size, size);
if(crcdir){//左移
ptr += strdata00.substr(0, crcnum - size);
}else{//右移
ptr = StringDisInvertlToString(ptr);
ptr = strdata00.substr(0, crcnum - size) + ptr;
}
strcrcinit = ptr;
ctr = strcrcinit + ctr;
len -= size;
}
for(i = 0;i < (len / crcnum);i++) {
ptr = str.substr(len - i * crcnum - crcnum, crcnum);
ptr = StringTestInvertlToString(ptr);
strcrcinit = GetDisHotWC3CRCPolyWorkValue(strcrcinit, ptr, strcrcpoly, strdata00, crcdir, crcbits, 0);//CRC4~64
strcrcinit = StringTestInvertlToString(strcrcinit);
if(i < (len / crcnum - 1)) ctr = strcrcinit + ctr;
}
text13.value = ctr;
text120.value = strcrcinit;
SetCRCTableArrayInitString(text120.value);//新初值
}
}
else {
text12.value = '';
HotWC3DataBuffText.value = "";//清空
if (text140.value.length != crcnum)
{
if (crcbits <= 32)
{
text140.value += inttohex(hextoint(ptr.substr(len - crcnum)) ^ hextoint(text170.value), crcnum);//还原密文
}
else
{
text140.value += inttohex(hextoint(ptr.substr(len - crcnum, crcnumh)) ^ hextoint(text170.value.substr(0, crcnumh)), crcnumh);//还原密文
text140.value += inttohex(hextoint(ptr.substr(len - crcnum + crcnumh, 8)) ^ hextoint(text170.value.substr(crcnumh, 8)), 8);//还原密文
}
}
else
{
ptr = (len - crcnum > 0) ? ptr.substr(0, len - crcnum) : "";
if (crcbits <= 32)
{
ptr += inttohex(hextoint(text140.value) ^ hextoint(text170.value), crcnum);//还原密文
}
else
{
ptr += inttohex(hextoint(text140.value.substr(0, crcnumh)) ^ hextoint(text170.value.substr(0, crcnumh)), crcnumh);//还原密文
ptr += inttohex(hextoint(text140.value.substr(crcnumh, 8)) ^ hextoint(text170.value.substr(crcnumh, 8)), 8);//还原密文
}
text13.value = ptr;
}
len = ptr.length;//取密文长度
crcbitcount = parseInt(strikbittext.value);//位域4的长度
if (crcbitcount && crcbitcount < len) len = crcbitcount;
crcbitcount = len * 4;//位域4
crcdir = GetCRCTableArrayDirInt();
if (crcbits <= 32)
{
strdata0 = inttohex(0 ,crcnum);
}
else
{
strdata0 = inttohex(0 ,crcnumh) + inttohex(0, 8);
}
strcrc = text120.value;
str = "";
for(i = 0; i < len; i += crcnum)
{
strdata = ptr.substr(i, crcnum);//密文
strcrc = GetDisHotWC3CRCPolyWorkValue(strdata, strcrc, text130.value, strdata0, crcdir, crcbits, crcbitcount);//CRC4~64
if (crcdir == 0){//右移
HotWC3DataBuffText.value += StringInvertlToString(strcrc);//反序
}
else{
HotWC3DataBuffText.value += strcrc;
}
crcbitcount -= 4 * crcnum;
str += strcrc;//明文
strcrc = strdata;//上次密文
}
text12.value = HexToCodeString(str, idselecodemode.selectedIndex);
text140.value = StringXORToString(strcrc, text170.value);
if(displayout.checked) {
idTextBox.value = "CRC逆运算结果=" + text12.value;
ChangeidTextBox();
}
}
}
}
//EndHide-->
</script>
<script>
<!--Hide
function hotcrc()
{
var i, j, len, str, ptr, ctr, ch;
var crcdir, crcbits, crcnumh, crcnum, crcbitcount;
var strdata, strcrc, strdata0;
var patrn=/^[\r0-9a-fA-F]+$/;//正则表达式
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
crcnumh = crcnum - 8;
if (text130.value.length == crcnum && text130.value.length == text120.value.length && text130.value.length == text170.value.length)
{
len = GetText12StringLen();
if (len > 0)
{
HotWC3DataBuffText.value = "";//清空
text13.value = '';
crcdir = GetCRCTableArrayDirInt();
if (crcbits <= 32)
{
strdata0 = inttohex(0 ,crcnum);
}
else
{
strdata0 = inttohex(0 ,crcnumh) + inttohex(0, 8);
}
strcrc = text120.value;//取初值
if(idselecodemode.selectedIndex == 0) text12.value = HexStringFormat(text12.value);
str = CodeStringToHex(text12.value, idselecodemode.selectedIndex);
len = str.length;
ctr = xortextvalue.value;
if (ctr != ""){
ch = "";
for(i = 0;i < len;i+=ctr.length){
ptr = str.substr(i, i + ctr.length);
ch += StringXORToStringLeftCut(ptr, ctr);
}
str = ch
}
}
strikbittext.value = len;
crcbitcount = len * 4;//位域4
text140.value = "";
ptr = "";
for(i = 0; i < len; i += crcnum)
{
strdata = str.substr(i, crcnum);//明文
if (crcdir == 0){//右移
HotWC3DataBuffText.value += StringInvertlToString(strdata);//反序
}
else{
HotWC3DataBuffText.value += strdata;
}
strcrc = GetHotWC3CRCPolyWorkValue(strdata, strcrc, text130.value, strdata0, crcdir, crcbits, crcbitcount);//CRC4~64
ptr += strcrc;//密文
crcbitcount -= 4 * crcnum;
}
text13.value = ptr;
text140.value = StringXORToString(strcrc, text170.value);
if(displayout.checked) {
idTextBox.value = "CRC正运算结果=0x" + text140.value;
ChangeidTextBox();
}
}
else {
if(displayout.checked) idTextBox.value = "CRC参数错误!!!";
ChangeidTextBox();
}
}
//EndHide-->
</script>
<script>
<!--Hide
//HexFile函数包
function LoadHexFileCRCCalc()
{
g_hexfilenamecount = 0;//本次调用不写文件名
if(!TestHexFileFormat()){
return;
}
var binArray = new Array();
binArray = LoadHexFileArray();//装载明文
var i, j, len, addr, str, ptr;
var crcdir, crcbits, crcnumh, crcnum, crcbitcount;
var strdata, strcrc, strdata0;
var patrn=/^[\r0-9a-fA-F]+$/;//正则表达式
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
crcnumh = crcnum - 8;
if (text130.value.length == crcnum && text130.value.length == text120.value.length && text130.value.length == text170.value.length)
{
len = binArray.length;
if (len > 0)
{
HotWC3DataBuffText.value = "";//清空
crcdir = GetCRCTableArrayDirInt();
if (crcbits <= 32)
{
strdata0 = inttohex(0 ,crcnum);
}
else
{
strdata0 = inttohex(0 ,crcnumh) + inttohex(0, 8);
}
strcrc = text120.value;//取初值
strikbittext.value = len * 2;//2个数字
crcbitcount = len * 8;//位域4
text140.value = "";//结果
addr = 0;
for(i = 0; i < len; i += (crcnum / 2))
{
strdata = "";
for(j = 0;j < (crcnum / 2);j++){
if(addr < len){
strdata += inttohex(binArray[addr++], 2);//明文
}
}
if (crcdir == 0){//右移
HotWC3DataBuffText.value += StringInvertlToString(strdata);//反序
}
else{
HotWC3DataBuffText.value += strdata;
}
strcrc = GetHotWC3CRCPolyWorkValue(strdata, strcrc, text130.value, strdata0, crcdir, crcbits, crcbitcount);//CRC4~64
crcbitcount -= 4 * crcnum;
}
text140.value = StringXORToString(strcrc, text170.value);
//setTimeoutID = setTimeout(displayhotcrchexfile, 1000);//异步显示
}
}
else {
if(displayout.checked) alert("CRC参数错误!!!");
}
}
/*
function displayhotcrchexfile()
{
// text140.value = "";
}
*/
function GetHexFormatFileName()
{
var str, pos, size, filename;
filename = idhexfilename.value.toUpperCase();
filename = StringLeftTrim(filename);
pos = filename.indexOf("(0X");
if(pos >= 4){
filename = filename.substr(0, pos);
}
return filename;
}
function GetHexFormatLength()
{
var str, pos, size, filename;
filename = idhexfilename.value.toUpperCase();
filename = StringLeftTrim(filename);
pos = filename.indexOf("(0X");
if(pos >= 4){
str = filename.substr(pos + 3, filename.length - (pos + 3));
size = hextoint(str.substr(0, 4));
}
return size;
}
function GetHexFormatMessage()
{
var str, ptr, filename;
var strArray = new Array();
var patrn = /^[\r, 0-9a-fA-F]+$/;//正则表达式
filename = idhexfilename.value.toUpperCase();
strArray = filename.split(")");
str = "";
if(strArray.length > 1){
ptr = strArray[strArray.length - 1];
if(ptr[0] != "[ DISCUZ_CODE_0 ]quot;){
alert("规则必须以$开始!!!");
}
else if(ptr.length > 1 && !patrn.test(str.substr(1, str.length - 1))){
alert("规则内只能有逗号和空格即16进制数!!!");
}
else{
str = ptr;//成功
}
}
return str;
}
function GetHexFormatWork1()
{
var str;
str = GetHexFormatMessage();
if(str != ""){
str = str.substr(1, str.length - 1);
}
return str;
}
function GetHexFormatFill()
{
var str, filename;
var strArray = new Array();
filename = idhexfilename.value.toUpperCase();
strArray = filename.split(")");
str = "FF";
if(strArray.length > 1){
str = strArray[0];
str = StringRightTrim(str);
str = StringRight(str, 2);
}
//alert(str);
return str;
}
function GetHexFormatDataBuff()
{
var strArray = new Array();
var databuff = "";
strArray = LoadHexFileArray();
for(i = 0;i < strArray.length;i++){
databuff += inttohex(strArray[i], 2);
}
return databuff;
}
function LoadHexFileArray()
{
var str, ptr, i, j, k, fill;
var addr = 0, len = 0, size, checksum;
var strArray = new Array();
var result = false;
//alert(GetHexFormatMessage());
size = GetHexFormatLength();
if(size == 0){
alert("文件名后跟的文件长度不对!!!");
return;
}
var binArray = new Array(size);
fill = hextoint(GetHexFormatFill());
if(fill != 0){
for(i = 0;i < size;i++){
binArray[i] = fill;//填充
}
}
str = idHexEditBox.value;
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
for(i = 0;i < strArray.length;i++){
str = strArray[i];
if(str !== ""){
if(str.substr(7, 2) == "00"){
len = hextoint(str.substr(1, 2));
if((len * 2) != (str.length - 11)){
alert("第" + (i + 1) + "行长度不对!!!\n" + str);
return false;//退出
}
addr = hextoint(str.substr(3, 4));//开始地址
ptr = str.substr(9, len * 2);//1行明文
for(j = 0;j < len * 2;j += 2){
binArray[addr++] = hextoint(ptr.substr(j, 2));
}
}
}
}
return binArray;
}
function TestHexCRCFormat()
{
var str, ptr, i, j, k;
var strArray = new Array();
var patrn=/^[0-9a-fA-F]+$/;//Hex 格式正则表达式
str = idTextBox.value;
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
for(i = 0;i < strArray.length;i++){
str = strArray[i];
str = StringTrim(str);
if(str != ""){
if(str.substr(0, 1) != "[ DISCUZ_CODE_0 ]quot;){
return false;
}
}
}
return true;
}
var g_hexfilenamecount = 0;//本次调用不写文件名
function TestHexFileFormat()
{
var str, ptr, i, j, k;
var addr = 0, len = 0, size = 0, checksum;
var strArray = new Array();
var patrn=/^[0-9a-fA-F]+$/;//Hex 格式正则表达式
var result = false;
str = idHexEditBox.value;
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
for(i = 0;i < strArray.length;i++){
str = strArray[i];
if(str !== ""){
if((str.length & 1) && str[0] == ":" && !patrn.test(str.substr(1, str.length - 1))){//
alert("第" + (i + 1) + "行不是Hex格式!!!\n" + str);
break;
}
checksum = 0;
for(j = 1;j < str.length;j += 2){
ptr = str.substr(j, 2);
checksum += hextoint(ptr);
checksum &= 0xff;
}
if(checksum != 0){
checksum = 0x100 - (checksum - hextoint(ptr));
alert("第" + (i + 1) + "行校验和" + ptr +"不对, 应该是" + inttohex(checksum, 2) + "!!!\n" + str);
return false;//退出
}
if(str.substr(7, 2) == "00"){
len = hextoint(str.substr(1, 2));
if((len * 2) != (str.length - 11)){
alert("第" + (i + 1) + "行长度不对!!!\n" + str);
return false;//退出
}
addr = hextoint(str.substr(3, 4));
if(size < addr + len) size = addr + len;
}
else if(str == ":00000001FF"){
if(g_hexfilenamecount == 1){//本次调用写文件名
filename = GetHexFormatFileName();
idhexfilename.value = idhexfilename.value = filename + "(0x" + inttohex(size, 4) + ", " + size + ", FF)";
str = "$0, 0x" + inttohex(size - 1, 4) + ";//对长度" + size + "个字节的Hex文件";
str += filename + "进行CRC运算, CRC简写式:" + text160.value;
k = GetCRCTableArraySelectedIndex();
if(k >= 32){//标准CRC
var objradiobutton = document.getElementsByName("radiobutton");
str += ", 标准CRC名称:" + objradiobutton[k - 32].value;
}
else{
str += ", 任意HotCRC:[" + selemode1.value + ", " + select1.value +"]";
}
idTextBox.value = str;
ChangeidTextBox();
g_hexfilenamecount = 0;//下次调用不写文件名
}
result = true;
break;//结束
}
else{
alert("第" + (i + 1) + "行不是Hex格式!!!\n" + str);
return false;//退出
}
}
}
return result;
}
function ChangeidHexEditBox()
{
var str, strArray = new Array();
var i, k, str, row, len, cols, count;
if(TestIE()) strArray = idHexEditBox.value.split("\r\n");
else strArray = idHexEditBox.value.split("\n");
cols = idHexEditBox.cols;
count = 0;
row = 0;
for(i = 0; i < strArray.length; i++){
str = strArray[i];
if(str == "") row++;
else{
str = CodeStringToHex(str, 5);//采用HotCode编码
len = str.length >>> 1;//用HotCode测试长度
count += len;
k = len % cols;
len = Math.floor(len / cols);
row += len + ((k == 0) ? 0 : 1);
}
}
for(i = 0; i < idHexEditBoxCount.length; i++){
str = idHexEditBoxCount.options[i].value;
if(row <= parseInt(str)){
i++;
break;
}
}
idHexEditBoxCount.selectedIndex = i - 1;
idHexEditBox.rows = parseInt(idHexEditBoxCount.options[i - 1].value);
crceditcount.value = count;
return count;//
}
function ChangeHexEditBox()
{
if (parseInt(idHexEditBoxCount.value) > 0)
idHexEditBox.rows = parseInt(idHexEditBoxCount.value);
}
function ChangeHexEditBoxSet()
{
idHexEditBoxCount.selectedIndex = 2;
idHexEditBox.rows = parseInt(idHexEditBoxCount.value);
}
function DblClickidHexEditBox()
{
g_hexfilenamecount = 0;//本次调用不写文件名
TestHexFileFormat();
// alert("搜索或替换!!!");
}
function DblClickidTextBox()
{
ChangeidHexEditBox();
texteditclipboard();
}
function DblClickOpenHexFile()
{
if(operatorsele.selectedIndex == 0){//CRC运算
if(text12.value != ""){
clearinputtext();
clearoutputtext();//打开Hex文件
}
}
}
function TestOpenHexFile()
{
if(g_OpenHexFileBit == 0){
var filename = idhexfilename.value;
if((filename != "") && (filename.indexOf("\\") >= 2)){
alert("不能打开刚才的文件,请随便打开一个文件,然后再打开刚才的文件!!!");
}
}
}
function OpenHexFile()
{
g_OpenHexFileBit = 0;
idHexFile.click();//点击按钮浏览文件后调用HexHandleFiles()
setTimeoutID = setTimeout(TestOpenHexFile, 3000);//模拟同步读入
}
function HexHandleFiles()
{
g_OpenHexFileBit = 1;
var filename = idHexFile.value;//写入文件名称(有路径)
idhexfilename.value = filename;
filename = filename.toUpperCase();
var strArray = new Array();
var err = "";
strArray = filename.split("\\");
if(strArray.length > 1){//至少有根目录
filename = strArray[strArray.length - 1];
var fiilepath = strArray[1];//文件路径
strArray = filename.split(".");
if(strArray.length == 1){
var patrn=/^[0-9]+$/;//正则表达式
if(!(fiilepath == "FAKEPATH" && patrn.test(filename))){
err = "文件" + filename + "没有后缀,可能不是Hex格式的文件!!!";
}
}
else{
var str = strArray[strArray.length - 1];
if(str != "HEX"){
err = "文件" + filename + "后缀不是HEX,可能不是Hex格式的文件!!!";
}
}
if(!((err != "") && confirm(err + "\n请您确认是否放弃读出非Hex格式的文件???"))){
ReadFileEx(idHexFile);
//g_hexfilenamecount = 0;//本次调用不写文件名
setTimeoutID = setTimeout(TestHexFileFormat, 1000);//模拟同步读入
}
}
}
var g_OpenHexFileBit = 1;
function ReadFileEx(idFileHandle)
{
var str = "", filename;
var seleFile, reader, blob;
filename = idFileHandle.value;
if(filecheckbox.checked && (filename != "")){
if(TestIE()){
g_hexfilenamecount = 1;//本次调用写文件名
displayout.checked = false;//禁止写主编辑框
displayoutlabel.style.color = "blue";
idHexEditBox.value = ReadFile(filename);//同步读入!!!
}
else{
seleFile = idFileHandle.files[0];//seleFile.name(没有路径)
reader = new FileReader();
reader.readAsText(seleFile, "gb2312");
reader.onload = function(){
g_hexfilenamecount = 1;//本次调用写文件名
displayout.checked = false;//禁止写主编辑框
displayoutlabel.style.color = "blue";
idHexEditBox.value = this.result;//异步读入!!!
}
}
}
}
function selectTextEditMode()
{
if(radioTextMode.checked){//单行
labelTextMode.style.color = "red";
labelHexMode.style.color = "blue";
labelTableMode.style.color = "blue";
labelHexEditBox.style.display = "none";
labelHexCRCBox.style.display = "";
labelHexEditMode.style.display = "none";
}
else if(radioHexMode.checked){//多行
labelTextMode.style.color = "blue";
labelHexMode.style.color = "red";
labelTableMode.style.color = "blue";
labelHexEditBox.style.display = "";
text13.value = "";
labelHexCRCBox.style.display = "none";
labelHexEditMode.style.display = "";
}
else if(radioTableMode.checked){//表格
labelTextMode.style.color = "blue";
labelHexMode.style.color = "blue";
labelTableMode.style.color = "red";
labelHexEditBox.style.display = "none";
labelHexCRCBox.style.display = "none";
labelHexEditMode.style.display = "";
text13.value = "";
}
}
function OpenHexFileName()
{
if(!radioTextMode.checked){//单行编辑不能打开文件
OpenHexFile();//打开HEX文件并加载数据到主编辑框内
}
else{
alert("明文单行模式不支持文件操作,请选择多行或表格模式!!!");
}
}
function LoadHexFormatText()
{
if(radioHexMode.checked){//多行编辑可以装载
text12.value = GetHexFormatDataBuff();
radioTextMode.checked = true;
selectTextEditMode();//切换
}
}
//EndHide-->
</script>
<script>
<!--Hide
function stopTimeout() {
clearTimeout(setTimeoutID);
}
function StringINCToString(str)
{
var val, ptr, poly;
var crcbits, crcnum;
crcnum = str.length;
crcbits = crcnum * 4;
ptr = "";
if(crcbits <= 32) {
val = hextoint(str);
val ++;
ptr = inttohex(val, crcnum);
}
else if(crcbits <= 64){
ptr = str.substr(crcnum - 8, 8);
poly = hextoint(ptr);
poly ++;
val = poly;
if (val != 0) {
ptr = str.substr(0, crcnum - 8) + inttohex(val, 8);
}
else {
str = str.substr(0, crcnum - 8);
val = hextoint(str);
val ++;
ptr = inttohex(val, crcnum - 8) + inttohex(0, 8);
}
}
return ptr;
}
function StringDECToString(str)
{
var val, ptr, poly;
var crcbits, crcnum;
crcnum = str.length;
crcbits = crcnum * 4;
ptr = "";
if(crcbits <= 32) {
val = hextoint(str);
val --;
ptr = inttohex(val, crcnum);
}
else if(crcbits <= 64){
ptr = str.substr(crcnum - 8, 8);
poly = hextoint(ptr);
poly --;
val = poly;
if (val >= 0) {
ptr = str.substr(0, crcnum - 8) + inttohex(val, 8);
}
else {
str = str.substr(0, crcnum - 8);
val = hextoint(str);
val --;
ptr = inttohex(val, crcnum - 8) + inttohex(-1, 8);
}
}
return ptr;
}
function StringHexToString(str, crcnum)
{
var len, num;
len = str.length;
if(crcnum <= len){
str = str.substr(len - crcnum, crcnum);//取低位
}
else{
str = inttohex(0, crcnum - len) + str;
}
return str;
}
function StringLMToStringEx(str0, bits)
{
var str, len, num, i, h, l;
str0 = inttohex(0, (bits + 3) >>> 2) + str0;
len = str0.length;
if(len > 16) {
str0 = str0.substr(len - 16, 16);
len = 16;
}
if (len <= 8)
{
num = hextoint(str0) << bits;
str = inttohex(num, len);//还原结果
}
else
{
len -= 8;
h = hextoint(str0.substr(0, len));
l = hextoint(str0.substr(len, 8));
for(i = 0;i < bits;i++){
h <<= 1;
if(l & 0x80000000) h |= 1;
l <<= 1;
}
str = inttohex(h, len) + inttohex(l, 8);//还原结果
}
return str;
}
function StringLMToString(str0, bits)
{
var str, len, num, i, h, l;
len = str0.length;
if (len <= 8)
{
num = hextoint(str0) << bits;
str = inttohex(num, len);//还原结果
}
else
{
len -= 8;
h = hextoint(str0.substr(0, len));
l = hextoint(str0.substr(len, 8));
for(i = 0;i < bits;i++){
h <<= 1;
if(l & 0x80000000) h |= 1;
l <<= 1;
}
str = inttohex(h, len) + inttohex(l, 8);//还原结果
}
return str;
}
function StringRMToString(str0, bits)
{
var str, len, num, i, h, l;
len = str0.length;
if (len <= 8)
{
num = hextoint(str0) >>> bits;
str = inttohex(num, len);//还原结果
}
else
{
len -= 8;
h = hextoint(str0.substr(0, len));
l = hextoint(str0.substr(len, 8));
for(i = 0;i < bits;i++){
l >>>= 1;
if(h & 0x00000001) l |= 0x80000000;
h >>>= 1;
}
str = inttohex(h, len) + inttohex(l, 8);//还原结果
}
return str;
}
function StringSUBToString(str0, str1)
{
var str, len, len0, len1, val0, val1;
len0 = str0.length;
len1 = str1.length;
len = Math.max(len0, len1);
if(len0 < len1) str0 = inttohex(0, len1 - len0) + str0;
else if(len0 > len1) str1 = inttohex(0, len0 - len1) + str1;
if (len <= 8)
{
str = inttohex(hextoint(str0) - hextoint(str1), len);//还原结果
}
else
{
len -= 8;
val0 = hextoint(str0.substr(0, len)) - hextoint(str1.substr(0, len));
val1 = hextoint(str0.substr(len, 8)) - hextoint(str1.substr(len, 8));
if(val1 < 0) val0--;
str = inttohex(val0, len);//还原结果
str += inttohex(val1, 8);//还原结果
}
return str;
}
function StringADDToString(str0, str1)
{
var str, len, len0, len1, val0, val1;
len0 = str0.length;
len1 = str1.length;
len = Math.max(len0, len1);
if(len0 < len1) str0 = inttohex(0, len1 - len0) + str0;
else if(len0 > len1) str1 = inttohex(0, len0 - len1) + str1;
if (len <= 8)
{
str = inttohex(hextoint(str0) + hextoint(str1), len);//还原结果
}
else
{
len -= 8;
val0 = hextoint(str0.substr(0, len)) + hextoint(str1.substr(0, len));
val1 = hextoint(str0.substr(len, 8)) + hextoint(str1.substr(len, 8));
if(inttohex(val1, 8) < str0.substr(len, 8)){
val0++;
}
str = inttohex(val0, len);//还原结果
str += inttohex(val1, 8);//还原结果
}
return str;
}
//以下是新函数
function HexToNumber(hex)
{//ch必须是大写字母A-F,数字0-9.半个字节
/*
var patrn = /^[0-9a-fA-F]+$/;//正则表达式
if(!patrn.test(hex)){
return 0;
}
return (hex <= "9") ? (hex.charCodeAt(0)- 0x30):(hex.charCodeAt(0) - 0x41 + 10);
*/
if((hex >= "0") && (hex <= "9")){
return (hex.charCodeAt(0)- 0x30);
}
if((hex >= "A") && (hex <= "F")){
return (hex.charCodeAt(0)- 0x41 + 10);
}
if((hex >= "a") && (hex <= "f")){
return (hex.charCodeAt(0)- 0x61 + 10);
}
return 0;//出错返回0
}
function NumberToHex(num)
{
num &= 0xf;
return (num <= 9)? String.fromCharCode(num + 0x30):String.fromCharCode(num + 0x41 - 10);
}
function StringMoveToStringLeftSelf(str0, size)
{//自环左移动,不管长度。出口长度不变
return StringMoveToStringLeftCY(str0, size, HexToNumber(str0[0]) & 8);
}
function StringMoveToStringLeftCY(str0, size, cy)
{//左移动,不管长度。出口长度不变
var str = StringMoveToStringLeft(str0, size);
if(cy > 0){
str = StringORToStringRight(str, "1");//
}
return str;
}
function StringMoveToStringLeft(str0, size)
{//左移动,不管长度。出口长度不变
var str, ptr, ctr, len, len0, pos;
var i, j, iptr, istr, istr0;
len0 = str0.length;
if(size == 0){
return str0;
}
len = Math.floor(size / 4);
pos = size & 3;
if(len > 0){//有半字节不用移动,后补半字节的0
str = "";
for(i = 0;i < len;i++) str += "0";
str0 = str + str0;
str0 = StringRight(str0, len0);//去掉最高位后填充"0"
if(pos == 0) return str0;
}
else if(len0 == 1){
iptr = HexToNumber(str0);
}
ctr = "";
for(i = 0;i < pos;i++){//左移pos次(0-3)次
for(j = 0;j < len0 - 1;j++){//str0左移1位
str = str0[j];//取半个字节
istr = HexToNumber(str);
istr <<= 1;
ptr = str0[j + 1];
iptr = HexToNumber(ptr);
if(iptr >= 8){
istr ++;//看下半个字节
}
ctr += NumberToHex(istr);
}
iptr <<= 1;//最后半个字节直接处理
ctr += NumberToHex(iptr);
}
ctr = StringRight(ctr, len0);//
return ctr;
}
function StringMoveToStringRightSelf(str0, size)
{//自环右移动,不管长度。出口长度不变
return StringMoveToStringRightCY(str0, size, HexToNumber(str0[str0.length - 1]) & 1);
}
function StringMoveToStringRightCY(str0, size, cy)
{//带进位右移动,不管长度。出口长度不变
var str = StringMoveToStringRight(str0, size);
if(cy > 0){
str = StringORToStringLeft(str, "8");//
}
return str;
}
function StringMoveToStringRight(str0, size)
{//右移动,不管长度。出口长度不变
var str, ptr, ctr, len, len0, pos;
var i, j, k, k0, iptr, istr, istr0;
len0 = str0.length;
if(size == 0){
return str0;
}
len = Math.floor(size / 4);
pos = size & 3;
if(len > 0){//有半字节不用移动,后补半字节的0
str = "";
for(i = 0;i < len;i++) str += "0";
str0 = str + str0;
str0 = StringLeft(str0, len0);//去掉最低位后填充"0"
if(pos == 0) return str0;
}
ctr = "";
for(i = 0;i < pos;i++){//右移pos次(0-3)次
k = 0;
for(j = 0;j < len0;j++){//str0右移1位
str = str0[j];//取半个字节
istr = HexToNumber(str);
k0 = istr & 1;//**
istr >>>= 1;
istr &= 0xf;
if(k > 0) istr |= 0x8;
k = k0;
ctr += NumberToHex(istr);
}
}
ctr = StringLeft(ctr, len0);//
return ctr;
}
function StringXORToStringRightCut(str0, str1)
{
if(str0.length > str1.length) str0 = StringRight(str0, str1.length);
else if(str1.length > str0.length) str1 = StringRight(str1, str0.length);
return StringXORToStringRight(str0, str1);
}
function StringXORToStringRight(str0, str1)
{//右对齐,不管长度。
var str, len, len0, len1;
var i,pos;
len0 = str0.length;
len1 = str1.length;
len = Math.min(len0, len1);//取小的为移位次数
if(len0 > len1){
pos = len0 - len1;
str = StringLeft(str0,pos);
for(i = 0;i < len;i++){
str += NumberToHex(HexToNumber(str0[i + pos]) ^ HexToNumber(str1[i]));
}
}
else if(len0 < len1){
pos =len1 - len0;
str = StringLeft(str1, pos);
for(i = 0;i < len;i++){
str += NumberToHex(HexToNumber(str0[i]) ^ HexToNumber(str1[i + pos]));
}
}
else {
str = "";
for(i = 0;i < len;i++){
str += NumberToHex(HexToNumber(str0[i]) ^ HexToNumber(str1[i]));
}
}
return str;
}
function StringXORToStringLeftCut(str0, str1)
{
if(str0.length > str1.length) str0 = StringLeft(str0, str1.length);
else if(str1.length > str0.length) str1 = StringLeft(str1, str0.length);
return StringXORToStringLeft(str0, str1);
}
function StringXORToStringLeft(str0, str1)
{//左对齐,不管长度。当两个等长时,建议用此函数
var str, len, len0, len1;
var i;
len0 = str0.length;
len1 = str1.length;
len = Math.min(len0, len1);//取小的为移位次数
str = "";
for(i = 0;i < len;i++){
str += NumberToHex(HexToNumber(str0[i]) ^ HexToNumber(str1[i]));
}
if(len0 > len1) str += StringRight(str0, len0-len1);
else if(len0 < len1) str += StringRight(str1, len1-len0);
return str;
}
function StringANDToStringRightCut(str0, str1)
{
if(str0.length > str1.length) str0 = StringRight(str0, str1.length);
else if(str1.length > str0.length) str1 = StringRight(str1, str0.length);
return StringANDToStringRight(str0, str1);
}
function StringANDToStringRight(str0, str1)
{//右对齐,不管长度。
var str, len, len0, len1;
var i,pos;
len0 = str0.length;
len1 = str1.length;
len = Math.min(len0, len1);//取小的为移位次数
if(len0 > len1){
pos = len0 - len1;
str = "";
for(i = 0;i < pos;i++) str+="0";
for(i = 0;i < len;i++){
str += NumberToHex(HexToNumber(str0[i+pos]) & HexToNumber(str1[i]));
}
}
else if(len0 < len1){
pos = len1 - len0;
str="";
for(i = 0;i < pos;i++) str+="0";
for(i = 0;i <len;i++){
str += NumberToHex(HexToNumber(str0[i]) & HexToNumber(str1[i+pos]));
}
}
else {
str="";
for(i = 0;i < len;i++){
str += NumberToHex(HexToNumber(str0[i]) & HexToNumber(str1[i]));
}
}
return str;
}
function StringANDToStringLeftCut(str0, str1)
{
if(str0.length > str1.length) str0 = StringLeft(str0, str1.length);
else if(str1.length > str0.length) str1 = StringLeft(str1, str0.length);
return StringANDToStringLeft(str0, str1);
}
function StringANDToStringLeft(str0, str1)
{//左对齐,不管长度。当两个等长时,建议用此函数
var str, len, len0, len1;
var i;
len0 = str0.length;
len1 = str1.length;
len = Math.min(len0, len1);//取小的为移位次数
str = "";
for(i = 0;i < len;i++){
str += NumberToHex(HexToNumber(str0[i]) & HexToNumber(str1[i]));
}
len = Math.abs(len0 - len1);
for(i = 0;i < len;i++){
str += "0";
}
return str;
}
function StringORToStringRightCut(str0, str1)
{
if(str0.length > str1.length) str0 = StringRight(str0, str1.length);
else if(str1.length > str0.length) str1 = StringRight(str1, str0.length);
return StringORToStringRight(str0, str1);
}
function StringORToStringRight(str0, str1)
{//右对齐,不管长度。
var str, len, len0, len1;
var i,pos;
len0 = str0.length;
len1 = str1.length;
len = Math.min(len0, len1);//取小的为移位次数
if(len0 > len1){
pos = len0-len1;
str = StringLeft(str0, pos);
for(i = 0;i < len;i++){
str += NumberToHex(HexToNumber(str0[i+pos]) | HexToNumber(str1[i]));
}
}
else if(len0 < len1){
pos = len1-len0;
str = StringLeft(str1,pos);
for(i = 0;i < len;i++){
str += NumberToHex(HexToNumber(str0[i]) | HexToNumber(str1[i+pos]));
}
}
else {
str="";
for(i = 0;i < len;i++){
str += NumberToHex(HexToNumber(str0[i]) | HexToNumber(str1[i]));
}
}
return str;
}
function StringORToStringLeftCut(str0, str1)
{
if(str0.length > str1.length) str0 = StringLeft(str0, str1.length);
else if(str1.length > str0.length) str1 = StringLeft(str1, str0.length);
return StringORToStringLeft(str0, str1);
}
function StringORToStringLeft(str0, str1)
{//左对齐,不管长度。当两个等长时,建议用此函数
var str, len, len0, len1;
var i;
len0 = str0.length;
len1 = str1.length;
len = Math.min(len0, len1);//取小的为移位次数
str = "";
for(i = 0;i < len;i++){
str += NumberToHex(HexToNumber(str0[i]) | HexToNumber(str1[i]));
}
if(len0 > len1) str += StringRight(str0,len0 - len1);
else if(len0 < len1) str += StringRight(str1,len1 - len0);
return str;
}
//以上是新函数!!!!!!!!!!!!
function StringXORToString(str0, str1)
{
var str, len, len0, len1;
len0 = str0.length;
len1 = str1.length;
len = Math.max(len0, len1);
if(len0 < len1) str0 = inttohex(0, len1 - len0) + str0;
else if(len0 > len1) str1 = inttohex(0, len0 - len1) + str1;
if (len <= 8)
{
str = inttohex(hextoint(str0) ^ hextoint(str1), len);//还原结果
}
else
{
len -= 8;
str = inttohex(hextoint(str0.substr(0, len)) ^ hextoint(str1.substr(0, len)), len);//还原结果
str += inttohex(hextoint(str0.substr(len, 8)) ^ hextoint(str1.substr(len, 8)), 8);//还原结果
}
return str;
}
function StringNOTToString(str)
{
var str, len;
len = str.length;
if (len <= 8)
{
str = inttohex(~hextoint(str), len);//还原结果
}
else
{
len -= 8;
str = inttohex(~hextoint(str.substr(0, len)), len) + inttohex(~hextoint(str.substr(len, 8)), 8);//还原结果
}
return str;
}
function StringANDToString(str0, str1)
{
var str, len, len0, len1;
len0 = str0.length;
len1 = str1.length;
len = Math.min(len0, len1);
if(len0 > len1) str0 = str0.substr(len0 - len1, len1);
else if(len0 < len1) str1 = str1.substr(len1 - len0, len0);
if (len <= 8)
{
str = inttohex(hextoint(str0) & hextoint(str1), len);//还原结果
}
else
{
len -= 8;
str = inttohex(hextoint(str0.substr(0, len)) & hextoint(str1.substr(0, len)), len);//还原结果
str += inttohex(hextoint(str0.substr(len, 8)) & hextoint(str1.substr(len, 8)), 8);//还原结果
}
return str;
}
function StringORToString(str0, str1)
{
var str, len, len0, len1;
len0 = str0.length;
len1 = str1.length;
len = Math.max(len0, len1);
if(len0 < len1) str0 = inttohex(0, len1 - len0) + str0;
else if(len0 > len1) str1 = inttohex(0, len0 - len1) + str1;
if (len <= 8)
{
str = inttohex(hextoint(str0) | hextoint(str1), len);//还原结果
}
else
{
len -= 8;
str = inttohex(hextoint(str0.substr(0, len)) | hextoint(str1.substr(0, len)), len);//还原结果
str += inttohex(hextoint(str0.substr(len, 8)) | hextoint(str1.substr(len, 8)), 8);//还原结果
}
return str;
}
function initpatrnTest(str)
{
var i, len, ch;
len = str.length;
ch = str.substr(0, 1);//取第1个字符
for(i = 1; i < len; i ++){
if(ch != str.substr(i, 1)) {
return false;
}
}
return true;
}
function converse(index)
{
var str, ptr, ctr, str0, str1, i, j, k, len, crcnum, crcnumh, crcdir, crcbits, crcsize;
var strcrcpoly, strcrcinit, strcrcstop;
var strpoly01, strpoly80, strpolyff;
var data00, data01, data80, dataff;
var strdata00, strdata01, strdata80, strdataff;
var strcrc00, strcrc01, strcrc80, strcrcff;
var strcrcx00, strcrcx01, strcrcx80, strcrcxff;
var objradiobutton = document.getElementsByName("radiobutton");
var strArray = new Array();
var tabArray = new Array(4);
var strText;
tabArray[0] = "0000000000000000";
tabArray[1] = "5555555555555555";
tabArray[2] = "AAAAAAAAAAAAAAAA";
tabArray[3] = "FFFFFFFFFFFFFFFF";
strText = "";
str = "";
len = GetText12StringLen();
if (len && (len % 4) == 0 && len <= text13.value.length)//四点采样避开局部权值碰撞
{
selemode1.selectedIndex = 0;
selectHotCRC();
crcnum = len / 4;
crcbits = crcnum * 4;
crcnumh = crcnum - 8;
strdata00 = text12.value.substr(0, crcnum);
strdata01 = text12.value.substr(crcnum, crcnum);
strdata80 = text12.value.substr(crcnum * 2, crcnum);
strdataff = text12.value.substr(crcnum * 3, crcnum);
if (crcbits <= 32)
{
data00 = inttohex(0, crcnum);
data01 = inttohex(1, crcnum);
if (crcnum == 1) data80 = inttohex(0x8, crcnum);//奇数
else data80 = inttohex(0x80, crcnum);
dataff = inttohex(-1, crcnum);
}
else
{
data00 = inttohex(0, crcnumh) + inttohex(0, 8);
data01 = inttohex(0, crcnumh) + inttohex(1, 8);
data80 = inttohex(0, crcnumh) + inttohex(0x80, 8);
dataff = inttohex(-1, crcnumh) + inttohex(-1, 8);
}
crcdir = -1;
if (strdata00 == data00 && strdata01 == data01 && strdata80 == data80 && strdataff == dataff)
{
strcrcx00 = text13.value.substr(0, crcnum);
if(index == 0){
strcrcx01 = text13.value.substr(crcnum, crcnum);
strcrcx80 = text13.value.substr(crcnum * 2, crcnum);
}
else{
strcrcx80 = text13.value.substr(crcnum, crcnum);
strcrcx01 = text13.value.substr(crcnum * 2, crcnum);
}
strcrcxff = text13.value.substr(crcnum * 3, crcnum);
if (crcbits <= 32)
{
strpoly01 = inttohex(hextoint(strcrcx00) ^ hextoint(strcrcx01), crcnum);
strpoly80 = inttohex(hextoint(strcrcx00) ^ hextoint(strcrcx80), crcnum);
}
else
{
strpoly01 = inttohex(hextoint(strcrcx00.substr(0, crcnumh)) ^ hextoint(strcrcx01.substr(0, crcnumh)), crcnumh);
strpoly01 += inttohex(hextoint(strcrcx00.substr(crcnumh, 8)) ^ hextoint(strcrcx01.substr(crcnumh, 8)), 8);
strpoly80 = inttohex(hextoint(strcrcx00.substr(0, crcnumh)) ^ hextoint(strcrcx80.substr(0, crcnumh)), crcnumh);
strpoly80 += inttohex(hextoint(strcrcx00.substr(crcnumh, 8)) ^ hextoint(strcrcx80.substr(crcnumh, 8)), 8);
}
discheckbox.checked = false;
strcrc01 = GetHotWC3CRCPolyWorkValue(strdata01, strdata00, strpoly80, strdata00, 0, crcbits, 0);//CRC4~64
strcrcff = GetHotWC3CRCPolyWorkValue(strdataff, strdata00, strpoly80, strdata00, 0, crcbits, 0);//CRC4~64
strcrcff = StringXORToString(strcrcff, strcrcx00);
if (strpoly01 == strcrc01 && strcrcxff == strcrcff)//判断右权
{
crcdir = 0;
strcrcpoly = strpoly80;
}
else
{
strcrc80 = GetHotWC3CRCPolyWorkValue(strdata80, strdata00, strpoly01, strdata00, 1, crcbits, 0);//CRC4~64
strcrcff = GetHotWC3CRCPolyWorkValue(strdataff, strdata00, strpoly01, strdata00, 1, crcbits, 0);//CRC4~64
strcrcff = StringXORToString(strcrcff, strcrcx00);
if ((strpoly80 == strcrc80) && (strcrcxff == strcrcff))//判断左权
{
crcdir = 1;
strcrcpoly = strpoly01;
}
else
{
if(index != 0){
strText = "采样错误";
alert(strText);
}
return;
}
}
if (crcdir >= 0)
{
SetCRCTableArraySelectedIndex(crcbits, crcdir);
if (strcrcx00 == strdata00)//初值=0,出值=0
{
strcrcinit = strdata00;
strcrcstop = strdata00;
}
else if (strcrcx00 == strdataff)//初值=0,出值=ff
{
strcrcinit = strdata00;
strcrcstop = strdataff;
}
else if (strcrcxff == strdata00)//初值=ff,出值=0
{
strcrcinit = strdataff;
strcrcstop = strdata00;
}
else if (strcrcxff == strdataff)//初值=ff,出值=ff
{
strcrcinit = strdataff;
strcrcstop = strdataff;
}
else//初值=xx,出值=xx
{
strcrcinit = GetDisHotWC3CRCPolyWorkValue(strcrcx00, strdata00, strcrcpoly, strdata00, crcdir, crcbits, 0);//CRC4~64
strcrcinit = StringTestInvertlToString(strcrcinit);
strcrcstop = strdata00;
str = ":\n";
}
SetCRCTableArrayPolyString(strcrcpoly);
SetCRCTableArrayInitString(strcrcinit);
SetCRCTableArrayStopString(strcrcstop);
if(index == 0) strText = "标准";
else strText = "非标准";
if (crcdir) strText += "左移CRC";
else strText += "右移CRC";
strText += crcbits;
strText += "逆向成功";
if (str != "")
{
strText += ",出现初值出值碰撞";
str += "CRC多项式:" + text150.value + "\n";
str += "CRC简写式可能为:\n";
str0 = text160.value;
ctr = text120.value;
ptr = "";
for (i = 0; i < 4; i ++)
{
strcrcinit = tabArray[i].substr(0, crcnum);
strcrcstop = GetHotWC3CRCPolyWorkValue(strcrcinit, ctr, strcrcpoly, strdata00, crcdir, crcbits, 0);//CRC8
text120.value = strcrcinit;
SetCRCTableArrayInitString(text120.value);
text170.value = strcrcstop;
SetCRCTableArrayStopString(text170.value);
str += text160.value;
if(initpatrnTest(strcrcstop)){
str += " (可信度高!!!)";
if(ptr == "") ptr = text160.value;
break;
}
str += "\n";
}
k = 4;
if(discheckbox.checked) {
str += "\n";
for (i = 0; i < 4; i ++)
{
strcrcstop = tabArray[i].substr(0, crcnum);
strcrcinit = GetDisHotWC3CRCPolyWorkValue(strcrcx00, strdata00, strcrcpoly, strcrcstop, crcdir, crcbits, 0);//CRC4~64
strcrcinit = StringTestInvertlToString(strcrcinit);
text120.value = strcrcinit;
SetCRCTableArrayInitString(text120.value);
text170.value = strcrcstop;
SetCRCTableArrayStopString(text170.value);
if(str.indexOf(text160.value) < 0) {
str += text160.value;
if(initpatrnTest(strcrcinit)){
str += " (可信度高!!!)";
if(ptr == "") ptr = text160.value;
break;
}
k ++;
str += "\n";
}
}
}
if(ptr != "") text160.value = ptr;
else text160.value = str0;
SetCRCTableArrayPolyFormatString();
}
}
else
{
if (strText == "")
{
if(index != 0){
strText = "输出错误";
alert(strText);
}
return;
}
}
}
else
{
if(index != 0){
strText = "输入错误";
alert(strText);
}
return;
}
}
else
{
strText = "长度错误";
alert(strText);
return;
}
idTextBox.value = strText;
if (str !="") {
str += "请在这" + k.toString(10) + "个CRC简写式中选中一个填入CRC简写式框内!!!"
str += "\n\nHotCRC_V1.23以上版本可以立即点击\"穷举\"按钮找出精准的初值和出值"
idTextBox.value += str;
}
else{
for(i = 0;i < objradiobutton.length;i++){
if(text160.value == HotCRCPolyTableArray[32 + i]){
str = text160.value;
ptr = objradiobutton[i].value;
objradiobutton[i].checked = true;
idTextBox.value += "\n恭喜您**了标准的CRC: " + ptr;
idTextBox.value += "\nCRC简写式:" + str;
break;
}
}
}
ChangeidTextBox();
alert(strText);
}
function StringLeft0Cut(str)
{
while(StringRight(str, 2) == "00"){
str = str.substr(str.length - 2,str.length - 2);
};
return str;
}
function StringLeft0(str, len)
{
if(str.length < len) {
do{
str += "0";
}while(str.length < len);
return str;
}
else{
return str.substr(0, len);
}
}
function StringLeft(str, len)
{
if(len < 0){
return str.substr(0, str.length+len);
}
else{
return str.substr(0, len);
}
}
function StringRight0(str, len)
{
if(str.length < len) {
do{
str = "0" + str;
}while(str.length < len);
return str;
}
else{
return str.substr(str.length - len, len);
}
}
function StringRight(str, len)
{
return str.substr(str.length - len, len);
}
function StringTrim(str)
{
return str.replace(/^\s+|\s+$/g, "");
}
function StringLeftTrim(str)
{
return str.replace(/^\s+/g, "");
}
function StringRightTrim(str)
{
return str.replace(/\s+$/g, "");
}
function StringNot(str0)
{
var str = "";
var len,ch,i;
len=str0.length;
for(i=0;i<len;i++){
ch=str0[i];
ch=~HexToNumber(ch);
str+=NumberToHex(ch);
}
return str;
}
function HtmlWebtOnlineMessage(n, messtr)
{
var str;
if(idWebOnlineMessageText.checked){
str = n + ": " + messtr;
if(idTextBox.value == "") idTextBox.value = "压缩前行信息分析:";
idTextBox.value += "\n" + str;
}
}
var htmlArray = new Array();
var ghtmltextsize;
var g_webstart, g_webzip;
function WebOnlineCompressor()
{//HTML在线压缩
if(idWebOnlineCompressor.value == "停止转换"){
if(confirm("请您确认是否退出网页压缩???")) {
clearTimeout(setTimeoutID);
idWebOnlineCompressor.value = "网页压缩";
Changeidweboutputconversion();
return;
}
}
if(TestIE()) htmlArray = webinputconversion.value.split("\r\n");
else htmlArray = webinputconversion.value.split("\n");
var d = new Date();
idbWebTextRowStartTime.value = d.toLocaleTimeString();
idbWebTextRowTimeCount.value = d.toLocaleTimeString();
idbWebTextRowStart.value = "1";
if(idbWebTextRowSize.value == "") {
idbWebTextRowSize.value = htmlArray.length;
}
idbWebTextRowLength.value = htmlArray.length;
idbWebTextRowCount.value = "1";
idbWebTextRowTotal.value = "";
weboutputconversion.value = "";
Changeidwebinputconversion();
Changeidweboutputconversion();
if(idWebOnlineMessageText.checked){
idTextBox.value = "";
ChangeidTextBox();
}
idWebOnlineCompressor.value = "停止转换";
ghtmltextsize = 0;
g_webstart = 0;
g_webzip = 0;
setTimeoutID = setTimeout(HtmlWebtOnlineCompressortimeout, 5);
}
function HtmlWebtOnlineCompressortimeout()
{//HTML在线压缩
var strArray = new Array();
var valArray = new Array();
var str, ptr, ctr, i, j, k, len, pos, row, start;
var htmltextcount, htmltextsize, htmltextlength;
var patrn = /[:;{}) ]/;//正则表达式
var patrnx = /[:;{}\x3e]/;//正则表达式
row = 0;
htmltextcount = parseInt(idbWebTextRowStart.value);
htmltextsize = parseInt(idbWebTextRowSize.value);
htmltextlength = htmlArray.length;
for(i = 0;i < 100;i ++) {
str = htmlArray[htmltextcount - 1];
str = StringTrim(str);//取一行文本
if(str != ""){
if((str.substr(0, 1) == "<") || (str.substr(str.length - 1, 1) == ">")){
if(str.substr(str.length - 3, 2) == "--"){
str = "\n" + str;//"-->"
idbWebTextRowCount.value = parseInt(idbWebTextRowCount.value) + 1;
}
else if(str.substr(1, 3) == "!--"){
str = "\n" + str;//"<!--"
idbWebTextRowCount.value = parseInt(idbWebTextRowCount.value) + 2;
}
else if((str.substr(0, 7).toLowerCase() == "<script") || (str.substr(0, 6).toLowerCase() == "<style")){
if(str.substr(0, 7).toLowerCase() == "<script"){
ptr = str.toLowerCase();
if(ptr.indexOf("vbscript") >= 18){
g_webstart |= 2;//VBS连续不压缩
}
else{
g_webzip |= 1;//压缩
}
}
else if(str.substr(0, 6).toLowerCase() == "<style"){
g_webzip |= 9;//压缩
}
str = "\n" + str;
idbWebTextRowCount.value = parseInt(idbWebTextRowCount.value) + 1;
}
else if((str.substr(str.length - 8, 8).toLowerCase() == "/script>") || (str.substr(str.length - 7, 7).toLowerCase() == "/style>")){
if(str.substr(str.length - 8, 8).toLowerCase() == "/script>"){
g_webstart = 0;//连续压缩
}
g_webzip = 0;
str = "\n" + str;
idbWebTextRowCount.value = parseInt(idbWebTextRowCount.value) + 1;
}
}
else if(str.substr(0, 2) == "/*") {//多行注解在开始
HtmlWebtOnlineMessage(htmltextcount, str);
if(!((g_webstart == 0) && (str.substr(str.length - 2, 2) == "*/"))){//可能是行内注释
g_webstart |= 1;//多行注释开始
}
str = "";//删除一整行
}
else if(str.substr(str.length - 2, 2) == "*/") {
HtmlWebtOnlineMessage(htmltextcount, str);
if(g_webstart > 0){
str = "";//删除一整行
}
else{//发现行内注解
strArray = str.split("/*");
len = strArray.length;
if(len > 1){//开始注解
strArray[len - 1] = "";//去掉尾部注释
str = strArray.join("");//更新str
}
else{
str = "";//删除一整行
}
}
g_webstart = 0;
}
else if(g_webstart == 1){
str = "";//删除一整行
}
else if(str.substr(0, 2) == "//") {
HtmlWebtOnlineMessage(htmltextcount, str);
if(str.substr(str.length - 3, 3) != "--\x3e"){
str = "";//删除一整行
}
else{
str = "\n" + str;
idbWebTextRowCount.value = parseInt(idbWebTextRowCount.value) + 1;
}
}
else{
strArray = str.split("//");
len = strArray.length;
if(len > 1){//分号
ctr = StringRightTrim(strArray[len - 1]);
if(ctr.substr(ctr.length - 1,1) != ";"){//肯定是注释了
ptr = StringRightTrim(strArray[len - 2]);//取注释前的部分字符
if(patrn.test(StringRight(ptr, 1)) || (ptr.substr(ptr.length - 4, 4) == "else")){
HtmlWebtOnlineMessage(htmltextcount, str);
if(len > 2){//1行有多个注释符号
str = str.slice(0, -(ctr.length + 2));
str += "\n";
idbWebTextRowCount.value = parseInt(idbWebTextRowCount.value) + 1;
}
else{
strArray[len - 1] = "";//去掉尾部注释
str = strArray.join("");//更新str
}
}
}
}
}
if(str != ""){
if(str.substr(0, 9) == "function "){
str = EraseCodeStringBackspace(str, 9, ")");
HtmlWebtOnlineMessage(htmltextcount, str);
if(g_webzip & 4){
g_webzip &= ~4;
}
else{
str = "\n" + str;
}
idbWebTextRowCount.value = parseInt(idbWebTextRowCount.value) + 1;
g_webzip |= 2;
}
else{
if(!patrnx.test(str.substr(str.length - 1, 1))){
if(g_webzip & 2){
g_webzip &= ~2;
}
else{
str += "\n";
g_webzip |= 4;
}
}
else if(str.substr(0, 4) == "var "){
if(str.indexOf("new ") < 0){
str = EraseCodeStringBackspace(str, 4, ";");
}
}
else if(str.substr(0, 2) == "if"){
str = EraseCodeStringBackspace(str, 2, ")");
}
else if(str.substr(0, 4) == "else"){
if(str.substr(0, 7) == "else if"){
str = EraseCodeStringBackspace(str, 7, ")");
}
}
else if(str.substr(0, 3) == "for"){
str = EraseCodeStringBackspace(str, 3, ")");
}
else if(str.substr(0, 5) == "while"){
str = EraseCodeStringBackspace(str, 5, ")");
}
else if(str.substr(0, 6) == "switch"){
str = EraseCodeStringBackspace(str, 6, ")");
}
else if(str.substr(0, 2) == "do"){
}
else if(str.substr(0, 4) == "case"){
}
else if(str.substr(0, 5) == "break"){
}
else if(str.substr(0, 7) == "default"){
}
else if(str.substr(0, 6) == "return"){
}
else if(g_webstart == 0){
if(str.indexOf("new ") < 0){
if(g_webzip & 8){//CCS
if(str.indexOf("{") < 0){
// str = EraseCodeStringBackspace(str, 0, "");
}
}
else{
str = EraseCodeStringBackspace(str, 0, ";");
}
}
}
}
weboutputconversion.value += str;
}
}
htmltextcount++;
ghtmltextsize++;
if(ghtmltextsize >= htmltextsize) break;
}
var d = new Date();
idbWebTextRowStart.value = htmltextcount;
idbWebTextRowTimeCount.value = d.toLocaleTimeString();
if(idWebOnlineMessageText.checked){
ChangeidTextBox();
}
idbWebTextRowTotal.value = Changeidweboutputconversion();
if(ghtmltextsize < htmltextsize){
setTimeoutID = setTimeout(HtmlWebtOnlineCompressortimeout, 5);
return;
}
else{
if((htmltextcount + htmltextsize) < htmltextlength){
if(confirm("网页压缩段落完成,请确认是否继续压缩???")){
ghtmltextsize = 0;
setTimeoutID = setTimeout(HtmlWebtOnlineCompressortimeout, 5);
return;
}
}
start = 0;
if(idWebOnlineMessagePackText.checked){
if(TestIE()) strArray = weboutputconversion.value.split("\r\n");
else strArray = weboutputconversion.value.split("\n");
if(!idWebOnlineMessageText.checked){
idTextBox.value = "";
str = "压缩后行信息分析:";
}
else{
str = "\n\n" + "压缩后行信息分析:";
}
for(n = 0;n < strArray.length;n++){
ptr = strArray[n];
valrArray = ptr.split("//");
len = valrArray.length;
if(len > 1){//分号
str += "\n" + (n + 1) + ": //" + valrArray[1];
start = 1;
}
}
}
if(start > 0){
idTextBox.value += str;
ChangeidTextBox();
}
idWebOnlineCompressor.value = "网页转换";
Changeidweboutputconversion();
if(confirm("网页压缩成功!!!需要将其复制到剪切板上吗???")){
if(idclipboard(weboutputconversion)) alert("网页目的编辑框的内容已经被全部复制,请在其它地方用Ctrl+V粘贴过去!!!");
else alert("该浏览器多线程不支持自动复制,请点击”复制文本“按钮复制到剪切板上!!!");
}
}
}
function EraseCodeStringBackspace(str, pos, sp)
{
var ptr, ctr, len, i;
if(g_webzip & 1){
ptr = str.substr(pos, str.length-pos);
if((ptr.indexOf("'") < 0) && (ptr.indexOf('"') < 0) && (ptr.indexOf("//") < 0)){
len = str.length;
ptr = "";
ctr = "";
for(i = pos;i < len;i++){
if(str[i] == sp){
ctr = str.substr(i, len - 1);
break;
}
if(str[i] != " "){
ptr += str[i];
}
}
str = str.substr(0, pos);
str += ptr + ctr;
}
}
return str;
}
function calculator()
{
var str, str0, str1, len, i, j, val, ibit;
var crcdir, crcbit, size;
var ptr;
var numpatrn = /^[0-9]+$/;//正则表达式
len = GetText12StringLen();
switch(operatorsele.selectedIndex)
{
case 0://CRC运算
hotcrc();
break;
case 1://^
text140.value = StringXORToStringLeft(text12.value, text13.value);
break;
case 2://!,旧的
text13.value = "";
text140.value = StringNOTToString(text12.value);
break;
case 3://&
text140.value = StringANDToStringLeft(text12.value, text13.value);
break;
case 4://|
text140.value = StringORToStringLeft(text12.value, text13.value);
break;
case 5://"<<"
text13.value = StringMoveToStringLeft(text12.value, parseInt(text140.value));
break;
case 6://">>"
text13.value = StringMoveToStringRight(text12.value, parseInt(text140.value));
break;
case 7://+,旧的
text140.value = StringADDToString(text12.value, text13.value);
break;
case 8://-,旧的
text140.value = StringSUBToString(text12.value, text13.value);
break;
case 9://反序运算
text13.value = StringInvertlToString(text12.value);//反序
text140.value = "";
break;
case 10://反转运算
text13.value = StringReversalToString(text12.value);//反转
text140.value = "";
break;
case 11://HTML在线压缩
break;
case 12://采样,表格或算法逆向
crcbit = GetCRCTableArrayBitsInt();
crcdir = GetCRCTableArrayDirInt();//方向
crcnum = crcbit / 4;
switch(GetCRCNxTabSelect()){
/*
selindex=000单表大表
selindex=001单表小表
selindex=010双表大表
selindex=011双表小表
selindex=100算法大表
selindex=101算法小表
*/
case 0://单表大表
OutputCRCTableArrayText(0);//采样
break;
case 1://单表小表
OutputCRCTableArrayText(1);//采样
break;
case 2://双表大表
OutputCRCTableArrayText(2);//采样
break;
case 3://双表小表
OutputCRCTableArrayText(3);//采样
break;
case 4://算法
case 5://算法
ptr = text13.value;//保存密文即4次或5次的结果
if (crcbit <= 32)
{
str0 = inttohex(0, crcnum);
str0 += inttohex(1, crcnum);
if (crcnum == 1) str0 += inttohex(0x8, crcnum);//奇数
else str0 += inttohex(0x80, crcnum);
str0 += inttohex(-1, crcnum);
}
else
{
crcnumh = crcnum - 8;
str0 = inttohex(0, crcnumh) + inttohex(0, 8);
str0 += inttohex(0, crcnumh) + inttohex(1, 8);
str0 += inttohex(0, crcnumh) + inttohex(0x80, 8);
str0 += inttohex(-1, crcnumh) + inttohex(-1, 8);
}
str = GetHotWC3CRCPolyWorkValue(str0.substr(0, crcnum), text120.value, text130.value, text170.value, crcdir, crcbit, 0);//CRC4~32
str += GetHotWC3CRCPolyWorkValue(str0.substr(crcnum, crcnum), text120.value, text130.value, text170.value, crcdir, crcbit, 0);//CRC4~32
str += GetHotWC3CRCPolyWorkValue(str0.substr(crcnum * 2, crcnum), text120.value, text130.value, text170.value, crcdir, crcbit, 0);//CRC4~32
str += GetHotWC3CRCPolyWorkValue(str0.substr(crcnum * 3, crcnum), text120.value, text130.value, text170.value, crcdir, crcbit, 0);//CRC4~32
text12.value = str0;
text13.value = str;
str1 = str0.substr(3*crcnum,crcnum);//FFFF
str0 = str0.substr(0,crcnum);//0000
if((str != ptr) && (((text120.value == str0) || (text120.value == str1)) && ((text170.value == str0) || (text170.value == str1)))) {//初值和出值都为0000,FFFF。两次密文一样也采样5点
if(displayout.checked) idTextBox.value = "四点采样逆向数据=" + text13.value;
}
else{
// operatorsele.selectedIndex = 0;
// calculator();
hotcrc();//运算
text13.value = str + text140.value;
operatorsele.selectedIndex = 12;
if(displayout.checked) idTextBox.value = "五点采样逆向数据=" + text13.value;
}
ChangeidTextBox();
break;
}
break;
case 13://生成
MakeCRCTablePROC();
break;
case 14://Unicode编码
if (text12.value != "")
{
text13.value = escape(text12.value);
idTextBox.value = "Unicode原码=" + text12.value + "\n";
idTextBox.value += "Unicode编码=" + text13.value + "\n";
idTextBox.value += "UTF-8编码=" + encodeURIComponent(text12.value);
ChangeidTextBox();
}
break;
case 15://GB2312-80编码
if (text12.value != "")
{
text13.value = AscToHexString(text12.value);
idTextBox.value = "GB2312-80原码=" + text12.value + "\n";
idTextBox.value += "GB2312-80编码=" + text13.value;
ChangeidTextBox();
}
break;
case 16://HotCode
if (text12.value != "")
{
text13.value = HotCodeToHex(text12.value);
idTextBox.value = "HotCode原码=" + text12.value + "\n";
idTextBox.value += "HotCode编码=" + text13.value;
ChangeidTextBox();
}
break;
case 17://ASCII
if (text12.value != "")
{
str = text12.value;
text13.value = AsciiToHex(str);
idTextBox.value = "ASCII原码=" + text12.value + "\n";
idTextBox.value += "ASCII编码=" + text13.value;
text140.value = str.charCodeAt(0);
idTextBox.value += "\n第1个ASCII码对应的10进制数为" + text140.value;
ChangeidTextBox();
}
break;
case 18://BASE64
if (text12.value != "")
{
str = CodeStringToHex(text12.value, idselecodemode.selectedIndex);
text13.value = HexToAscii(Base64ToHex(str));
idTextBox.value = "BASE64原码为" + text12.value + "\n";
idTextBox.value += "BASE64编码为" + text13.value;
idTextBox.value += "\n对应的HEX为" +AsciiToHex(text13.value);
ChangeidTextBox();
}
break;
case 19://UUEncode编码
if (text12.value != "")
{
str = CodeStringToHex(text12.value, idselecodemode.selectedIndex);
text13.value = HexToAscii(UUEncodeToHex(str));
idTextBox.value = "UUEncode原码为" + text12.value + "\n";
idTextBox.value += "UUEncode编码为" + text13.value;
idTextBox.value += "\n对应的HEX为" + AsciiToHex(text13.value);
ChangeidTextBox();
}
break;
case 20://XXEncode编码
if (text12.value != "")
{
str = CodeStringToHex(text12.value, idselecodemode.selectedIndex);
text13.value = HexToAscii(XXEncodeToHex(str));
idTextBox.value = "XXEncode原码为" + text12.value + "\n";
idTextBox.value += "XXEncode编码为" + text13.value;
idTextBox.value += "\n对应的HEX为" + AsciiToHex(text13.value);
ChangeidTextBox();
}
break;
case 21://Quoted-printable
if (text12.value != "")
{
str = CodeStringToHex(text12.value, idselecodemode.selectedIndex);
text13.value = HexToAscii(QPCodeToHex(str));
idTextBox.value = "Quoted-printable原码为" + text12.value + "\n";
idTextBox.value += "Quoted-printable编码为" + text13.value;
idTextBox.value += "\n对应的HEX为" + AsciiToHex(text13.value);
ChangeidTextBox();
}
break;
case 22://UTF-8
if (text12.value != "")
{
text13.value = UTF_8ToHex(text12.value);//encodeURIComponent(text12.value)
idTextBox.value = "UTF-8原码=" + text12.value + "\n";
idTextBox.value += "UTF-8编码=" + text13.value + "\n";
idTextBox.value += "UniCode编码=" + escape(text12.value);
ChangeidTextBox();
}
break;
case 23://区位码
if (text12.value != "")
{
text13.value = ChnToNumString(text12.value);//区位码
idTextBox.value = "区位码原码=" + text12.value + "\n";
idTextBox.value += "区位码编码=" + text13.value;
ChangeidTextBox();
}
break;
}
text140Count = 0;
text140text = text140.value;
}
function SetFuncNameString(str)
{
var strArray = new Array();
strArray = str.split(",");
if(strArray.length != 5){
idinputtext.value = "明文";
idoutputtext.value = "密文";
idresulttext.value = "结果";
idbcalculator.value = "运算";
idbrevert.value = "还原";
}
else{
if(strArray[0] != "") idinputtext.value = strArray[0];
if(strArray[1] != "") idoutputtext.value = strArray[1];
if(strArray[2] != "") idresulttext.value = strArray[2];
if(strArray[3] != "") idbcalculator.value = strArray[3];
if(strArray[4] != "") idbrevert.value = strArray[4];
}
}
function changeoperator()
{
var str;
switch(operatorsele.selectedIndex)
{
case 11://保留功能
operatorsele.selectedIndex = 0;
// break;
case 0://CRC运算
SetFuncNameString("明文,密文,结果,运算,还原");
idbsetuphelpsele.selectedIndex = 0;//帮助
text140.value = "";
selesetuphelp();
break;
case 12://CRC表格或算法逆向
SetFuncNameString("样本,采集,结果,采样,**");
crcnxsele.selectedIndex = 2;//算法
crctabsele.selectedIndex = 0;//大表
idbsetuphelpsele.selectedIndex = 1;//帮助
selesetuphelp();
//???? calculator();//采样
break;
case 13://CRC表及算法
SetFuncNameString("明文,文件,结果,生成,逆向");
if(TestIE()){
text13.value = "C:\\HotWC3\\" + text160.value + languagesele.value;
}
else{
text13.value = "";
}
crcnxsele.selectedIndex = 0;//单表
crctabsele.selectedIndex = 0;//大表
idbsetuphelpsele.selectedIndex = 2;//帮助
selesetuphelp();
break;
case 14://Unicode
case 17://ASCII
case 22://UTF-8
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 18://BASE64
case 19://UUEncode
case 20://XXEncode
case 21://Quoted-printable
if(TestIE()) {
idselecodemode.selectedIndex = 2;//GB2312-80
}
else {
idselecodemode.selectedIndex = 5;//强行变为文本HotCode
}
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 14://Unicode
case 17://ASCII
case 22://UTF-8
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 18://BASE64
case 19://UUEncode
case 20://XXEncode
case 21://Quoted-printable
if(TestIE()) {
idselecodemode.selectedIndex = 2;//GB2312-80
}
else {
idselecodemode.selectedIndex = 5;//强行变为文本HotCode
}
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 14://Unicode
case 17://ASCII
case 22://UTF-8
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 18://BASE64
case 19://UUEncode
case 20://XXEncode
case 21://Quoted-printable
if(TestIE()) {
idselecodemode.selectedIndex = 2;//GB2312-80
}
else {
idselecodemode.selectedIndex = 5;//强行变为文本HotCode
}
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 14://Unicode
case 17://ASCII
case 22://UTF-8
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 18://BASE64
case 19://UUEncode
case 20://XXEncode
case 21://Quoted-printable
if(TestIE()) {
idselecodemode.selectedIndex = 2;//GB2312-80
}
else {
idselecodemode.selectedIndex = 5;//强行变为文本HotCode
}
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 14://Unicode
case 17://ASCII
case 22://UTF-8
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 18://BASE64
case 19://UUEncode
case 20://XXEncode
case 21://Quoted-printable
if(TestIE()) {
idselecodemode.selectedIndex = 2;//GB2312-80
}
else {
idselecodemode.selectedIndex = 5;//强行变为文本HotCode
}
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
break;
case 15://GB2312-80
case 23://区位码
if(TestIE()) {
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 11;//帮助
selesetuphelp();
}
else {
SetFuncNameString("明文,密文,结果,运算,还原");
idbsetuphelpsele.selectedIndex = 11;//帮助
operatorsele.selectedIndex = 0;//CRC基本运算
idTextBox.value = "非IE浏览器不得选中!!!";
}
break;
case 16://HotCode
SetFuncNameString("明文,密文,结果,编码,解码");
idbsetuphelpsele.selectedIndex = 12;//帮助
selesetuphelp();
break;
default:
SetFuncNameString("明文,密文,结果,计算,求逆");
break;
}
}
function revert()
{
var str, i, j, k, x, y, len;
switch(operatorsele.selectedIndex)
{
case 0://CRC运算
dishotcrc();
break;
case 1://^
text140.value = StringXORToStringRight(text12.value, text13.value);
break;
case 2://"!"
len = text140.value.length;
if (len <= 8)
{
text12.value = inttohex(~hextoint(text140.value), len);
}
else
{
text12.value = inttohex(~hextoint(text140.value.substr(0, len - 8)), len - 8) + inttohex(~hextoint(text140.value.substr(len - 8, 8)), 8);
}
break;
case 3://&
text140.value = StringANDToStringRight(text12.value, text13.value);
break;
case 4://|
text140.value = StringORToStringRight(text12.value, text13.value);
break;
case 5://"<<"
text13.value = StringMoveToStringLeftCY(text12.value, parseInt(text140.value), 1);
break;
case 6://">>"
text13.value = StringMoveToStringRightCY(text12.value, parseInt(text140.value), 1);
break;
case 9://反序还原
text12.value = StringDisInvertlToString(text13.value);//反序的还原
text140.value = "";
break;
case 10://反转还原
text12.value = StringReversalToString(text13.value);//反转
text140.value = "";
break;
case 11://HTML文件压缩
break;
case 12://表格或算法逆向
switch(GetCRCNxTabSelect()){
/*
selindex=000单表大表
selindex=001单表小表
selindex=010双表大表
selindex=011双表小表
selindex=100算法大表
selindex=101算法小表
*/
case 0://单表大表
InputCRCTableArrayText(0);//**
break;
case 1://单表小表
InputCRCTableArrayText(1);//**
break;
case 2://双表大表
InputCRCTableArrayText(2);//**
break;
case 3://双表小表
InputCRCTableArrayText(3);//**
break;
case 4://算法
case 5://算法
idTextBox.value = "";
//return;
var text13_value = text13.value;
converse(0);
if(idTextBox.value == ""){
converse(1);
}
text13.value = text13_value;
break;
}
break;
case 13://逆向表格
//MakeCRCTablePROC();
break;
case 14://Unicode解码
/*
0X00~0X7F ascii
0x4e00~0x9FA5 常用汉字部分
0xff00~0xffef 全角ascii,全角中英文标点等
*/
if (text13.value != "")
{
text12.value = unescape(text13.value);
idTextBox.value = "Unicode编码=" + text13.value + "\n";
idTextBox.value += "Unicode解码=" + text12.value;
ChangeidTextBox();
}
break;
case 15://GB2312-80解码
if (text13.value != "")
{
text12.value = HexToAscString(text13.value);
idTextBox.value = "GB2312-80编码=" + text13.value + "\n";
idTextBox.value += "GB2312-80解码=" + text12.value;
ChangeidTextBox();
}
else
{
var Hot_GB2312_80_TableArray = new Array(23);
Hot_GB2312_80_TableArray[0] = "A_1601_1636";
Hot_GB2312_80_TableArray[1] = "B_1637_1832";
Hot_GB2312_80_TableArray[2] = "C_1833_2077";
Hot_GB2312_80_TableArray[3] = "D_2078_2273";
Hot_GB2312_80_TableArray[4] = "E_2274_2301";
Hot_GB2312_80_TableArray[5] = "F_2302_2432";
Hot_GB2312_80_TableArray[6] = "G_2433_2593";
Hot_GB2312_80_TableArray[7] = "H_2594_2786";
Hot_GB2312_80_TableArray[8] = "J_2787_3105";
Hot_GB2312_80_TableArray[9] = "K_3106_3211";
Hot_GB2312_80_TableArray[10] = "L_3212_3471";
Hot_GB2312_80_TableArray[11] = "M_3472_3634";
Hot_GB2312_80_TableArray[12] = "N_3635_3721";
Hot_GB2312_80_TableArray[13] = "O_3722_3729";
Hot_GB2312_80_TableArray[14] = "P_3730_3857";
Hot_GB2312_80_TableArray[15] = "Q_3858_4026";
Hot_GB2312_80_TableArray[16] = "R_4027_4085";
Hot_GB2312_80_TableArray[17] = "S_4086_4389";
Hot_GB2312_80_TableArray[18] = "T_4390_4557";
Hot_GB2312_80_TableArray[19] = "W_4558_4683";
Hot_GB2312_80_TableArray[20] = "X_4684_4924";
Hot_GB2312_80_TableArray[21] = "Y_4925_5248";
Hot_GB2312_80_TableArray[22] = "Z_5249_5589";
idTextBox.value = "";
for (i = 0; i <= 22; i ++)
{
cstr = Hot_GB2312_80_TableArray[i];
x = cstr.substr(2, 4);
y = cstr.substr(7, 4);
str = "第" + cstr.substr(0, 1) + "区(区位码" + x + "~" + y;
x = parseInt(x, 10);
y = parseInt(y, 10);
str += "共" + parseInt(y - x + 1, 10) + "个汉字):\n";
k = 0;
for(j = x; j <= y;)
{
str += HexToAscString(inttohex((((j / 100) + 160)<<8) + ((j % 100)+160) ,4));
k ++;
if((k % 64) == 0) str += "\n";
j ++;
if ((j % 100) == 95) j += 6;
}
idTextBox.value += str + "\n";
}
ChangeidTextBox();
}
break;
case 16://HotCode
if (text13.value != "")
{
text12.value = HexToHotCode(text13.value);//HotCode
idTextBox.value = "HotCode编码=" + text13.value + "\n";
idTextBox.value += "HotCode解码=" + text12.value;
ChangeidTextBox();
}
break;
case 17://ASCII
if (text13.value != "")
{
str = HexToAscii(text13.value);
text12.value = str;
idTextBox.value = "ASCII编码=" + text13.value + "\n";
idTextBox.value += "ASCII解码=" + text12.value;
}
else if (text140.value != "")
{
text13.value = inttohex(parseInt(text140.value), 2);
str = HexToAscii(text13.value);
text12.value = str;
idTextBox.value = "ASCII编码=" + text13.value + "\n";
idTextBox.value += "ASCII解码=" + text12.value;
}
ChangeidTextBox();
break;
case 18://BASE64
if (text13.value != "")
{
str = AsciiToHex(text13.value);
str = HexToBase64(str);
text12.value = HexToCodeString(str, idselecodemode.selectedIndex);
idTextBox.value = "BASE64编码为" + text13.value + "\n";
idTextBox.value += "BASE64解码为" + text12.value;
ChangeidTextBox();
}
break;
case 19://UUEncode解码
if (text13.value != "")
{
str = AsciiToHex(text13.value);
str = HexToUUEncode(str);
text12.value = HexToCodeString(str, idselecodemode.selectedIndex);
idTextBox.value = "UUEncode编码为" + text13.value + "\n";
idTextBox.value += "UUEncode解码为" + text12.value;
ChangeidTextBox();
}
break;
case 20://XXEncode解码
if (text13.value != "")
{
str = AsciiToHex(text13.value);
str = HexToXXEncode(str);
text12.value = HexToCodeString(str, idselecodemode.selectedIndex);
idTextBox.value = "XXEncode编码为" + text13.value + "\n";
idTextBox.value += "XXEncode解码为" + text12.value;
ChangeidTextBox();
}
break;
case 21://Quoted-printable
if (text13.value != "")
{
str = AsciiToHex(text13.value);
str = HexToQPCode(str);
text12.value = HexToCodeString(str, idselecodemode.selectedIndex);
idTextBox.value = "Quoted-printable编码为" + text13.value + "\n";
idTextBox.value += "Quoted-printable解码为" + text12.value;
ChangeidTextBox();
}
break;
case 22://UTF-8
if (text13.value != "")
{
text12.value = HexToUTF_8(text13.value);//decodeURI(text13.value)
idTextBox.value = "UTF-8编码=" + text13.value + "\n";
idTextBox.value += "UTF-8解码=" + text12.value;
ChangeidTextBox();
}
break;
case 23://区位码
if (text13.value != "")
{
text12.value = NumToChnString(text13.value);//区位码
idTextBox.value = "区位码编码=" + text13.value + "\n";
idTextBox.value += "区位码解码=" + text12.value;
}
else
{
idTextBox.value = "";
for (i = 1; i <= 94; i ++)
{
str = "第" + i + "区(区内94位):\n";
k = 0;
for(j = 1; j <= 47; j ++)
{
str += HexToAscString(inttohex(((i + 160)<<8) + (j+160) ,4));
}
str += "\n";
for(j = 48; j <= 94; j ++)
{
str += HexToAscString(inttohex(((i + 160)<<8) + (j+160) ,4));
}
idTextBox.value += str + "\n";
}
}
ChangeidTextBox();
break;
}
text140Count = 0;
text140text = text140.value;
}
function getcrcrandom12(num)
{
var str, crcbits, crcnum;
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
str = getrandomnum(2 * crcnum * num);
text12.value = str;
}
function getcrcrandom13()
{
var str, crcbits, crcnum;
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
str = getrandomnum(4 * crcnum);
text13.value = str;
}
function getrandomnum(num)
{
/*
var i, len;
i = Math.random();
i = i.toString();
len = i.length;
i = i.substr(2,len - 2);
i = inttohex(eval(i),num);
return i;
*/
var i, str;
str = "";
for(i = 0; i < num;i++){
str += inttohex(Math.floor(Math.random() * 16));
}
return str;
}
function clearwc3input()
{
if(TestIE()){
// wc3input.focus();
// wc3input.select();
// document.execCommand("selectAll", "false", null);
wc3input.focus();
wc3input.select();
document.execCommand("Paste", "false", null);
alert("已经将剪切板复制到明文编辑框中!!!")
}
else{
wc3input.value = "";
ChangeidinputHotWC3TextBox();
}
}
function clearwc3output()
{
if(TestIE()){
// wc3output.focus();
// wc3output.select();
// document.execCommand("selectAll", "false", null);
wc3output.focus();
wc3output.select();
document.execCommand("Paste", "false", null);
alert("已经将剪切板复制到密文编辑框中!!!")
}
else{
wc3output.value = "";
ChangeidoutputHotWC3TextBox();
}
}
function getweek(century, year, month, day)
{
var week, dateval, table;
if (month <= 2)//1,2月变为去年的13,14月
{
year --;
if (year < 0)
{
year = 99;
century --;
if (century < 0)
{
century = 99;
}
}
month |= 4;//1,2月查5,6月表
// month += 12;//去年的13,14月
}
switch(weeksele.selectedIndex)
{
case 0:
/*
菜农星期公式
星期=(百年%4*5+年+年/4+(13*月+8)/5+日)%7
*/
week = ((century & 3) * 5 + year + (year >> 2) + Math.floor((13 * month + 8) / 5) + day) % 7;
break;
case 1:
/*
蔡勒星期公式
星期=(203+百年/4-2*百年+年+年/4+(13*月+8)/5+日)%7
*/
week = (203 + Math.floor(century / 4) - 2 * century + year + (year >> 2) + Math.floor((13 * month + 8) / 5) + day) % 7;
break;
case 2:
/*
基姆星期公式
星期=(百年/4+百年*5+年+年/4+(13*月+8)/5+日)%7
*/
week = (Math.floor(century / 4) + century * 5 + year + (year >> 2) + Math.floor((13 * month + 8) / 5) + day) % 7;
break;
case 3:
/*
菜农第二星期公式
星期=((百年*5)%20+年+年/4+(13*月+8)/5+日)%7
*/
week = ((century * 5) % 20 + year + (year >> 2) + Math.floor((13 * month + 8) / 5) + day) % 7;
break;
case 4:
/*
菜农第三星期公式
星期=(((日期/100)*5)%20+日期%100+(日期%100)4+(13*月+8)/5+日)%7
*/
dateval = century * 100 + year;
week = ((Math.floor(dateval / 100) * 5) % 20 + year + (year >> 2) + Math.floor((13 * month + 8) / 5) + day) % 7;
break;
case 5:
/*
星期公式月表
星期=(百年%4*5+年+年/4+星期月表+日)%7
*/
table = "2503514620";//3月为基月,3~12月,1,2月查5,6月表
week = ((century & 3) * 5 + year + (year >> 2) + parseInt(table.substr(month-3, 1), 10) + day) % 7;
break;
}
return week;
}
//取三角不可逆密码
function gettriangletable()
{
var i, j, str;
str = " 三角";
for (i = 0; i < 16; i ++) str += "---0x" + inttohex(i, 2);
str += "---密码\n";
for (i = 0; i < 16; i ++)
{
str += " 0x" + inttohex(i * 16, 2) + ": ";
for (j = 0; j < 16; j ++)
{
str += "0x" + inttohex(password(i * 16 + j), 4) + " ";
}
str += ":0x" + inttohex(i * 16, 2) + "\n";
}
str += " 三角";
for (i = 0; i < 16; i ++) str += "---0x" + inttohex(i, 2);
str += "---密码\n";
idTextBox.value = str;
ChangeidTextBox();
}
//取三角不可逆密码
function gettrianglepass(trianglepass)
{
var wc3l, wc3r;
trianglepass = trianglepass = password(trianglepass);//三角变换
wc3l = trianglepass >> 8;
wc3r = trianglepass & 0xff;
trianglepass = wc3l ^ wc3r;//叠加阻止反推密码(对的概率很大,欺骗解密者)
return trianglepass;
}
//EndHide-->
</script>
<script>
<!--Hide
//wc3加密过程
function hotwc3pass()
{
if(hotwc3filecheckbox.checked){//文件操作
idHotWC3File.click();//浏览文件后调用HotWC3HandleFiles()
}
else{
hotwc3passex();//直接加密
}
}
function HotWC3HandleFiles()
{
var filename, str, pos, len;
wc3fileinput.value = idHotWC3File.value.toUpperCase();//写入文件名称
filename = wc3fileinput.value;
if(!FileExists(filename)){
alert("文件:\n" + filename + "\n不存在!!!");
return;
}
if(wc3fileoutput.value == "") {
len = filename.length;
pos = filename.indexOf(".");
wc3fileoutput.value = filename.substr(0, pos) + ".WC3";
}
str = ReadFile(filename);
wc3input.value = str;
ChangeidinputHotWC3TextBox();
}
//wc3解密过程
function hotwc3dispass()
{
if(hotwc3filecheckbox.checked){//文件操作
idHotWC3FileEx.click();//浏览文件后调用HotWC3HandleFiles()
}
else{
hotwc3dispassex();
}
}
function HotWC3HandleFilesEx()
{
var filename, str;
wc3fileoutput.value = idHotWC3FileEx.value.toUpperCase();//写入文件名称
filename = wc3fileoutput.value;
if(!FileExists(filename)){
alert("文件:\n" + filename + "\n不存在!!!");
return;
}
str = ReadFile(filename);
wc3output.value = str;
ChangeidoutputHotWC3TextBox();
}
function CRCHandleFiles()
{
var stable, filename, write;
var seleFile, reader, blob;
if(idCRCFile.value != ""){
text13.value = idCRCFile.value;//写入文件名称(有路径)
}
filename = text13.value;
stable = idTextBox.value;
if(TestFILE() && (filename != "")){
seleFile = idCRCFile.files[0];//seleFile.name(没有路径)
reader = new FileReader();
reader.readAsText(seleFile, "gb2312");
reader.onload = function(){
idTextBox.value = this.result;//读入!!!
}
}
else if(TestIE() && (filename != "")){
write = true;
if(FileExists(filename)){
write = confirm("文件:\n" + filename + "\n已存在,覆盖吗?");
}
if(write){
WriteFile(filename, stable);
alert("文件:\n" + filename +"\n写入成功!!!");
}
}
}
function MakeCRCTablePROC()
{
MakeCRCTablePROCex();
if(crcfilecheckbox.checked){//文件操作
idCRCFile.click();//浏览文件后调用CRCHandleFiles()
}
}
function GetCRCTableBits()
{
var crcdir = selemode1.selectedIndex;
var crcbits = select1.selectedIndex;
var bits;
if((crcdir == 0) && ((crcbits & 1) == 0)){
bits = 4;//小表
crctabsele.selectedIndex = 1;
}
else{
bits = 8;//大表
crctabsele.selectedIndex = 0;
}
return bits;
}
function MakeCRCTablePROCex()
{
switch(GetCRCNxTabSelect()){
/*
selindex=000单表大表
selindex=001单表小表
selindex=010双表大表
selindex=011双表小表
selindex=100算法大表
selindex=101算法小表
*/
case 0://单表大表
MakeCRCTableArray(8);//单表大表
break;
case 1://单表小表
MakeCRCTableArray(4);//单表大表
break;
case 2://双表大表
MakeCRCTableArrayEx(8);//双表大表
break;
case 3://双表小表
MakeCRCTableArrayEx(4);//双表大表
break;
case 4://移位大表
MakeCRCBitsFunction(GetCRCTableBits());//源码
break;
case 5://移位小表
MakeCRCBitsFunction(GetCRCTableBits());//源码
break;
}
}
function MakeHotwc3Poly(crcpoly, crcinit, crcstop, crcdir)
{
var str;
if(crcdir){//左移CRC正运算
str = "CRC8L";
crcpoly |= 0x01;
}
else{
str = "CRC8R";
crcpoly |= 0x80;
}
str += "_" + inttohex(crcpoly, 2) + "_" + inttohex(crcinit, 2) + "_" + inttohex(crcstop, 2);
return str;
}
function hotwc3inputpasscheck()
{
var i, j, k, len, value, str, ptr, ctr, diff, mess, pass;
var strArray = new Array();
var strTextArray = new Array();
var valTextArray = new Array();
var strkey;
var err = 0;
strkey = "";
str = wc3inputanalysis.value;//取加密分析流
if(str == ""){
alert("加密分析编辑框内为空!!!");
return;
}
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) * 2;//1个字节2个数据位
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
for(i = 1; i < strArray.length; i++){//开始有表头
str = strArray[i];//取一行加密分析流
if(str != ""){
// idTextBox.value += str + "\n";
strTextArray = str.split("*");//1#0*CRC8R_XX_XX_XX(明文HEX,密文HEX,差分检测HEX)
if(strTextArray.length == 2) {
str = strTextArray[1];//CRC8R_XX_XX_XX(明文HEX,密文HEX,差分检测HEX)
strTextArray = str.split("(");//CRC8R_XX_XX_XX(明文HEX,密文HEX,差分检测HEX)
str = strTextArray[0];//CRC简写式:CRC8R_XX_XX_XX
ptr = strTextArray[1];//明文HEX,密文HEX,差分检测HEX)
valTextArray = ptr.split(",");//明文HEX,入口明文HEX,出口密文HEX,密文HEX,差分检测HEX)
mess = valTextArray[0];//明文
pass = valTextArray[1];//密文
str = GetHotWC3CRCPolyWorkString(str, mess, 0);//取出口密文运算值
diff= StringLeft(valTextArray[2], crcnum);//差分检测
if(HotWC3DiffCheck.checked){
diff = StringNot(diff);
}
if((str == pass) && (diff == StringXORToStringLeft(mess, pass))){//加密运算正确
}
else{
err++;
}
}//if
}//if
}//for
if(err){
alert("加密内核运算错误" + err + "次!!!");
}
else{
alert("加密内核运算正确!!!");
}
}//fuction
function hotwc3outputpasscheck()
{
var i, j, k, len, value, str, ptr, ctr, diff, mess, pass;
var strArray = new Array();
var strTextArray = new Array();
var valTextArray = new Array();
var strkey;
var err = 0;
strkey = "";
str = wc3outputanalysis.value;//取解密分析流
if(str == ""){
alert("解密分析编辑框内为空!!!");
return;
}
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) * 2;//1个字节2个数据位
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
for(i = 1; i < strArray.length; i++){//开始有表头
str = strArray[i];//取一行加密分析流
if(str != ""){
// idTextBox.value += str + "\n";
strTextArray = str.split("*");//1#0*CRC8R_XX_XX_XX(明文HEX,密文HEX,差分检测HEX)
if(strTextArray.length == 2) {
str = strTextArray[1];//CRC8R_XX_XX_XX(明文HEX,密文HEX,差分检测HEX)
strTextArray = str.split("(");//CRC8R_XX_XX_XX(明文HEX,密文HEX,差分检测HEX)
str = strTextArray[0];//CRC简写式:CRC8R_XX_XX_XX
ptr = strTextArray[1];//明文HEX,密文HEX,差分检测HEX)
valTextArray = ptr.split(",");//明文HEX,密文HEX,差分检测HEX)
mess = valTextArray[0];//明文
pass = valTextArray[1];//密文
str = GetDisHotWC3CRCPolyWorkString(str, pass, 0);//取入口明文运算值
diff= StringLeft(valTextArray[2], crcnum);//差分检测
if(HotWC3DiffCheck.checked){
diff = StringNot(diff);
}
if((str == mess) && (diff == StringXORToStringLeft(mess, pass))){//解密运算正确
}
else{
err++;
}
}//if
}//if
}//for
if(err){
alert("解密内核运算错误" + err + "次!!!");
}
else{
alert("解密内核运算正确!!!");
}
}//fuction
function hotwc3inputpassanalysis(displaymode)
{
var i, j, k, len, value, str, ptr, ctr;
var count;
var strArray = new Array();
var strTextArray = new Array();
var strkey;
var err = 0;
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) << 1;
var size = 3 * crcnum + 4;
strkey = "";
ctr = "";
str = wc3inputanalysis.value;//取加密分析流
if(str == ""){
alert("加密分析编辑框内为空!!!");
return;
}
else{
wc3outputanalysis.value = "";
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");//strArray为原始加密分析流
for(i = 1; i < (((strArray.length - 2) / 2) + 1); i++){//开始有表头,最多搜索一半
str = strArray[i];//取一行加密分析流
if(str != ""){//str为空可能是回车
strTextArray = str.split("*");//取一行加密分析流
if(strTextArray.length != 2) {//有1个*号把128位密钥隔开
err++;
break;
}
ctr = StringLeft(strTextArray[1], -size);//取128位密钥对应的CRCn简写式
for(j = i + 1; j < strArray.length; j++){//从下面开始找这个CRC8简写式
str = strArray[j];//取一行加密分析流
if(str != ""){
strTextArray = str.split("*");//取128位密钥
if(strTextArray.length != 2) {
err++;
break;
}
if(ctr == StringLeft(strTextArray[1], -size)){//找到的CRC8简写式
//此时是i, j之间的问题
len = j - i;//搜索长度
count = 0;
if((j + len) < strArray.length){
for(k = 1; k < len; k++){//去掉第1个,因为已经测试过了
str = strArray[i + k];//取一行加密分析流
strTextArray = str.split("*");//取128位密钥
str = StringLeft(strTextArray[1], -size);//CRC8简写式
ptr = strArray[j + k];//取一行加密分析流
strTextArray = ptr.split("*");//取128位密钥
ptr = StringLeft(strTextArray[1],-size);//CRC8简写式
if(str != ptr){//
break;//没找到退出
}//if str
count++;//
}
if(count > 0){//找到两块数据,(i-k),(j-k)
count++;//实际个数
wc3outputanalysis.value += "{\n";
wc3outputanalysis.value += " {\n";
for(k = 0; k < count; k++){//i-(i+k)
str = strArray[i + k];//取一行加密分析流
wc3outputanalysis.value += " " + str + "#" + (i + k + 1) + "\n";
}//for k
wc3outputanalysis.value += " }\n";
wc3outputanalysis.value += " {\n";
for(k = 0; k < count; k++){//j-(j+k)
str = strArray[j + k];//取一行加密分析流
wc3outputanalysis.value += " " + str + "#" + (j + k + 1) + "\n";
}//for k
wc3outputanalysis.value += " }\n";
wc3outputanalysis.value += "}\n\n";
i = j + count;
}//if count > 0找到
}
}
}
}
}
}
}
ChangeidHotWC3outputTextBoxanalysis();
if(wc3outputanalysis.value != "") {
alert("加密密钥:\n" + getHotWC3Password() + "是弱密钥!!!");
return;//找到弱密钥退出
}
if(err){
alert("加密分析编辑框内分析格式不对!!!");
}
else if(displaymode){
alert("恭喜您,没有发现加密弱密钥!!!");
}
}
function hotwc3outputpassanalysis(displaymode)
{
var i, j, k, len, value, str, ptr, ctr;
var count;
var strArray = new Array();
var strTextArray = new Array();
var strkey;
var err = 0;
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) << 1;
var size = 3 * crcnum + 4;
strkey = "";
ctr = "";
str = wc3outputanalysis.value;//取解密分析流
if(str == ""){
alert("解密分析编辑框内为空!!!");
return;
}
else{
wc3inputanalysis.value = "";
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
for(i = 1; i < ((strArray.length / 2) + 1); i++){//开始有表头,最多搜索一半
str = strArray[i];//取一行解密分析流
if(str != ""){
strTextArray = str.split("*");//取一行解密分析流
if(strTextArray.length != 2) {
err++;
break;
}
ctr = StringLeft(strTextArray[1],-size);//取128位密钥对应的CRC8简写式
for(j = i + 1; j < strArray.length; j++){//从下面开始找这个CRC8简写式
str = strArray[j];//取一行解密分析流
if(str != ""){
strTextArray = str.split("*");//取128位密钥
if(strTextArray.length != 2) {
err++;
break;
}
if(ctr == StringLeft(strTextArray[1],-size)){//找到的CRC8简写式
//此时是i, j之间的问题
len = j - i;//搜索长度
count = 0;
if((j + len) < strArray.length){
for(k = 1; k < len; k++){//去掉第1个,因为已经测试过了
str = strArray[j];//取一行解密分析流
strTextArray = str.split("*");//取128位密钥
str = StringLeft(strTextArray[1],-size);//CRC8简写式
ptr = strArray[j];//取一行解密分析流
strTextArray = ptr.split("*");//取128位密钥
ptr = StringLeft(strTextArray[1],size);//CRC8简写式
if(str != ptr){
break;//没找到退出
}
count++;//
}
if(count > 0){//找到两块数据,(i-k),(j-k)
count++;
wc3inputanalysis.value += "{\n";
wc3inputanalysis.value += " {\n";
for(k = 0; k < count; k++){
str = strArray[i + k];//取一行解密分析流
wc3inputanalysis.value += " " + str + "#" + (i + k + 1) + "\n";
}
wc3inputanalysis.value += " }\n";
wc3inputanalysis.value += " {\n";
for(k = 0; k < count; k++){
str = strArray[j + k];//取一行解密分析流
idTextBox.value += " " + str + "#" + (j + k + 1) + "\n";
}
wc3inputanalysis.value += " }\n";
wc3inputanalysis.value += "}\n\n";
i=j+count;
}
}
}
}
}
}
}
}
ChangeidHotWC3inputTextBoxanalysis();
if(wc3inputanalysis.value != "") {
alert("解密密钥:\n" + getHotWC3Password() + "是弱密钥!!!");
return;//找到弱密钥退出
}
if(err){
alert("解密分析编辑框内分析格式不对!!!");
}
else if(displaymode){
alert("恭喜您,没有发现解密弱密钥!!!");
}
}
//wc3加密过程
var gHotWC3LoadCout = 0;
function hotwc3passex()
{
var i, j, k, n, len, str, ptr;
var strArray = new Array();
var strTextArray = new Array();
var polyArray = new Array();
var polyArrayString;
RefreshCRCTextString();//刷新
/*
1.HotWC3初始化
*/
//HotWC3初始密钥推导过程(推导出:日期密钥,天地密钥,星期密钥,三角密钥)
if(!TestHotWC3Password(getHotWC3Password())){//取128位密钥
return;
}
RefreshCRCTextString();//刷新
/*
初始化开始
*/
/*
初始化结束
*/
str = wc3input.value;//取明文流
if(str.length == 0)
{
alert("明文是空的不能加密!!!");
return;
}
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) << 1;
if(hotwc3CRC32checkbox.checked){
polyArrayString = "CRC32R_EDB88320_FFFFFFFF_FFFFFFFF";//CRC32
polyArray = polyArrayString.split("_");
}
wc3inputanalysis.value = "0#0*CRCn简写式(明文HEX,入口明文HEX,出口密文HEX,密文HEX,差分检测HEX)";
wc3output.value = "";
strTextArray.length = 0;
var diffcheck = true;
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
for(n = 0; n < strArray.length; n++){
str = strArray[n];//取一组明文
str = CodeStringToHex(str, idselechnmode.selectedIndex);//把明文转换为HEX
len = str.length;//取明文长度
if(hotwc3CRC32checkbox.checked){//需要CRC32
if(str == "") polyArray[2] = GetHotWC3CRCPolyWorkStringEx(polyArrayString, inttohex(n, 8));
else polyArray[2] = GetHotWC3CRCPolyWorkStringEx(polyArrayString, str);
polyArrayString = polyArray.join("_");
}
ptr = "";//输出密文字符串
if((len & 1) == 0){//明文流字符为偶数
for(i = 0; i < len; i += crcnum){
ptr += GetHotWC3PassWorkFunction(crcindex, str.substr(i, crcnum), diffcheck);//取明文
}
str = CodeStringExToHex(ptr, idseleoutmode.selectedIndex);
switch(idseleoutmode.selectedIndex)
{
case 1:
case 2:
case 3:
case 4:
str = HexToAscii(str);
break;
case 5:
str = HexToBase4096(str);
break;
}
strTextArray[strTextArray.length] = str;//写一行密文
}
}
ChangeidHotWC3inputTextBoxanalysis();
//加密结束
str = getHotWC3Password();//取128位密钥
if(hotwc3CRC32checkbox.checked){//CRC32
strTextArray[strTextArray.length] = "===" + polyArray[2];//填写CRC32
}
if(hotwc3Keycheckbox.checked){
strTextArray[strTextArray.length] = "***" + str;
}
if(hotwc3titlecheckbox.checked){
if(hotwc3titleoutput.value != "") {
strTextArray[strTextArray.length] = "???" + hotwc3titleoutput.value;//发送标题
}
}
if(strTextArray.length > 0) {//有密文生成
if(TestIE()) str = strTextArray.join("\r\n");
else str = strTextArray.join("\n");
wc3output.value = str;
ChangeidoutputHotWC3TextBox();
if(gHotWC3LoadCout == 0) {
gHotWC3LoadCout = 1;
}
else {
if(confirm("明文成功加密!!!需要将密文复制到剪切板上吗???")){
wc3outputclipboard();//
}
}
}
if(hotwc3filecheckbox.checked && (wc3output.value != "") && (wc3fileoutput.value)){
filename = wc3fileoutput.value.toUpperCase();
len = filename.length;
if(filename.substr(len - 4, 4) != ".WC3"){
alert("文件:\n" + filename +"\n必须是.WC3文件!!!");
}
else{
write = true;
if(FileExists(filename)){
write = confirm("文件:\n" + filename + "\n已存在,覆盖吗?");
}
if(write){
WriteFile(filename, wc3output.value);
alert("文件:\n" + filename +"\n写入成功!!!");
}
}
}
}
//wc3解密过程
function hotwc3dispassex()
{
var i, j, k, n, len, str, ptr;
var strArray = new Array();
var strTextArray = new Array();
var polyArray = new Array();
var polyArrayString;
var result;
/*
初始化开始
*/
RefreshCRCTextString();//刷新
if(!HotWC3OutputModeStringTest()){
return;
}
if(!TestHotWC3Password(getHotWC3Password())){//取128位密钥
return;
}
RefreshCRCTextString();//刷新
var crcindex = idselecrcnmode.selectedIndex;//当前采用的CRCn内核
var crcnum = (crcindex + 1) << 1;
/*
初始化结束
*/
polyArrayString = "CRC32R_EDB88320_FFFFFFFF_FFFFFFFF";//CRC32
polyArray = polyArrayString.split("_");
wc3outputanalysis.value = "0#0*CRCn简写式(明文HEX,入口明文HEX,出口密文HEX,密文HEX,差分检测HEX)";
wc3input.value = "";
strTextArray.length = 0;
var diffcheck = true;
if(TestIE()) strArray = wc3output.value.split("\r\n");
else strArray = wc3output.value.split("\n");
for(n = 0; n < strArray.length; n++){
str = strArray[n];//取一组密文
len = str.length;
if(str.substr(0, 3) == "==="){//需要CRC32
if(polyArray[2] == str.substr(3, len - 3)){//去掉“===”
result = true;//CRC32正确
}
}
else if(str.substr(0, 3) == "***"){//新密码
//新密文已经写入了。
}
else if(str.substr(0, 3) == "???"){//输出标题
hotwc3titleoutput.value = str.substr(3, str.length - 3);//输出标题
break;//退出
}
else {//密文格式验证
if(idseleoutmode.selectedIndex > 0){
switch(idseleoutmode.selectedIndex)
{
case 1:
case 2:
case 3:
case 4:
str = AsciiToHex(str);
break;
case 5:
str = Base4096ToHex(str);
break;
}
}
ptr = HexToCodeExString(str, idseleoutmode.selectedIndex);
len = ptr.length;//取密文长度
str = '';//清除明文
if((len & 1) == 0){//密文流字符为偶数
for(i = 0; i < len; i += crcnum){
str += GetHotWC3DisPassWorkFunction(crcindex, ptr.substr(i, crcnum), diffcheck);//取密文
}
str = HexToCodeString(str, idselechnmode.selectedIndex);
strTextArray[strTextArray.length] = str;
if(hotwc3CRC32checkbox.checked){//需要CRC32
str = CodeStringToHex(str, idselechnmode.selectedIndex);//把明文转换为HEX
if(str == "") polyArray[2] = GetHotWC3CRCPolyWorkStringEx(polyArrayString, inttohex(n, 8));
else polyArray[2] = GetHotWC3CRCPolyWorkStringEx(polyArrayString, str);
polyArrayString = polyArray.join("_");
}
}
}
}
ChangeidHotWC3outputTextBoxanalysis();
if(strTextArray.length > 0) {//有解密好的明文
if(TestIE()) str = strTextArray.join("\r\n");
else str = strTextArray.join("\n");
wc3input.value = str;
ChangeidinputHotWC3TextBox();
//输出告警
if(hotwc3CRC32checkbox.checked) {
if(result) {
if(confirm("密文成功解密并且CRC32校验正确!!!需要将明文复制到剪切板上吗???")){
wc3inputclipboard();//
}
}
else{
alert("密文成功解密但是CRC32校验错误!!!");
}
}
else {
if(confirm("密文成功解密!!!需要将明文复制到剪切板上吗???")){
wc3inputclipboard();//
}
}
}
//准备写文件
if(hotwc3filecheckbox.checked && (wc3input.value != "") && (wc3fileinput.value)){
filename = wc3fileinput.value.toUpperCase();
len = filename.length;
if(filename.substr(len - 4, 4) == ".WC3"){
alert("文件:\n" + filename +"\n不能是.WC3文件!!!");
}
else{
write = true;
if(FileExists(filename)){
write = confirm("文件:\n" + filename + "\n已存在,覆盖吗?");
}
if(write){
WriteFile(filename, wc3input.value);
alert("文件:\n" + filename +"\n写入成功!!!");
}
}
}
}
function formattext160()
{
var str,ptr,ctr,i,len,val,crcbits, crcdir;
var strarray = new Array();
var patrn = /^[\r0-9]+$/;//正则表达式
str = text160.value.toUpperCase();
if(TestCRCTableArrayPolyArrayString(str)){
text160.value = str;
SetCRCTableArrayPolyFormatString();
WriteCRCTableArrayTextString();
}
else {
alert("CRC简写式输入错误");
text160.value = GetCRCTableArrayPolyFormatString();
}
}
function formattext150()
{
text150.value = text150.value.toUpperCase();//左移CRC12=X12+X11+X3+X2+X+1
if(TestCRCTableArrayPolyTextString(text150.value)){
SetCRCTableArrayPolyTextString();
WriteCRCTableArrayTextString();
}
else{
alert("CRC多项式输入错误!!!");
text150.value = GetCRCTableArrayPolyTextString(text160.value);
discheckbox.checked = text150.value.substr(text150.value.length - 2, 2) == "+1";
}
}
function SetCRCTableArraySelectedchecked(){//选择HotCRC
var objradiobutton = document.getElementsByName("radiobutton");
objradiobutton[objradiobutton.length - 1].checked = true;
}
function selectHotCRC()
{
SetCRCTableArraySelectedchecked();//选择HotCRC
selectStandCRC();
}
function selectStandCRC()
{
str = HotCRCPolyTableArray[GetCRCTableArraySelectedIndex()];
text160.value = str;
SetCRCTableArrayPolyFormatString();
}
function TestCRCTableArrayPolyTextString(str)
{//150
var i, val, bits, dir, len, crcnum, ptr, err, bitval;
var polyh, polyl;
var strArray = new Array();
var patrn10 = /^[0-9]+$/;//正则表达式
err = false;
strArray = str.split("=");
if(strArray.length == 2){
ptr = strArray[0];//CRC12
if(ptr.substr(0, 3) == "CRC"){
bits = ptr.substr(3, ptr.length - 3);
if(patrn10.test(bits)){
bits = parseInt(bits);
if((bits > 0) && ((bits & 3) == 0)){
str = strArray[1];//X12+X11+X3+X2+X+1
strArray = str.split("+");//X12,X11,X3,X2,X,1
bitval = strArray[0].substr(1, strArray[0].length - 1);
if(patrn10.test(bitval)){
bitval = parseInt(bitval);
if(bitval == bits){
for(i = 0;i < strArray.length;i++){
str = strArray[i].substr(0, 1);
if(str == "X"){
val = strArray[i].substr(1, strArray[i].length - 1);
if((val=="") || ((val > "1") && patrn10.test(val))){
val = (val == "") ? 1:parseInt(val);
if(val <= bitval){
bitval = val;
if(i == strArray.length - 1) err = true;
}
else{
return false;
}
}
else{
return false;
}
}
else if(strArray[i] == "1"){
if(i == strArray.length-1) err = true;
}
}
}
}
}
}
}
}
return err;
}
function SetCRCTableArrayPolyTextString()
{//150
var i, val, bits, dir, len, crcnum, str, ptr;
var polyh, polyl;
var strArray = new Array();
var valArray = new Array();
var patrn10 = /^[0-9]+$/;//正则表达式
str = text160.value;//CRC12L_80F_000_000
valArray = str.split("_");
ptr = valArray[0];//CRC12L
dir = (StringRight(ptr, 1) == "R") ? 0:1;
str = text150.value;//CRC12=X12+X11+X3+X2+X+1
strArray = str.split("=");
ptr = strArray[0];//CRC12
bits = parseInt(ptr.substr(3, ptr.length - 3));
crcnum = bits / 4;
str = strArray[1];//X12+X11+X3+X2+X+1
strArray = str.split("+");//X12,X11,X3,X2,X,1
len = strArray.length;
if(strArray[len - 1] == "1"){
strArray[len - 1] = "X0";
if(strArray[len - 2] == "X"){
strArray[len - 2] = "X1";
}
}
else if(strArray[len - 1] == "X"){
strArray[len - 1] = "X1";
}
polyh = 0;
polyl = 0;
for(i = 1;i < len;i++){
val = parseInt(strArray[i].substr(1, strArray[i].length - 1));
if(val < 32){
polyl |= (1 << val);
}
else{
polyh |= (1 << (val - 32));
}
}
str = inttohex(polyh, 8) + inttohex(polyl, 8);
str = str.substr(str.length - crcnum, crcnum);
if(dir == 0) str = StringReversalToString(str);//反转
str = ptr + ((dir == 0) ? "R":"L") + "_" + str;
str += "_" + StringLeft0(valArray[2], crcnum);
str += "_" + StringLeft0(valArray[3], crcnum);
text160.value = str;
SetCRCTableArrayPolyFormatString();
}
function GetCRCTableArrayPolyTextString(str)
{
var ptr, poly, intpoly, strpoly;
var i, bits, dir, len;
var strArray = new Array();
// str = text160.value;
strArray = str.split("_");
ptr = strArray[0];
poly = strArray[1];
strpoly = "";
if(ptr.substr(ptr.length - 1, 1) == "R"){
dir = 0;
}
else{
dir = 1;
}
strpoly += ptr.substr(0, ptr.length - 1) + "=X" + ptr.substr(3, ptr.length - 4);
bits = parseInt(ptr.substr(3, ptr.length - 4));
if(bits <= 32){//bits<=32
if(dir == 1) poly = StringReversalToString(poly);//反转
intpoly = parseInt(poly, 16);
for(i = 0; i < bits; i ++){
if(intpoly & 1){
if(i < bits - 2) strpoly += "+X" + (bits - i - 1).toString(10);
else if(i < bits - 1) strpoly += "+X";
else strpoly += "+1";
}
intpoly >>>= 1;
}
}
else{//bits<=64
if(dir == 1) poly = StringReversalToString(poly);//反转
intpoly = parseInt(poly.substr(poly.length - 8, 8), 16);
for(i = 0;i < 32;i ++){
bits--;
if(intpoly & 1){
strpoly += "+X" + bits.toString(10);
}
intpoly >>>= 1;
}
intpoly = parseInt(poly.substr(0, poly.length - 8), 16);
len = (poly.length - 8) * 4;
for(i = 0;i < len;i ++){
bits--;
if(intpoly & 1){
if(i < (len - 2)) strpoly += "+X" + bits.toString(10);
else if(i < (len - 1)) strpoly += "+X";
else strpoly += "+1";
}
intpoly >>>= 1;
}
}
return strpoly;
}
function GetCRCTableArrayPolyFormatString()
{
var i, bits, len, crcnum, str, ptr, err;
str = "CRC";
bits = (select1.selectedIndex + 1) * 4;
str += parseInt(bits) + ((selemode1.selectedIndex == 0) ? "R":"L");
str += "_" + text130.value;
str += "_" + text120.value;
str += "_" + text170.value;
return str;
}
function SetCRCTableArrayPolyFormatString()
{
select1.selectedIndex = (GetCRCTableArrayBitsInt() >>> 2) - 1;//CRCn
selemode1.selectedIndex = GetCRCTableArrayDirInt();//CRCDir
text150.value = GetCRCTableArrayPolyTextString(text160.value);
discheckbox.checked = text150.value.substr(text150.value.length - 2, 2) == "+1";
text130.value = GetCRCTableArrayPolyString();
text120.value = GetCRCTableArrayInitString();
text170.value = GetCRCTableArrayStopString();
}
function WriteCRCTableArrayTextString()
{
var i;
var str, ptr;
var objradiobutton = document.getElementsByName("radiobutton");
str = text160.value;
for(i = 32;i < HotCRCPolyTableArray.length;i++){
if(str == HotCRCPolyTableArray[i]){
objradiobutton[i - 32].checked = true;
return;
}
}
SetCRCTableArraySelectedchecked();//选择HotCRC
i = (select1.selectedIndex << 1) + selemode1.selectedIndex;
HotCRCPolyTableArray[i] = str;
}
function TestCRCTableArrayPolyArrayString(str)
{
var i, bits, len, crcnum, str, ptr, err;
var strArray = new Array();
var patrn10 = /^[0-9]+$/;//正则表达式
var patrn = /^[0-9a-fA-F]+$/;//正则表达式
strArray = str.split("_");
ptr = strArray[0];
len = ptr.length;
err = false;
if((strArray.length == 4) && (ptr.substr(0, 3) == "CRC")){
if((ptr.substr(len - 1, 1) == "R") || (ptr.substr(len - 1, 1) == "L")){
ptr = ptr.substr(3, len - 4);
if(patrn10.test(ptr)){
bits = parseInt(ptr);
crcnum = bits / 4;
if(patrn.test(strArray[1]) && patrn.test(strArray[2]) && patrn.test(strArray[3])){
if((strArray[1].length == crcnum) && (strArray[2].length == crcnum) && (strArray[3].length == crcnum)){
err = true;
}
}
}
}
}
return err;
}
function TestCRCTableArrayPolyArray()
{
var i, bits, len, crcnum, str, ptr, err;
var strArray = new Array();
var patrn10 = /^[0-9]+$/;//正则表达式
var patrn = /^[0-9a-fA-F]+$/;//正则表达式
idTextBox.value = "";
for(i = 0; i < 32; i++) {
str = HotCRCPolyTableArray[i];
HotCRCPolyTableArray[i] = str.toUpperCase();
strArray = str.split("_");
ptr = strArray[0];
len = ptr.length;
err = true;
if((strArray.length == 4) && (ptr.substr(0, 3) == "CRC")){
if(((ptr.substr(len - 1, 1) == "R") && ((i & 1) == 0)) || ((ptr.substr(len - 1, 1) == "L") && ((i & 1) == 1))){
ptr = ptr.substr(3, len - 4);
if(patrn10.test(ptr)){
bits = parseInt(ptr);
crcnum = bits / 4;
if(patrn.test(strArray[1]) && patrn.test(strArray[2]) && patrn.test(strArray[3])){
if((strArray[1].length == crcnum) && (strArray[2].length == crcnum) && (strArray[3].length == crcnum)){
err = false;
}
}
}
}
}
if(err) {
if(idTextBox.value == "") idTextBox.value = "HotCRCPolyTableArray[0x" + inttohex(i, 2) + "] = " + HotCRCPolyTableArray[i] + ";错误的简写式";
else idTextBox.value += "\nHotCRCPolyTableArray[0x" + inttohex(i, 2) + "] = " + HotCRCPolyTableArray[i] + ";错误的简写式";
}
}
for(i = 32; i < HotCRCPolyTableArray.length; i++) {
str = HotCRCPolyTableArray[i];
HotCRCPolyTableArray[i] = str.toUpperCase();
strArray = str.split("_");
ptr = strArray[0];
len = ptr.length;
err = true;
if((strArray.length == 4) && (ptr.substr(0, 3) == "CRC")){
if((ptr.substr(len - 1, 1) == "R") || (ptr.substr(len - 1, 1) == "L")){
ptr = ptr.substr(3, len - 4);
if(patrn10.test(ptr)){
bits = parseInt(ptr);
crcnum = bits / 4;
if(patrn.test(strArray[1]) && patrn.test(strArray[2]) && patrn.test(strArray[3])){
if((strArray[1].length == crcnum) && (strArray[2].length == crcnum) && (strArray[3].length == crcnum)){
err = false;
}
}
}
}
}
if(err) {
if(idTextBox.value == "") idTextBox.value = "HotCRCPolyTableArray[" + i + "] = " + HotCRCPolyTableArray[i] + ";错误的简写式";
else idTextBox.value += "\nHotCRCPolyTableArray[" + i + "] = " + HotCRCPolyTableArray[i] + ";错误的简写式";
}
}
if(idTextBox.value != "") ChangeidTextBox();
return idTextBox.value == "";
}
function SetCRCTableArraySelectedDir(crcdir)
{
var str;
var strArray = new Array();
selemode1.selectedIndex = crcdir;
str = text160.value;
strArray = str.split("_");
str = strArray[0];
str = str.substr(0, str.length - 1) + ((crcdir == 0) ? "R":"L");
strArray[0] = str;
text160.value = strArray.join("_");
text150.value = GetCRCTableArrayPolyTextString(text160.value);
discheckbox.checked = text150.value.substr(text150.value.length - 2, 2) == "+1";
WriteCRCTableArrayTextString();
return;
}
function SetCRCTableArraySelectedBits(crcbits)
{
var str;
var strArray = new Array();
select1.selectedIndex = (crcbits >>> 2) - 1;
str = text160.value;
strArray = str.split("_");
str = strArray[0];
str = "CRC" + parseInt(crcbits) + str.substr(str.length - 1, 1);
strArray[0] = str;
text160.value = strArray.join("_");
text150.value = GetCRCTableArrayPolyTextString(text160.value);
discheckbox.checked = text150.value.substr(text150.value.length - 2, 2) == "+1";
WriteCRCTableArrayTextString();
return;
}
function SetCRCTableArraySelectedIndex(crcbits, crcdir)
{
var str;
var strArray = new Array();
select1.selectedIndex = (crcbits >>> 2) - 1;
selemode1.selectedIndex = crcdir;
str = text160.value;
strArray = str.split("_");
strArray[0] = "CRC" + crcbits + ((crcdir == 0) ? "R":"L");
text160.value = strArray.join("_");
text150.value = GetCRCTableArrayPolyTextString(text160.value);
discheckbox.checked = text150.value.substr(text150.value.length - 2, 2) == "+1";
return;
}
function GetCRCTableArraySelectedIndex()
{
var objradiobutton = document.getElementsByName("radiobutton");
var i;
for (i = 0; i < objradiobutton.length; i ++)
{
if (objradiobutton[i].checked)
{
if (i < (objradiobutton.length - 1)){//标准CRC[>32]
i += 32;
}
else{//自定义[<=32]
i = (select1.selectedIndex << 1) + selemode1.selectedIndex;
}
break;
}
}
return i;
}
function GetCRCTableArrayPolyString()
{
var str;
var strArray = new Array();
str = text160.value;
strArray = str.split("_");
str = strArray[1];
return str;
}
function SetCRCTableArrayPolyString(strcrcpoly)
{
var str;
var strArray = new Array();
text130.value = strcrcpoly;
str = text160.value;
strArray = str.split("_");
strArray[1] = strcrcpoly;
text160.value = strArray.join("_");
text150.value = GetCRCTableArrayPolyTextString(text160.value);
discheckbox.checked = text150.value.substr(text150.value.length - 2, 2) == "+1";
return;
}
function GetCRCTableArrayInitString()
{
var str;
var strArray = new Array();
str = text160.value;
strArray = str.split("_");
return strArray[2];
}
function SetCRCTableArrayInitString(strcrcinit)
{
var str;
var strArray = new Array();
text120.value = strcrcinit;
str = text160.value;
strArray = str.split("_");
strArray[2] = strcrcinit;
text160.value = strArray.join("_");
return;
}
function GetCRCTableArrayStopString()
{
var str;
var strArray = new Array();
str = text160.value;
strArray = str.split("_");
return strArray[3];
}
function SetCRCTableArrayStopString(strcrstop)
{
var str;
var strArray = new Array();
text170.value = strcrstop;
str = text160.value;
strArray = str.split("_");
strArray[3] = strcrstop;
text160.value = strArray.join("_");
return;
}
function GetCRCTableArrayDirInt()
{
var str, crcdir;
var strArray = new Array();
str = text160.value;
strArray = str.split("_");
str = strArray[0];
crcdir = (str.substr(str.length - 1, 1) == "R") ? 0 : 1;
return crcdir;
}
function GetCRCTableArrayBitsInt()
{
var str, crcbits;
var strArray = new Array();
str = text160.value;
strArray = str.split("_");
str = strArray[0];
crcbits = parseInt(str.substr(3, str.length - 4));
return crcbits;
}
function WebOnlineHELPTextCompressor()
{
var str, strText;
var i, j;
var strArray = new Array();
var varArray = new Array();
str = webinputconversion.value;
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
if(strArray.length > 0){
strText = "";
for(i = 0; i < strArray.length; i ++){
str = strArray[i];
varArray = str.split("\"");//搜索
j = varArray.length;
for(j = 0; j < varArray.length; j ++){
if(j == 0) strText += " str += \"" + varArray[j];
else strText += "\\\"" + varArray[j];
}
if(i < strArray.length - 1) strText += "\\n\";\n";
else strText += "\";\n";
}
weboutputconversion.value = strText;
Changeidweboutputconversion();
if(confirm("网页帮助以转换成功!!!需要将其复制到剪切板上吗???")){
weboutputclipboard();//
}
}
}
function WebOnlineHELPTextRestore()
{
var str, ptr, strText;
var i, j;
var strArray = new Array();
var varArray = new Array();
str = weboutputconversion.value;
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
if(strArray.length > 0){
strText = "";
for(i = 0; i < strArray.length; i ++){
str = strArray[i];
if((str.length > 12) && (str.substr(0, 10) == " str += \"")) {
varArray = str.split("\"");//搜索
varArray[0] = "";
for(j = 1; j < varArray.length - 1; j ++){
if(varArray[j].substr(varArray[j].length - 1, 1) == "\\") {
varArray[j] = varArray[j].substr(0, varArray[j].length - 1);
}
}
varArray[varArray.length - 1] = "";
ptr = varArray.join("\"");
ptr = ptr.substr(1, ptr.length - 2);
if(ptr.substr(ptr.length - 2, 2) == "\\n") {
ptr = ptr.substr(0, ptr.length - 2) + "\n";
}
strText += ptr;
}
}
if(strText != ""){//转换成功
webinputconversion.value = strText;
Changeidwebinputconversion();
if(confirm("网页帮助逆向成功!!!需要将其复制到剪切板上吗???")){
webinputclipboard();//
}
}
else{
alert("文本转换失败!!!");
}
}
}
function GetHexFormatString(hexstr, crcnum)
{
var val, str, ptr;
var valArray = new Array();
str = hexstr;
valArray = str.split("0x");
if(valArray.length != 2){
valArray = str.split("0X");
if(valArray.length != 2){
str = HexStringFormat(str);
if(str == "") str = "0";
val = parseInt(str);//10进制数
str = inttohex(val, crcnum);//转换为16进制数
return str;
}
}
str = valArray[1];//取16进制数
str = HexStringFormat(str);//去掉空格
val = str.length;//实际长度
if(val >= crcnum){
str = str.substr(val - crcnum, crcnum);
return str;
}
ptr = "";
while(val < crcnum) {
ptr += "0";
val++;
}
str = ptr + str;
return str;
}
function InputCRCTableArrayText(selemode)
{
var str, strh, strl, ptr, ctr, polystr, polybak, polyText, strText;
var crcbits, crcnum, crcnumh, crcnuml;
var crcdir, crcsize;
var crcpoly, crcstr;
var i, j, k, n, len, value;
var strArray = new Array();
var strArrayh = new Array();
var strArrayl = new Array();
var valArray = new Array();
var tabArray = new Array();
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
crcsize = (selemode & 1) ? 16:256;
if(selemode > 1){
switch(crcbits)
{
case 16:
crcnumh = 2;//crcnumh=2! char,char
crcnuml = 2;//char
break;
case 24://crcnumh=2! char,short
case 32://crcnumh=4! short,short
crcnumh = crcnum - 4;
crcnuml = 4;//short
break;
case 40://crcnumh=2! char,long
case 48://crcnumh=4! short,long
case 64://crcnumh=8! long,long
crcnumh = crcnum - 8;
crcnuml = 8;//long
break;
default:
alert("您选中的CRC" + crcbits + "目前版本不支持双表!!!");
return;
}
}
selemode >>>= 1;//0单表,1双表
str = idTextBox.value;
valArray = str.split("{");//分离表格
k = 0;
tabArray.length = 0;
for(i = 1;i < valArray.length;i++){
str = valArray[i];
strArray = str.split("}");
if(strArray.length >= 2){
str = strArray[0];
strArray = str.split(",");//分离出0x1234,…
len = strArray.length;
if((crcsize == len) || (crcsize == (len - 1))){
tabArray.length++;
tabArray[k] = str;//存入表格
k ++;
}
}
}
if(k == 0){//没有发现表格
alert("没有发现表格!");
return;
}
if(selemode && (k < 2)){
str = "";
for(i = 0;i < crcsize;i ++) str += "0,";
}
tabArray.length++;
tabArray[k] = str;//存入表格
str = idTextBox.value;
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
for(i = 0;i < strArray.length;i ++){
str = strArray[i];
if(str.indexOf("**CRC表格成功!!!") >= 0){
strArray.length = i;
break;
}
}
if(TestIE()) str = strArray.join("\r\n");
else str = strArray.join("\n");
idTextBox.value = str;
polybak = text160.value;
polystr = "";
ptr = "";
ctr = "";
for(n = 0;n <= selemode;n++){
if(selemode == 0)
{//单表
str = tabArray[0];
strArray = str.split(",");//分离出0x1234,…
}
else{//双表
str = tabArray[0];
strArrayh = str.split(",");//分离出0x1234,…
str = tabArray[1];
strArrayl = str.split(",");//分离出0x1234,…
}
for(crcdir = 0;crcdir < 2;crcdir++){//先假设右移
if(crcdir){//左移
i = 0x01;
}
else{//右移
if(crcsize == 16) i =0x08;//小表
else i = 0x80;//大表
}
if(selemode == 0)
{
str = GetHexFormatString(strArray[i], crcnum);
if(str == ""){
alert("单表表格[0x" + inttohex(i, 2) + "]不是16进制数,没有发现0x!");
return;
}
}
else{
strh = GetHexFormatString(strArrayh[i], crcnumh);
if(strh == ""){
alert("双表高位表格[0x" + inttohex(i, 2) + "]不是16进制数,没有发现0x!");
return;
}
strl = GetHexFormatString(strArrayl[i], crcnuml);
if(strl == ""){
alert("双表低位表格[0x" + inttohex(i, 2) + "]不是16进制数,没有发现0x!");
return;
}
str = strh + strl;
}
crcpoly = str;//假定一个权值
len = 0;//计数
SetCRCTableArrayPolyString(crcpoly);
SetCRCTableArraySelectedDir(crcdir);
polyText = text160.value;
valArray = polyText.split("_");
valArray.length -= 2;//不要初值和出值
polyText = valArray.join("_");
for(i = 0;i < crcsize;i++){//小表16大表256
if(selemode == 0)
{
str = GetHexFormatString(strArray[i], crcnum);
if(str == ""){
alert(polyText + "[0x" + inttohex(i, 2) + "]不是16进制数,没有发现0x!");
return;
}
str = StringHexToString(str, crcnum);
}
else{
strh = GetHexFormatString(strArrayh[i], crcnumh);
if(strh == ""){
alert(polyText + "[0x" + inttohex(i, 2) + "]不是16进制数,没有发现0x!");
return;
}
strl = GetHexFormatString(strArrayl[i], crcnuml);
if(strl == ""){
alert(polyText + "[0x" + inttohex(i, 2) + "]不是16进制数,没有发现0x!");
return;
}
str = strh + strl;
}
if(crcdir || (crcsize == 256)) value = i;
else value = i << 4;
value = inttohex(value, crcnum);
crcstr = GetHotWC3CRCPolyWorkValue(value, inttohex(0, crcnum), crcpoly, inttohex(0, crcnum), crcdir, crcbits, 0);//CRC4~64
if(str == crcstr){//表格位置处数据正确
len++;//计数
}
else{//出错!
if((i == 0) && (str != inttohex(0, crcnum))){
alert("表格数组[0]处数据非0,它不是CRC表格格式!");
return;
}
if(selemode == 0)
{//单表
ctr += "\n" + polyText + "[0x" + inttohex(i, 2) + "]:错误 =" + strArray[i] + ",正确 = 0x" + crcstr;
}
else{//双表
if(strh != crcstr.substr(0, crcnumh)){
ctr += "\n" + polyText + "_Hi[0x" + inttohex(i, 2) + "]:错误 =" + strArrayh[i] + ",正确 = 0x" + crcstr.substr(0, crcnumh);
}
if(strl != crcstr.substr(crcnumh, crcnuml)){
ctr += "\n" + polyText + "_Lo[0x" + inttohex(i, 2) + "]:错误 =" + strArrayl[i] + ",正确 = 0x" + crcstr.substr(crcnumh, crcnuml);
}
}
if(discheckbox.checked) {
ctr += " CRC可逆";
}
else{
ctr += " CRC不可逆";
}
}
}//for(i)
if(len == crcsize){//全部正确
if(ptr != "") ptr += "\n";
str = text160.value;
varArray = str.split("_");
varArray[2] = inttohex(0, crcnum);
varArray[3] = inttohex(0, crcnum);
str = varArray.join("_");
ptr += str;
idTextBox.value += "\n**CRC表格成功!!!";
idTextBox.value += "\n" + str;
if(discheckbox.checked) {
idTextBox.value += " CRC可逆";
polystr = str;
}
else{
idTextBox.value += " CRC不可逆";
}
break;
}
else{
valArray = ctr.split("\n");
if(valArray.length <= 16){//出错次数
idTextBox.value += ctr;
}
}
ctr = "";
}//for(dir)
if((selemode == 0) || (k == 2)){
break;
}
if(k < 2){
str = tabArray[0];
tabArray[0] = tabArray[1];
tabArray[1] = str;
}
}//for(n)
if(ptr != ""){//成功
valArray = ptr.split("\n");
if(polystr == "") polystr = valArray[0];
text160.value = polystr;
formattext160();
str = "**CRC表格成功!!!";
if(valArray.length > 1){
if(crcsize == 16){
str += "\n发生CRC表格小表碰撞!!!";
}
else{
str += "\n发生CRC表格大表碰撞!!!";
}
}
ChangeidTextBox();
alert(str);
}
else{
text160.value = polybak;
formattext160();
alert("**CRC表格失败!!!");
ChangeidTextBox();
}
}//function
function OutputCRCTableArrayText(selemode)
{
var str, strText;
var crcbits, crcnum, crcnumh, crcnuml;
var crcdir, crcsize;
var i, j, k, len, value;
var strArray = new Array();
crcbits = GetCRCTableArrayBitsInt();
crcdir = GetCRCTableArrayDirInt();
crcnum = crcbits / 4;
crcsize = (selemode & 1) ? 16:256;
if(selemode > 1){
switch(crcbits)
{
case 16:
crcnumh = 2;//crcnumh=2! char,char
crcnuml = 2;//char
break;
case 24://crcnumh=2! char,short
case 32://crcnumh=4! short,short
crcnumh = crcnum - 4;
crcnuml = 4;//short
break;
case 40://crcnumh=2! char,long
case 48://crcnumh=4! short,long
case 64://crcnumh=8! long,long
crcnumh = crcnum - 8;
crcnuml = 8;//long
break;
default:
alert("您选中的CRC" + crcbits + "目前版本不支持双表!!!");
return;
}
strText = "{\n";
if(crcnumh <= 4) k = 16;
else k = 8;
len = 0;
for(i = 0;i < (crcsize / k);i ++){
strText += " ";
for(j = 0;j < k;j ++){
if((crcdir == 0) && (crcsize == 16)) value = len << 4;
else value = len;
value = inttohex(value, crcnum);
str = GetHotWC3CRCPolyWorkValue(value, inttohex(0, crcnum), text130.value, inttohex(0, crcnum), crcdir, crcbits, 0);//CRC4~64
len++;
strText += " 0x" + str.substr(0, crcnumh);
if(len < crcsize) strText += ",";
}
if(crcsize == 256){
strText += "\n";
}
else if(len == 16){
strText += "\n";
break;
}
}
strText += "};\n\n";
strText += "{\n";
if(crcnuml <= 4) k = 16;
else k = 8;
len = 0;
for(i = 0;i < (crcsize / k);i ++){
strText += " ";
for(j = 0;j < k;j ++){
if((crcdir == 0) && (crcsize == 16)) value = len << 4;
else value = len;
value = inttohex(value, crcnum);
str = GetHotWC3CRCPolyWorkValue(value, inttohex(0, crcnum), text130.value, inttohex(0, crcnum), crcdir, crcbits, 0);//CRC4~64
len++;
strText += " 0x" + str.substr(crcnumh, crcnuml);
if(len < crcsize) strText += ",";
}
if(crcsize == 256){
strText += "\n";
}
else if(len == 16){
strText += "\n";
break;
}
}
strText += "};\n";
}
else{
strText = "{\n";
if(crcbits <= 16) k = 16;
else k = 8;
len = 0;
for(i = 0;i < (crcsize / k);i ++){
strText += " ";
for(j = 0;j < k;j ++){
if((crcdir == 0) && (crcsize == 16)) value = len << 4;
else value = len;
value = inttohex(value, crcnum);
str = GetHotWC3CRCPolyWorkValue(value, inttohex(0, crcnum), text130.value, inttohex(0, crcnum), crcdir, crcbits, 0);//CRC4~64
len++;
strText += " 0x" + str;
if(len < crcsize) strText += ",";
}
if(crcsize == 256){
strText += "\n";
}
else if(len == 16){
strText += "\n";
break;
}
}
strText += "};\n";
}
idTextBox.value = strText;
ChangeidTextBox();
}
function GetCRCBitsPosionString(crcbits)
{
var str = "";
switch(crcbits){
case 12://3
str = "\\x00\\x02\\x01\\x03\\x05\\x04";
break;
case 20://5
str = "\\x00\\x02\\x01\\x04\\x03\\x05\\x07\\x06\\x09\\x08";
break;
case 28://7
str = "\\x00\\x02\\x01\\x04\\x03\\x06\\x05\\x07\\x09\\x08\\x0B\\x0A\\x0D\\x0C";
break;
case 36://9
str = "\\x00\\x02\\x01\\x04\\x03\\x06\\x05\\x08\\x07\\x09\\x0B\\x0A\\x0D\\x0C\\x0F\\x0E\\x11\\x10";
break;
case 44://b,11
str = "\\x00\\x02\\x01\\x04\\x03\\x06\\x05\\x08\\x07\\x0A\\x09\\x0B\\x0D\\x0C\\x0F\\x0E\\x11\\x10\\x13\\x12\\x15\\x14";
break;
case 52://d,13
str = "\\x00\\x02\\x01\\x04\\x03\\x06\\x05\\x08\\x07\\x0A\\x09\\x0C\\x0B\\x0D\\x0F\\x0E\\x11\\x10\\x13\\x12\\x15\\x14\\x17\\x16\\x19\\x18";
break;
case 60://f,15
str = "\\x00\\x02\\x01\\x04\\x03\\x06\\x05\\x08\\x07\\x0A\\x09\\x0C\\x0B\\x0E\\x0D\\x0F\\x11\\x10\\x13\\x12\\x15\\x14\\x17\\x16\\x19\\x18\\x1B\\x1A\\x1D\\x1C";
break;
}
return str;
}
function GetCRCBitsFunction(crcvalue, BitSize, sim)
{
var i, m, j, k;
var crc;
var crcTemp, posTemp;
var crcTableArrayName;
var crcTableArray = new Array();
var strArray = new Array();
var valArray = new Array();
var crcBuff, crcpoly;
var str, ptr, len, val;
var simstr;
var posTable = new Array();
var tabArray = new Array(2);
var crcbits, crcdir, crcnum, crcsize;
tabArray[0] = "0000000000000000";
tabArray[1] = "FFFFFFFFFFFFFFFF";
crcbits = GetCRCTableArrayBitsInt();
crcdir = GetCRCTableArrayDirInt();
crcnum = crcbits / 4;
tabArray[0] = tabArray[0].substr(0, crcnum);
tabArray[1] = tabArray[1].substr(0, crcnum);
crcBuff = CodeStringToHex(text12.value, idselecodemode.selectedIndex);
len = crcBuff.length;
crc = text120.value;//取初值
crcpoly = text130.value;
simstr = "/*";
simstr += "\r\n移位函数:\r\nGet" + text160.value + "(unsigned char *crcBuff, unsigned int crcLen);";
simstr += "\r\n待校验数据区:\r\ncrcBuff[] = {//移位函数内部运算需要的Hex编码";
k = 0;
str = "";
for(i = 0;i < len;i+=2){
if((k % 16) == 0) {
if(k) str += ",";
str += "\r\n ";
}
else str += ", ";
str += "0x" + crcBuff.substr(i, 2);
k++;
}
simstr += str;
simstr += "\r\n}";
if(BitSize == 4){//小表
simstr += "\r\n移位循环次数:\r\n(2 * crcLen) * 4 = " + (len * 4) + "次\r\n";
j = 0;
k = 0;
crcBuff += inttohex(0, crcnum - (len % crcnum));//补0
for(i = 0;i < len; i++){
simstr += "\r\ni = " + i + "; crc = 0x" + crc + ((i == 0)? "(初值)":"") + ";";
if(crcbits == 4){
crcTemp = crcBuff.substr(i, 1);//半字节
if(!(i & 1)){
simstr += "\r\n crcTemp = crcBuff[" + parseInt(i >>> 1) + "] >> 4 = 0x" + crcTemp + ";";
}
else{
simstr += "\r\n crcTemp = crcBuff[" + parseInt(i >>> 1) + "] & 0xf = 0x" + crcTemp + ";";
}
}
else{
simstr += " j = " + j + "; k = " + k + ";";
str = GetCRCBitsPosionString(crcbits);
posTable = str.split("\\x");//得到位置表
posTemp = hextoint(posTable[j + 1]);
simstr += "\r\n posTemp = posTable[j] = posTable[" + j + "] = " + posTemp + ";";
crcTemp = crcBuff.substr(k + posTemp, 1);//半字节
val = (k + posTemp) >>> 1;
simstr += "\r\n (k + posTemp) >> 1 = (" + k + " + " + posTemp + ") >> 1 = " + (k + posTemp) + " >> 1 = " + val + ";";
if(!(posTemp & 1)){
simstr += "\r\n crcTemp = crcBuff[" + val + "] >> 4 = 0x" + crcTemp + ";";
}
else{
simstr += "\r\n crcTemp = crcBuff[" + val + "] & 0xf = 0x" + crcTemp + ";";
}
if((k + posTemp) > len - 1){//溢出!
simstr += "//数组溢出!最后半个字节没有参与运算!!!";
}
val = crcnum << 1;
if(j < val - 1) j++;
else{
j = 0;
k += val;
}
}
for(n = 0;n < 4;n++){
simstr += "\r\n n = " + n + ", crc = 0x" + crc + ", crcTemp = 0x" + crcTemp + ";";
if(crcdir){//小表左移CRC4
simstr += "\r\n (crcTemp ^ crc) & 0x8 = (0x" + crcTemp + " ^ 0x" + crc + ") & 0x8 = 0x";
val = StringXORToString(crcTemp, crc);
simstr += val + " & 0x8 = 0x";
val = StringANDToString(val, "8");
simstr += val + ";";
crc = StringLMToString(crc, 1);
if(val != "0"){
crc = StringXORToString(crc, crcpoly);
}
crcTemp = StringLMToString(crcTemp, 1);
simstr += "\r\n crc = 0x" + crc + ", crcTemp = 0x" + crcTemp + ";";
}
else{//小表右移
if(crcbits == 4){
simstr += "\r\n (crcTemp ^ crc) & 0x1 = (0x" + crcTemp + " ^ 0x" + crc + ") & 0x1 = 0x";
val = StringXORToString(crcTemp, crc);
simstr += val + " & 0x1 = 0x";
val = StringANDToString(val, "1");
simstr += val + ";";
crc = StringRMToString(crc, 1);
if(val != "0"){
crc = StringXORToString(crc, crcpoly);
}
crcTemp = StringRMToString(crcTemp, 1);
simstr += "\r\n crc = 0x" + crc + ", crcTemp = 0x" + crcTemp + ";";
}
else{
simstr += "\r\n (crcTemp ^ crc) & 0x01 = (0x" + crcTemp + " ^ 0x" + crc + ") & 0x01 = 0x";
val = StringXORToString(crcTemp, crc.substr(crcnum - 1, 1));
simstr += val + " & 0x1 = 0x";
val = StringANDToString(val, "1");
simstr += val + ";";
crc = StringRMToString(crc, 1);
if(val != "0"){
crc = StringXORToString(crc, crcpoly);
}
crcTemp = StringRMToString(crcTemp, 1);
simstr += "\r\n crc = 0x" + crc + ", crcTemp = 0x" + crcTemp + ";";
}
}
}
}
}
else{//大表
simstr += "\r\n移位循环次数:\r\ncrcLen * 8 = " + (len * 4) + "次\r\n";
for(i = 0;i < len;i+=2){
simstr += "\r\ni = " + parseInt(i >>> 1) + "; crc = 0x" + crc + ((i == 0)? "(初值)":"") + ";";
crcTemp = crcBuff.substr(i, 2);
simstr += "\r\n crcTemp = crcBuff[" + parseInt(i >>> 1) + "] = 0x" + crcTemp + ";";
for(n = 0;n < 8;n++){
simstr += "\r\n n = " + n + ", crc = 0x" + crc + ", crcTemp = 0x" + crcTemp + ";";
if(crcdir){//大表左移
val = StringRMToString(crc, crcbits - 8);
simstr += "\r\n crc >> " + (crcbits - 8) + " = 0x" + crc + " >> " + (crcbits - 8) + " = 0x" + val + ";";
simstr += "\r\n (0x" + crcTemp + " ^ 0x" + val + ") & 0x80 = 0x";
val = StringXORToString(crcTemp, crc.substr(0, 2));
simstr += val + " & 0x80 = 0x";
val = StringANDToString(val, "80");
simstr += val + ";";
crc = StringLMToString(crc, 1);
if(val != "00"){
crc = StringXORToString(crc, crcpoly);
}
crcTemp = StringLMToString(crcTemp, 1);
simstr += "\r\n crc = 0x" + crc + ", crcTemp = 0x" + crcTemp + ";";
}
else{//大表右移
simstr += "\r\n (0x" + crcTemp + " ^ 0x" + crc + ") & 0x01 = 0x";
val = StringXORToString(crcTemp, crc.substr(crcnum - 2, 2));
simstr += val + " & 0x01 = 0x";
val = StringANDToString(val, "01");
simstr += val + ";";
crc = StringRMToString(crc, 1);
if(val != "00"){
crc = StringXORToString(crc, crcpoly);
}
crcTemp = StringRMToString(crcTemp, 1);
simstr += "\r\n crc = 0x" + crc + ", crcTemp = 0x" + crcTemp + ";";
}
}
}
}
simstr += "\r\n移位函数最终结果(HotWC3的crc = 0x" + crcvalue + "):\r\n crc = crc ^ 出值= 0x" + crc + " ^ 0x" + text170.value;
crc = StringXORToString(crc, text170.value);//出值,得到结果
simstr += " = 0x" + crc + ";\r\n*/\r\n";
return (sim) ? simstr: crc;
}
function GetCRCTableArrayFunction(crcvalue, BitSize, sim)
{
var i, j, k;
var crc;
var crcTemp, posTemp;
var crcTableArrayName;
var crcTableArray = new Array();
var strArray = new Array();
var valArray = new Array();
var crcBuff, crcpoly;
var str, ptr, len, val;
var simstr;
var posTable = new Array();
var tabArray = new Array(2);
var crcbits, crcdir, crcnum, crcsize;
tabArray[0] = "0000000000000000";
tabArray[1] = "FFFFFFFFFFFFFFFF";
crcbits = GetCRCTableArrayBitsInt();
crcdir = GetCRCTableArrayDirInt();
crcnum = crcbits / 4;
tabArray[0] = tabArray[0].substr(0, crcnum);
tabArray[1] = tabArray[1].substr(0, crcnum);
crcsize = (BitSize == 4) ? 16:256;
crcBuff = CodeStringToHex(text12.value, idselecodemode.selectedIndex);
len = crcBuff.length;
crc = text120.value;//取初值
crcpoly = text130.value;
crcTableArrayName = text160.value;
valArray = crcTableArrayName.split("_");
valArray[2] = "Table";
valArray.length --;
crcTableArrayName = valArray.join("_");
simstr = "/*";
simstr += "\r\n表格函数:\r\nGet" + text160.value + "_Table(unsigned char *crcBuff, unsigned int crcLen);";
simstr += "\r\n待校验数据区:\r\ncrcBuff[] = {//表格函数内部运算需要的Hex编码";
k = 0;
str = "";
for(i = 0;i < len;i+=2){
if((k % 16) == 0) {
if(k) str += ",";
str += "\r\n ";
}
else str += ", ";
str += "0x" + crcBuff.substr(i, 2);
k++;
}
simstr += str;
simstr += "\r\n}";
if(crcsize == 16){//小表
simstr += "\r\n小表循环次数:\r\ncrcLen * 2 = " + len + "次\r\n";
}
else{
simstr += "\r\n大表循环次数:\r\ncrcLen = " + (len / 2) + "次\r\n";
}
if(crcsize == 16){//小表
for(i = 0;i < crcsize;i++){
if(crcdir || (crcbits == 4)){//左移
val = i;
}
else{//右移
val = (i << 4);
}
val = inttohex(val, crcnum);
str = GetHotWC3CRCPolyWorkValue(val, tabArray[0], crcpoly, tabArray[0], crcdir, crcbits, 0);//CRC4~64
crcTableArray.length ++;
crcTableArray[i] = str;
}
j = 0;
k = 0;
crcBuff += inttohex(0, crcnum - (len % crcnum));//补0
for(i = 0;i < len;i++){
simstr += "\r\ni = " + i + "; crc = 0x" + crc + ((i == 0)? "(初值)":"") + ";";
if(crcdir){//小表左移
crcTemp = crcBuff.substr(i, 1);//半字节
if(!(i & 1)){
simstr += "\r\n crcTemp = crcBuff[i >> 1] >> 4 = crcBuff[" + parseInt(i >>> 1) + "] >> 4 = 0x" + crcTemp + ";";
}
else{
simstr += "\r\n crcTemp = crcBuff[i >> 1] & 0xf = crcBuff[" + parseInt(i >>> 1) + "] & 0xf = 0x" + crcTemp + ";";
}
if(crcbits == 4){
val = StringXORToString(crc, crcTemp);
simstr += "\r\n crc ^ crcTemp = 0x" + crc + " ^ 0x" + crcTemp + " = 0x"+ val + ";";
crc = crcTableArray[hextoint(val)];
simstr += "\r\n crc = " + crcTableArrayName + "[0x" + val + "] = 0x" + crc + ";";
}
else{
val = StringRMToString(crc, crcbits - 4);//>>bits-4
val = val.substr(val.length - 1, 1);
simstr += "\r\n (crc >> " + parseInt(crcbits - 4) + ") ^ crcTemp = (0x" + crc + " >> " + parseInt(crcbits - 4) + ") ^ 0x" + crcTemp + " = 0x" + val + " ^ 0x" + crcTemp;
val = StringXORToString(val, crcTemp);
simstr += " = 0x" + val + ";";
simstr += "\r\n " + crcTableArrayName + "[0x" + val + "] = 0x";
val = crcTableArray[hextoint(val)];//CRC8L_31_Table[(crc >> 4) ^ crcTemp]
simstr += val + ";";
simstr += "\r\n crc = (crc << 4) ^ 0x" + val + " = (0x" + crc + " << 4) ^ 0x" + val;
crc = StringLMToString(crc, 4);//(crc << 4)
simstr += " = 0x" + crc + " ^ 0x" + val;
crc = StringXORToString(crc, val);
simstr += " = 0x" + crc + ";";
}
simstr += "\r\n crc = 0x" + crc + " & 0x" + tabArray[1];
crc = StringANDToString(crc, tabArray[1]);//crc&=0xffff
simstr += " = 0x" + crc + ";";
}
else{//小表右移
if(crcbits == 4){
crcTemp = crcBuff.substr(i, 1);//半字节
if(!(i & 1)){
simstr += "\r\n crcTemp = crcBuff[i >> 1] >> 4 = crcBuff[" + parseInt(i >>> 1) + "] >> 4 = 0x" + crcTemp + ";";
}
else{
simstr += "\r\n crcTemp = crcBuff[i >> 1] & 0xf = crcBuff[" + parseInt(i >>> 1) + "] & 0xf = 0x" + crcTemp + ";";
}
val = StringXORToString(crc, crcTemp);
simstr += "\r\n crc ^ crcTemp = 0x" + crc + " ^ 0x" + crcTemp + " = 0x"+ val + ";";
crc = crcTableArray[hextoint(val)];
simstr += "\r\n crc = " + crcTableArrayName + "[0x" + val + "] = 0x" + crc + ";";
}
else{
if(crcnum & 1){//半字节
simstr += " j = " + j + "; k = " + k + ";";
str = GetCRCBitsPosionString(crcbits);
posTable = str.split("\\x");//得到位置表
posTemp = hextoint(posTable[j + 1]);
simstr += "\r\n posTemp = posTable[j] = posTable[" + j + "] = " + posTemp + ";";
crcTemp = crcBuff.substr(k + posTemp, 1);//半字节
val = (k + posTemp) >>> 1;
simstr += "\r\n (k + posTemp) >> 1 = (" + k + " + " + posTemp + ") >> 1 = " + (k + posTemp) + " >> 1 = " + val + ";";
if(!(posTemp & 1)){
simstr += "\r\n crcTemp = crcBuff[(k + posTemp) >> 1] >> 4 = crcBuff[" + val + "] >> 4 = 0x" + crcTemp + ";";
}
else{
simstr += "\r\n crcTemp = crcBuff[(k + posTemp) >> 1] & 0xf = crcBuff[" + val + "] & 0xf = 0x" + crcTemp + ";";
}
if((k + posTemp) > len - 1){//溢出!
simstr += "//数组溢出!最后半个字节没有参与运算!!!";
}
val = crc.substr(crc.length - 1, 1);//crc & 0x0F
simstr += "\r\n (crc & 0xf) ^ crcTemp = (0x" + crc + " & 0xf) ^ 0x" + crcTemp + " = 0x" + val + " ^ 0x" + crcTemp;
val = StringXORToString(val, crcTemp);//(crc & 0x0F) ^ crcTemp
simstr += " = 0x" + val + ";";
simstr += "\r\n " + crcTableArrayName + "[0x" + val + "]";
val = crcTableArray[hextoint(val)];// CRC8R_E0_Table[(crc & 0x0F) ^ crcTemp]
simstr += " = 0x" + val + ";";
simstr += "\r\n crc = (crc >> 4) ^ 0x" + val + " = (0x" + crc + " >> 4) ^ 0x" + val;
crc = StringRMToString(crc, 4);//(crc >> 4)
simstr += " = 0x" + crc + " ^ 0x" + val;
crc = StringXORToString(crc, val);
simstr += " = 0x" + crc + ";";
val = crcnum << 1;
if(j < val - 1) j++;
else{
j = 0;
k += val;
}
}
else{
crcTemp = crcBuff.substr(i ^ 1, 1);//半字节
if(i & 1){
simstr += "\r\n crcTemp = crcBuff[i >> 1] >> 4 = crcBuff[" + parseInt(i >>> 1) + "] >> 4 = 0x" + crcTemp + ";";
}
else{
simstr += "\r\n crcTemp = crcBuff[i >> 1] & 0xf = crcBuff[" + parseInt(i >>> 1) + "] & 0xf = 0x" + crcTemp + ";";
}
val = crc.substr(crc.length - 1, 1);//crc & 0x0F
simstr += "\r\n (crc & 0xf) ^ crcTemp = (0x" + crc + " & 0xf) ^ 0x" + crcTemp + " = 0x" + val + " ^ 0x" + crcTemp;
val = StringXORToString(val, crcTemp);//(crc & 0x0F) ^ crcTemp
simstr += " = 0x" + val + ";";
simstr += "\r\n " + crcTableArrayName + "[0x" + val + "]";
val = crcTableArray[hextoint(val)];// CRC8R_E0_Table[(crc & 0x0F) ^ crcTemp]
simstr += " = 0x" + val + ";";
simstr += "\r\n crc = (crc >> 4) ^ 0x" + val + " = (0x" + crc + " >> 4) ^ 0x" + val;
crc = StringRMToString(crc, 4);//(crc >> 4)
simstr += " = 0x" + crc + " ^ 0x" + val;
crc = StringXORToString(crc, val);
simstr += " = 0x" + crc + ";";
}
}
}
}
}
else{//大表
for(i = 0;i < crcsize;i++)
{
val = inttohex(i, crcnum);
str = GetHotWC3CRCPolyWorkValue(val, tabArray[0], crcpoly, tabArray[0], crcdir, crcbits, 0);//CRC4~64
crcTableArray.length ++;
crcTableArray[i] = str;
}
for(i = 0;i < len;i++){
simstr += "\r\ni = " + parseInt(i >>> 1) + "; crc = 0x" + crc + ((i == 0)? "(初值)":"") + ";";
crcTemp = crcBuff.substr(i, 2);
simstr += "\r\n crcTemp = crcBuff[i] = crcBuff[" + parseInt(i >>> 1) + "] = 0x" + crcTemp + ";";
if(crcdir){//大表左移
if(crcbits == 8){
val = StringXORToString(crc, crcTemp);
simstr += "\r\n crc ^ crcTemp = 0x" + crc + " ^ 0x" + crcTemp + " = 0x" + val + ";";
crc = crcTableArray[hextoint(val)];
simstr += "\r\n crc = " + crcTableArrayName + "[0x" + val + "] = 0x" + crc + ";";
i++;//整字节
}
else{
val = StringRMToString(crc, crcbits - 8);//>>bits-8
val = val.substr(val.length - 2, 2);//val & 0x0FF
simstr += "\r\n (crc >> " + parseInt(crcbits - 8) + ") ^ crcTemp = (0x" + crc + " >> " + parseInt(crcbits - 8) + ") ^ 0x" + crcTemp + " = 0x" + val + " ^ 0x" + crcTemp;
val = StringXORToString(val, crcTemp);//(crc >> 12) ^ crcBuff[i]
simstr += " = 0x" + val + ";";
simstr += "\r\n " + crcTableArrayName + "[0x" + val + "]";
val = crcTableArray[hextoint(val)];//CRC20L_10211_Table[(crc >> 12) ^ crcBuff[i]]
simstr += " = 0x" + val + ";";
simstr += "\r\n crc = (crc << 8) ^ 0x" + val + " = (0x" + crc + " << 8) ^ 0x" + val;
crc = StringLMToString(crc, 8);//(crc << 8)
simstr += " = 0x" + crc + " ^ 0x" + val;
crc = StringXORToString(crc, val);
simstr += " = 0x" + crc + ";";
i++;
}
simstr += "\r\n crc = crc & 0x" + tabArray[1];
crc = StringANDToString(crc, tabArray[1]);//crc&=0xffff
simstr += " = 0x" + crc + ";";
}
else{//大表右移
if(crcbits == 8){//1字节
val = StringXORToString(crc, crcTemp);
simstr += "\r\n crc ^ crcTemp = 0x" + crc + " ^ 0x" + crcTemp + " = 0x" + val + ";";
crc = crcTableArray[hextoint(val)];
simstr += "\r\n crc = " + crcTableArrayName + "[0x" + val + "] = 0x" + crc + ";";
i++;//整字节
}
else{
if(crcnum & 1){//半字节
}
else{//整字节
val = crc.substr(crc.length - 2, 2);//crc & 0xFF
simstr += "\r\n (crc & 0xff) ^ crcTemp = (0x" + crc + " & 0xff) ^ 0x" + crcTemp + " = 0x" + val + " ^ 0x" + crcTemp;
val = StringXORToString(val, crcTemp);//(crc & 0xFF) ^ crcTemp
simstr += " = 0x" + val + ";";
simstr += "\r\n " + crcTableArrayName + "[0x" + val + "]";
val = crcTableArray[hextoint(val)];// CRC8R_E0_Table[(crc & 0xFF) ^ crcTemp]
simstr += " = 0x" + val + ";";
simstr += "\r\n crc = (crc >> 8) ^ 0x" + val + " = (0x" + crc + " >> 8) ^ 0x" + val;
crc = StringRMToString(crc, 8);//(crc >> 8)
simstr += " = 0x" + crc + " ^ 0x" + val;
crc = StringXORToString(crc, val);
simstr += " = 0x" + crc + ";";
i++;//整字节
}
}
}
}
}
simstr += "\r\n表格函数最终结果(HotWC3的crc = 0x" + crcvalue + "):\r\n crc = crc ^ 出值= 0x" + crc + " ^ 0x" + text170.value;
crc = StringXORToString(crc, text170.value);//出值,得到结果
simstr += " = 0x" + crc + ";\r\n*/\r\n";
return (sim) ? simstr: crc;
}
function GetCRCTableArrayFunctionEx(crcvalue, BitSize, sim)
{
var i, j, k;
var crc, crch, crcl;
var crcTemp, posTemp;
var crcTableArrayNameh, crcTableArrayNamel;
var crcTableArrayh = new Array();
var crcTableArrayl = new Array();
var strArray = new Array();
var valArray = new Array();
var crcBuff, crcpoly;
var str, ptr, len, val, valx, valy, bith, bitl, bits;
var simstr;
var posTable = new Array();
var tabArray = new Array(2);
var crcbits, crcdir, crcnum, crcsize;
tabArray[0] = "0000000000000000";
tabArray[1] = "FFFFFFFFFFFFFFFF";
crcbits = GetCRCTableArrayBitsInt();
crcdir = GetCRCTableArrayDirInt();
crcnum = crcbits / 4;
switch(crcbits)
{
case 16:
crcnumh = 2;//crcnumh=2! char,char
crcnuml = 2;//char
break;
case 24://crcnumh=2! char,short
case 32://crcnumh=4! short,short
crcnumh = crcnum - 4;
crcnuml = 4;//short
break;
case 40://crcnumh=2! char,long
case 48://crcnumh=4! short,long
case 64://crcnumh=8! long,long
crcnumh = crcnum - 8;
crcnuml = 8;//long
break;
default:
return tabArray[0].substr(0, crcnum);
}
tabArray[0] = tabArray[0].substr(0, crcnum);
tabArray[1] = tabArray[1].substr(0, crcnum);
crcsize = (BitSize == 4) ? 16:256;
crcBuff = CodeStringToHex(text12.value, idselecodemode.selectedIndex);
len = crcBuff.length;
crc = text120.value;//取初值
crch = crc.substr(0, crcnumh);
crcl = crc.substr(crcnumh, crcnuml);
crcpoly = text130.value;
crcTableArrayNameh = text160.value;
valArray = crcTableArrayNameh.split("_");
valArray[2] = "Table";
valArray[3] = "Hi";
crcTableArrayNameh = valArray.join("_");
crcTableArrayNamel = text160.value;
valArray = crcTableArrayNamel.split("_");
valArray[2] = "Table";
valArray[3] = "Lo";
crcTableArrayNamel = valArray.join("_");
simstr = "/*";
simstr += "\r\n表格函数:\r\nGet" + text160.value + "_Table(unsigned char *crcBuff, unsigned int crcLen);";
simstr += "\r\n待校验数据区:\r\ncrcBuff[] = {//表格函数内部运算需要的Hex编码";
k = 0;
str = "";
for(i = 0;i < len;i+=2){
if((k % 16) == 0) {
if(k) str += ",";
str += "\r\n ";
}
else str += ", ";
str += "0x" + crcBuff.substr(i, 2);
k++;
}
simstr += str;
simstr += "\r\n}";
if(crcsize == 16){//小表
simstr += "\r\n小表循环次数:\r\ncrcLen * 2 = " + len + "次\r\n";
}
else{
simstr += "\r\n大表循环次数:\r\ncrcLen = " + (len / 2) + "次\r\n";
}
if(crcsize == 16){//小表
for(i = 0;i < crcsize;i++){
if(crcdir || (crcbits == 4)){//左移
val = i;
}
else{//右移
val = (i << 4);
}
val = inttohex(val, crcnum);
str = GetHotWC3CRCPolyWorkValue(val, tabArray[0], crcpoly, tabArray[0], crcdir, crcbits, 0);//CRC4~64
crcTableArrayh.length ++;
crcTableArrayl.length ++;
crcTableArrayh[i] = str.substr(0, crcnumh);
crcTableArrayl[i] = str.substr(crcnumh, crcnuml);
}
j = 0;
k = 0;
crcBuff += inttohex(0, crcnum - (len % crcnum));//补0
bith = (crcnumh - 1) * 4;
bitl = (crcnuml - 1) * 4;
for(i = 0;i < len;i++){
simstr += "\r\ni = " + i + "; crch = 0x" + crch + ", crcl = 0x" + crcl + ((i == 0)? "(初值)":"") + ";";
if(crcdir){//小表左移
crcTemp = crcBuff.substr(i, 1);//半字节
if(!(i & 1)){
simstr += "\r\n crcTemp = crcBuff[i >> 1] >> 4 = crcBuff[" + parseInt(i >>> 1) + "] >> 4 = 0x" + crcTemp + ";";
}
else{
simstr += "\r\n crcTemp = crcBuff[i >> 1] & 0xf = crcBuff[" + parseInt(i >>> 1) + "] & 0xf = 0x" + crcTemp + ";";
}
val = StringRMToString(crch, bith);//>>bits-4
simstr += "\r\n crcTemp = (crch >> " + bith + ") ^ crcTemp = 0x" + val;
val = StringXORToString(val.substr(val.length - 1, 1), crcTemp);
simstr += " ^ 0x" + crcTemp + " = 0x" + val + ";";
crcTemp = val;
val = crcTableArrayh[hextoint(crcTemp)];
simstr += "\r\n " + crcTableArrayNameh + "[crcTemp] = " + crcTableArrayNameh + "[0x" + crcTemp + "] = 0x" + val + ";";
valx = crch.substr(1, crcnumh - 1) + crcl.substr(0, 1);
simstr += "\r\n (crch << 4) | (crcl >> " + bitl + ")) = 0x" + valx + ";";
simstr += "\r\n crch = 0x" + valx + " ^ 0x" + val;
valx = valx.substr(valx.length - crcnumh, crcnumh);
val = StringXORToString(valx, val);
simstr += " = 0x" + val + ";";
crch = val;
val = crcTableArrayl[hextoint(crcTemp)];
simstr += "\r\n " + crcTableArrayNamel + "[crcTemp] = " + crcTableArrayNamel + "[0x" + crcTemp + "] = 0x" + val + ";";
valx = StringLMToString(crcl, 4);;
simstr += "\r\n crcl = (crcl << 4) ^ 0x" + val + " = 0x" + valx + " ^ 0x" + val;
val = StringXORToString(valx, val);
simstr += " = 0x" + val + ";";
crcl = val;
}
else{//小表右移
crcTemp = crcBuff.substr(i ^ 1, 1);//半字节
if((i & 1)){
simstr += "\r\n crcTemp = crcBuff[i >> 1] >> 4 = crcBuff[" + parseInt(i >>> 1) + "] >> 4 = 0x" + crcTemp + ";";
}
else{
simstr += "\r\n crcTemp = crcBuff[i >> 1] & 0xf = crcBuff[" + parseInt(i >>> 1) + "] & 0xf = 0x" + crcTemp + ";";
}
simstr += "\r\n crcTemp = (crcl & 0x0F) ^ crcTemp = 0x" + crcl.substr(crcl.length - 1, 1);
val = StringXORToString(crcl.substr(crcl.length - 1, 1), crcTemp);
simstr += " ^ 0x" + crcTemp + " = 0x" + val + ";";
crcTemp = val;
val = crcTableArrayl[hextoint(crcTemp)];
simstr += "\r\n " + crcTableArrayNamel + "[crcTemp] = " + crcTableArrayNamel + "[0x" + crcTemp + "] = 0x" + val + ";";
valx = crch.substr(crcnumh - 1, 1) + crcl.substr(0, crcnuml - 1);
simstr += "\r\n (crcl >> 4) | (crch << " + bitl + ")) = 0x" + valx + ";";
simstr += "\r\n crcl = 0x" + valx + " ^ 0x" + val;
valx = valx.substr(valx.length - crcnuml, crcnuml);
val = StringXORToString(valx, val);
simstr += " = 0x" + val + ";";
crcl = val;
val = crcTableArrayh[hextoint(crcTemp)];
simstr += "\r\n " + crcTableArrayNameh + "[crcTemp] = " + crcTableArrayNameh + "[0x" + crcTemp + "] = 0x" + val + ";";
valx = StringRMToString(crch, 4);;
simstr += "\r\n crch = (crch >> 4) ^ 0x" + val + " = 0x" + valx + " ^ 0x" + val;
val = StringXORToString(valx, val);
simstr += " = 0x" + val + ";";
crch = val;
}
}
crc = crch + crcl;
}
else{//大表
for(i = 0;i < crcsize;i++)
{
val = inttohex(i, crcnum);
str = GetHotWC3CRCPolyWorkValue(val, tabArray[0], crcpoly, tabArray[0], crcdir, crcbits, 0);//CRC4~64
crcTableArrayh.length ++;
crcTableArrayl.length ++;
crcTableArrayh[i] = str.substr(0, crcnumh);
crcTableArrayl[i] = str.substr(crcnumh, crcnuml);
}
bith = (crcnumh - 2) * 4;
bitl = (crcnuml - 2) * 4;
bits = bith + bitl;
for(i = 0;i < len;i+=2){
simstr += "\r\ni = " + parseInt(i >>> 1) + "; crch = 0x" + crch + ", crcl = 0x" + crcl + ((i == 0)? "(初值)":"") + ";";
if(crcdir){//大表左移
val = StringRMToString(crch, bith);
simstr += "\r\n crcTemp = ";
if(bith == 0){
simstr += "crch";
}
else{
simstr += "(crch >> " + bith + ")";
}
simstr += " ^ crcBuff[" + (i >>> 1) + "] = 0x" + val + " ^ 0x" + crcBuff.substr(i, 2);
val = StringXORToString(val, crcBuff.substr(i, 2));
val = StringHexToString(val, 2);
simstr += " = 0x" + val + ";";
crcTemp = val;
val = crcTableArrayh[hextoint(crcTemp)];
simstr += "\r\n " + crcTableArrayNameh + "[crcTemp] = " + crcTableArrayNameh + "[0x" + crcTemp + "] = 0x" + val + ";";
simstr += "\r\n";
if(bits == 0){//2,2
simstr += " crch = crcl ^ 0x" + val;
valx = crcl;
simstr += " = 0x" + crcl + " ^ 0x" + val;
}
else if(bits == 8){//2,4
simstr += " crch = (crcl >> 8) ^ 0x" + val;;
valx = StringRMToString(crcl, 8);
simstr += " = (0x" + crcl + " >> 8) ^ 0x" + val;
simstr += " = 0x" + valx + " ^ 0x" + val;
}
else{//4,4;4,8
simstr += " crch = ((crch << 8) | (crcl >> " + bitl + ")) ^ 0x" + val;
valx = StringLMToString(crch, 8);
valy = StringRMToString(crcl, bitl);
simstr += " = ((0x" + crch + " << 8) | (0x" + crcl + " >> " + bitl + ")) ^ 0x" + val + ";";
simstr += "\r\n crch = (0x" + valx + " | (0x" + valy + ") ^ 0x" + val;
valx = StringORToString(valx, valy);
simstr += " = 0x" + valx + " ^ 0x" + val;
}
val = StringXORToString(valx, val);
val = val.substr(val.length - crcnumh, crcnumh);
simstr += " = 0x" + val + ";";
crch = val;
val = crcTableArrayl[hextoint(crcTemp)];
simstr += "\r\n " + crcTableArrayNamel + "[crcTemp] = " + crcTableArrayNamel + "[0x" + crcTemp + "] = 0x" + val + ";";
simstr += "\r\n";
if(bitl == 0){
simstr += " crcl = 0x" + val;
}
else{
valx = StringLMToString(crcl, 8);
simstr += " crcl = (crcl << 8) ^ 0x" + val;
simstr += " = (0x" + crcl + " << 8) ^ 0x" + val;
simstr += " = (0x" + valx + " ^ 0x" + val;
val = StringXORToString(valx, val);
simstr += " = 0x" + val + ";";
}
crcl = val;
}
else{//大表右移
simstr += "\r\n crcTemp = crcl ^ crcBuff[" + (i >>> 1) + "] = 0x" + crcl + " ^ 0x" + crcBuff.substr(i, 2);
val = StringXORToString(crcl, crcBuff.substr(i, 2));
val = StringHexToString(val, 2);
simstr += " = 0x" + val + ";";
crcTemp = val;
val = crcTableArrayl[hextoint(crcTemp)];
simstr += "\r\n " + crcTableArrayNamel + "[crcTemp] = " + crcTableArrayNamel + "[0x" + crcTemp + "] = 0x" + val + ";";
simstr += "\r\n";
if(bitl == 0){//2,2
simstr += " crcl = crch ^ 0x" + val;
simstr += " = 0x" + crch + " ^ 0x" + val;
val = StringXORToString(crch, val);
}
else{//4,4;4,8;8,8
simstr += " crcl = ((crcl >> 8) | (crch << " + bitl + ")) ^ 0x" + val;
valx = StringRMToString(crcl, 8);
valy = StringLMToStringEx(crch, bitl);
simstr += " = ((0x" + crcl + " >> 8) | (0x" + crch + " << " + bitl + ")) ^ 0x" + val + ";";
simstr += "\r\n crcl = (0x" + valx + " | (0x" + valy + ") ^ 0x" + val;
valx = StringORToString(valx, valy);
simstr += " = 0x" + valx + " ^ 0x" + val;
val = StringXORToString(valx, val);
}
val = StringHexToString(val, crcnuml);
simstr += " = 0x" + val + ";";
crcl = val;
val = crcTableArrayh[hextoint(crcTemp)];
simstr += "\r\n " + crcTableArrayNameh + "[crcTemp] = " + crcTableArrayNameh + "[0x" + crcTemp + "] = 0x" + val + ";";
simstr += "\r\n";
if(bith == 0){
simstr += " crch = 0x" + val + ";";
}
else{
valx = StringRMToString(crch, 8);
simstr += " crch = (crch >> 8) ^ 0x" + val;
val = StringXORToString(valx, val);
simstr += " = 0x" + val + ";";
}
val = StringHexToString(val, crcnumh);
crch = val;
}
}
crc = crch + crcl;
}
simstr += "\r\n表格函数最终结果(HotWC3的crc = 0x" + crcvalue + "):\r\n crc = crc ^ 出值= 0x" + crc + " ^ 0x" + text170.value;
crc = StringXORToString(crc, text170.value);//出值,得到结果
simstr += " = 0x" + crc + ";\r\n*/\r\n";
return (sim) ? simstr: crc;
}
function MakeCRCBitsFunction(BitSize)
{
var str, stable, tblName, funcName;
var crcName, dataType;
var i, j, k, row, col, count, len, val;
var crcbits, crcdir, crcnum;
var strdata0, strpoly;
var strinit, strstop;
var strff = "FFFFFFFFFFFFFFFF";
var crcvalue, fucstring, errstring;
var filename, write;
// var Tabstring;
crcbits = GetCRCTableArrayBitsInt();
crcdir = GetCRCTableArrayDirInt();
crcnum = crcbits / 4;
filename = text13.value;//保护文件名
// Tabstring = text140.value;
if(languagesele.value == "TAB") languagesele.selectedIndex = 1;//.C
crcName = selemode1.value + select1.value;
len = GetText12StringLen();
idTextBox.value = "";
ChangeidTextBox();
if(len == 0){
alert("明文长度不能为0!!!");
return;
}
else if(len & 1){
alert("明文长度不能是奇数!!!");
return;
}
errstring = "";
if((crcdir == 0) && (crcnum > 1) && (crcnum & 1)){
i = crcnum + 1;
j = crcnum << 1;
k = len % j;
if(!((k == 0) || (k >= i))){
i -= k;
i >>>= 1;
k >>>= 1;
errstring = "明文需增加" + i + "个字节或删除" + k + "个字节!!!";
if(confirm("字节数不符合移位函数要求!!!\n" + errstring + "\n请确认是否退出???")) return;
}
}
fileName = text13.value;//保护文件名
// operatorsele.selectedIndex = 0;
// calculator();//暂时计算一次,得到结果
hotcrc();//运算
// operatorsele.selectedIndex = 13;
text13.value = filename;//恢复文件名
crcvalue = text140.value;
// text140.value = Tabstring;
fucstring = GetCRCBitsFunction(crcvalue, BitSize, 0);
strdata0 = inttohex(0, crcnum);
strpoly = text130.value;// GetCRCTableArrayPolyString()
strinit = text120.value;// GetCRCTableArrayInitString()
strstop = text170.value;// GetCRCTableArrayStopString()
str = text160.value;// HotCRCPolyTableArray[GetCRCTableArraySelectedIndex()]
stable = GetHotCRCCodeCopyRight() + "//CRC移位" + ((BitSize == 8) ? "大表" : "小表") + "表格:\r\n";
len = GetText12StringLen();
if (idselecodemode.selectedIndex == 0) len >>>= 1;
switch(crcbits)
{
case 4:
dataType = "unsigned char";
break;
case 8:
dataType = "unsigned char";
break;
case 12:
dataType = "unsigned short";
break;
case 16:
dataType = "unsigned short";
break;
case 20:
case 24:
case 28:
case 32:
dataType = "unsigned long";
break;
case 36:
case 40:
case 44:;
case 48:
case 52:
case 56:
case 60:
dataType = "uint" + crcbits;
break;
case 64:
dataType = "uint" + crcbits;
break;
}
funcName = "Get" + str;
stable = GetHotCRCCodeCopyRight() + "//CRC移位" + ((BitSize == 8) ? "大表" : "小表") + "表格:\r\n";
stable += dataType + " " + funcName + "(unsigned char *crcBuff, unsigned ";
stable += "int crcLen) {\r\n";
stable += "unsigned int i, n;\r\n";
stable += dataType + " crc = 0x" + strinit + ";//初值\r\n";
stable += "unsigned char crcTemp";
if((crcnum > 1) && (BitSize == 4)){//“半字节CRC”
stable += ", j = 0, k = 0, posTemp;\r\n";
stable += "unsigned char posTable[] = ";
stable += "\"" + GetCRCBitsPosionString(crcbits) + "\"";
}
stable += ";\r\n";
if (BitSize == 4)
{//位域4
stable += " for(i = 0; i < (crcLen * 2); i ++){\r\n";
}
else stable += " for(i = 0; i < crcLen; i ++){\r\n";
if (crcdir)
{//左移
if (BitSize == 4)
{//位域4
stable += " if(!(i & 1)) crcTemp = crcBuff[i >> 1] >> 4;\r\n";
stable += " else crcTemp = crcBuff[i >> 1] & 0x0F;\r\n";
}
else{
stable += " crcTemp = crcBuff[i];\r\n";
}
stable += " for(n = 0; n < " + BitSize + "; n++){\r\n";
if (BitSize == 4){
stable += " if((crcTemp ^ crc) & 0x08){\r\n";
}
else{
stable += " if((crcTemp ^ (crc >> " + (crcbits - 8) + ")) & 0x80){\r\n";
}
stable += " crc <<= 1;\r\n";
stable += " crc ^= 0x" + strpoly + ";\r\n";
stable += " }\r\n";
stable += " else crc <<= 1;\r\n";
stable += " crcTemp <<= 1;\r\n";
stable += " }\r\n";
stable += " crc &= 0x" + strff.substr(0, crcnum) + ";\r\n";
}
else
{//右移
if (BitSize == 4)
{//位域4
if(crcbits == 4){
stable += " if(!(i & 1)) crcTemp = crcBuff[i >> 1] >> 4;\r\n";
stable += " else crcTemp = crcBuff[i >> 1] & 0x0F;\r\n";
}
else{
stable += " posTemp = posTable[j];\r\n";
stable += " if(!(posTemp & 1)) crcTemp = crcBuff[(k + posTemp) >> 1] >> 4;\r\n";
stable += " else crcTemp = crcBuff[(k + posTemp) >> 1] & 0x0F;\r\n";
}
}
else{
stable += " crcTemp = crcBuff[i];\r\n";
}
stable += " for(n = 0; n < " + BitSize + "; n++){\r\n";
stable += " if((crcTemp ^ crc) & 0x01){\r\n";
stable += " crc >>= 1;\r\n";
stable += " crc ^= 0x" + strpoly + ";\r\n";
stable += " }\r\n";
stable += " else crc >>= 1;\r\n";
stable += " crcTemp >>= 1;\r\n";
stable += " }\r\n";
if((crcnum > 1) && (BitSize == 4))
{//位域4
stable += " if(j < sizeof(posTable) - 2) j++;\r\n";
stable += " else{\r\n";
stable += " j = 0;\r\n";
stable += " k += sizeof(posTable) - 1;\r\n";
stable += " }\r\n";
}
}
stable += " }\r\n";
if (crcbits <= 32)
{
if (hextoint(strstop)) stable += " crc ^= 0x" + strstop + ";//出值\r\n";
}
else
{
if (hextoint(strstop.substr(0, crcnum - 8)) || hextoint(strstop.substr(crcnum - 8, 8))) stable += " crc ^= 0x" + strstop + ";//出值\r\n";
}
stable += " return crc;\r\n";
stable += "}\r\n";
stable += "int main(){\r\n//数据格式:";
stable += idselecodemode.value;
stable += "\r\n";
stable += "const unsigned char dataTable[] = ";
if (text12.value == "")
{
if (idselecodemode.selectedIndex) stable += '\"0123456789ABCDEF\"';
else stable += '{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}"';
}
else
{
if (idselecodemode.selectedIndex) stable += '"' + text12.value + '"';
else
{
stable += '{';
stable += '\r\n';
j = 0;
for (i = 0; i < GetText12StringLen(); i += 2)
{
if(j == 0) stable += " ";
stable += "0x" + text12.value.substr(i, 2);
if(i < (GetText12StringLen() - 2)) {
stable += ", ";
j ++;
if(j == 16) {
stable += '\r\n';
j = 0;
}
}
}
stable += '\r\n}';
}
}
stable += ";//特别注意Keil C51请用code替换const\r\n";
stable += dataType + " crc;\r\n";
stable += " crc = " + funcName + "((unsigned char *)dataTable, sizeof(dataTable)";
if (idselecodemode.selectedIndex) stable += " - 1";
stable += ");\r\n";
stable += "//移位函数返回crc=0x" + fucstring;
if(crcvalue == fucstring){
stable += ",与HotWC3运算相同";
}
else{
stable += ",HotWC3运算crc=0x" + crcvalue;
}
if(errstring) stable += "。验证失败!" + errstring;
stable += "\r\n";
stable += " while(crc | 1);//死循环,请在此处设置断点,验证函数返回值crc是否正确!!!\r\n";
stable += " return 0;\r\n";
stable += "}\r\n";
if(languagesele.value == ".SIM"){
stable += GetCRCBitsFunction(crcvalue, BitSize, 1);
}
idTextBox.value = stable;
ChangeidTextBox();
if (languagesele.value == ".C" || languagesele.value == ".SIM") {
if((errstring == "") && (crcvalue == fucstring)){
if(confirm(crcName + "C语言源码已通过模拟验证,请放心使用!!!"+"\n需要将其复制到剪切板上吗???")){
texteditclipboard();//
}
}
else{
alert(crcName + "C语言源码与HotWC3运算模拟验证失败!!!\n" + errstring);
}
}
}
function GetHotCRCCodeCopyRight()
{
var str = "";
var d = new Date();
str += "/*------------------------------------------------------------------------------\n";
str += " 本C语言核心代码由菜农HotPower@163.com的超级CRC计算器自动生成\n";
str += " Copyright 1996-2022 HotPower Software, Inc.\n";
str += " 菜农HotPower@163.com ";
str += d.getFullYear() + "年";
str += (d.getMonth() + 1) + "月";
str += d.getDate() + "日 ";
str += d.toLocaleTimeString();
str += " 于西安雁塔菜地\n";
str += "------------------------------------------------------------------------------*/\n";
return str;
}
function MakeCRCTableArray(BitSize)
{
var str, stable, tblName, funcName;
var crcName, dataType;
var i, j, k, row, col, count, len, val;
var crcbits, crcdir, crcnum;
var strdata0, strpoly;
var strinit, strstop;
var strff = "FFFFFFFFFFFFFFFF";
var crcvalue, fucstring, errstring;
var filename, write;
crcbits = GetCRCTableArrayBitsInt();
crcdir = GetCRCTableArrayDirInt();
crcnum = crcbits / 4;
if((crcbits == 4) || ((languagesele.value == ".C" || languagesele.value == ".SIM") && ((crcdir == 0) && (crcnum & 1)))){//右移半字节
BitSize = 4;//强行变为小表
}
crcName = selemode1.value + select1.value;
len = GetText12StringLen();
idTextBox.value = "";
ChangeidTextBox();
if(languagesele.value != ".TAB"){
if(len == 0){
alert("明文长度不能为0!!!");
return;
}
else if(len & 1){
alert("明文长度不能是奇数!!!");
return;
}
errstring = "";
if((crcdir == 0) && (crcnum > 1) && (crcnum & 1)){
i = crcnum + 1;
j = crcnum << 1;
k = len % j;
if(!((k == 0) || (k >= i))){
i -= k;
i >>>= 1;
k >>>= 1;
errstring = "明文需增加" + i + "个字节或删除" + k + "个字节!!!";
if(confirm("字节数不符合表格函数要求!!!\n" + errstring + "\n请确认是否退出???")) return;
}
}
}
filename = text13.value;//保护文件名
// operatorsele.selectedIndex = 0;
// calculator();//暂时计算一次,得到结果
hotcrc();//运算
// operatorsele.selectedIndex = 13;
text13.value = filename;//恢复文件名
crcvalue = text140.value;
fucstring = GetCRCTableArrayFunction(crcvalue, BitSize, 0);
strdata0 = inttohex(0, crcnum);
strpoly = text130.value;// GetCRCTableArrayPolyString()
strinit = text120.value;// GetCRCTableArrayInitString()
strstop = text170.value;// GetCRCTableArrayStopString()
str = text160.value;// HotCRCPolyTableArray[GetCRCTableArraySelectedIndex()]
stable = GetHotCRCCodeCopyRight() + "//CRC单表" + ((BitSize == 8) ? "大表" : "小表") + "表格:\r\n";
len = GetText12StringLen();
if (idselecodemode.selectedIndex == 0) len >>>= 1;
switch(crcbits)
{
case 4:
col = 16;
dataType = "unsigned char";
break;
case 8:
col = 16;
dataType = "unsigned char";
break;
case 12:
col = 16;
dataType = "unsigned short";
break;
case 16:
col = 16;
dataType = "unsigned short";
break;
case 20:
case 24:
case 28:
case 32:
col = 8;
dataType = "unsigned long";
break;
case 36:
case 40:
case 44:;
case 48:
case 52:
case 56:
case 60:
col = 8;
dataType = "uint" + crcbits;
break;
case 64:
col = 4;
dataType = "uint" + crcbits;
break;
}
if (crcbits < 8 || BitSize == 4) row = 16 / col;
else row = 256 / col;
count = row * col;
funcName = "Get" + str + "_Table";
tblName = str.substr(0, str.length - 2 * crcnum - 2) + "_Table";
stable += "const " + dataType + " " + tblName + "[" + count + "] = {//特别注意Keil C51请用code替换const";
if (!discheckbox.checked) stable += "//此表不可逆";
for (i = 0; i < row; i ++)
{
stable += "\r\n";
for (j = 0; j < col; j ++)
{
k = i * col + j;
if (crcbits < 8) str = inttohex(k, 1);
else
{
if (BitSize == 4 && crcdir == 0) str = inttohex(0, crcnum - 2) + inttohex(k << 4, 2);
else str = inttohex(0, crcnum - 2) + inttohex(k, 2);
}
str = GetHotWC3CRCPolyWorkValue(str, strdata0, strpoly, strdata0, crcdir, crcbits, 0);//CRC4~64
if (j) stable += ",";
else stable += " ";
switch(languagesele.value)
{
case ".TAB":
case ".SIM":
case ".C":
stable += "0x";
break;
}
stable += str;
if (crcbits > 16 && (languagesele.value == ".C" || languagesele.value == ".TAB" || languagesele.value == ".SIM")) stable += "L";
}
if (i < (row - 1)) if (j) stable += ",";
}
stable += "\r\n};\r\n";
if (languagesele.value == ".C" || languagesele.value == ".SIM")
{
stable += "//CRC单表" + ((BitSize == 8) ? "大表" : "小表") + "查表算法:\r\n";
stable += dataType + " " + funcName + "(unsigned char *crcBuff, unsigned ";
// stable += (len > 255) ? "int" : "char";
stable += "int crcLen) {\r\n";
stable += "unsigned int i";
if((BitSize == 4) && (crcdir == 0) && (crcnum > 1) && (crcnum & 1)){//“半字节CRC”
stable += ", j = 0, k = 0"
}
stable += ";\r\n";
stable += dataType + " crc = 0x" + strinit + ";//初值\r\n";
if (BitSize == 4)
{//位域4
stable += "unsigned char crcTemp";
if((crcdir == 0) && (crcnum > 1) && (crcnum & 1)){//“半字节CRC”
stable += ", posTemp;\r\n";
stable += "unsigned char posTable[] = ";
stable += "\"" + GetCRCBitsPosionString(crcbits) + "\"";
}
stable += ";\r\n";
stable += " for(i = 0; i < (crcLen * 2); i ++){\r\n";
}
else stable += " for(i = 0; i < crcLen; i ++){\r\n";
if (crcdir)
{//左移
if (BitSize == 4)
{//位域4
stable += " if (i & 1) crcTemp = crcBuff[i >> 1] & 0x0F;\r\n";
stable += " else crcTemp = crcBuff[i >> 1] >> 4;\r\n";
}
}
else
{//右移
if (BitSize == 4)
{//位域4
if(crcnum == 1){//“半字节CRC”
stable += " if (!(i & 1))";
stable += " crcTemp = crcBuff[i >> 1] >> 4;\r\n";
stable += " else crcTemp = crcBuff[i >> 1] & 0x0F;\r\n";
}
else if((crcdir == 0) && (crcnum & 1)){//“半字节CRC”
stable += " posTemp = posTable[j];\r\n";
stable += " if (!(posTemp & 1)) crcTemp = crcBuff[(k + posTemp) >> 1] >> 4;\r\n";
stable += " else crcTemp = crcBuff[(k + posTemp) >> 1] & 0x0F;\r\n";
}
else{
stable += " if (i & 1) crcTemp = crcBuff[i >> 1] >> 4;\r\n";
stable += " else crcTemp = crcBuff[i >> 1] & 0x0F;\r\n";
}
}
}
if (crcdir)
{
if ((BitSize == 8 && crcbits == 8) || crcbits == 4)
{
stable += " crc = " + tblName + "[crc";
}
else
{
stable += " crc = (crc << " + BitSize + ") ^";
stable += " " + tblName + "[(crc >> ";
stable += crcbits - BitSize + ")";
}
stable += " ^ ";
if (BitSize == 4) stable += "crcTemp];\r\n";
else stable += "crcBuff[i]];\r\n";
if(crcbits != 8){
stable += " crc &= 0x" + strff.substr(0, crcnum);
if(crcbits > 16) stable += "L";
stable += ";//请注意此语句为了防止数据溢出,有时可删除,具体看编译环境!\r\n";
}
}
else
{//右移
if ((BitSize == 8 && crcbits == 8) || crcbits == 4)
{
stable += " crc = " + tblName + "[crc";
}
else
{
stable += " crc = (crc >> " + BitSize;
stable += ") ^ " + tblName + "[(crc & ";
stable += (BitSize == 4) ? "0x0F)": "0xFF)";
}
stable += " ^ ";
if (BitSize == 4) stable += "crcTemp];\r\n";
else stable += "crcBuff[i]];\r\n";
if((BitSize == 4) && (crcdir == 0) && (crcnum > 1) && (crcnum & 1)){
stable += " if(j < sizeof(posTable) - 2) j++;\r\n";
stable += " else{\r\n";
stable += " j = 0;\r\n";
stable += " k += sizeof(posTable) - 1;\r\n";
stable += " }\r\n";
}
}
stable += " }\r\n";
if (crcbits <= 32)
{
if (hextoint(strstop)) stable += " crc ^= 0x" + strstop + ";//出值\r\n";
}
else
{
if (hextoint(strstop.substr(0, crcnum - 8)) || hextoint(strstop.substr(crcnum - 8, 8))) stable += " crc ^= 0x" + strstop + ";//出值\r\n";
}
stable += " return crc;\r\n";
stable += "}\r\n";
stable += "int main(){\r\n//数据格式:";
stable += idselecodemode.value;
stable += "\r\n";
stable += "const unsigned char dataTable[] = ";
if (text12.value == "")
{
if (idselecodemode.selectedIndex) stable += '\"0123456789ABCDEF\"';
else stable += '{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}"';
}
else
{
if (idselecodemode.selectedIndex) stable += '"' + text12.value + '"';
else
{
stable += '{';
stable += '\r\n';
j = 0;
for (i = 0; i < GetText12StringLen(); i += 2)
{
if(j == 0) stable += " ";
stable += "0x" + text12.value.substr(i, 2);
if(i < (GetText12StringLen() - 2)) {
stable += ", ";
j ++;
if(j == 16) {
stable += '\r\n';
j = 0;
}
}
}
stable += '\r\n}';
}
}
stable += ";//特别注意Keil C51请用code替换const\r\n";
stable += dataType + " crc;\r\n";
stable += " crc = " + funcName + "((unsigned char *)dataTable, sizeof(dataTable)";
if (idselecodemode.selectedIndex) stable += " - 1";
stable += ");\r\n";
stable += "//表格函数返回crc=0x" + fucstring;
if(crcvalue == fucstring){
stable += ",与HotWC3运算相同";
}
else{
stable += ",HotWC3运算crc=0x" + crcvalue;
}
if(errstring) stable += "。验证失败!" + errstring;
stable += "\r\n";
stable += " while(crc | 1);//死循环,请在此处设置断点,验证函数返回值crc是否正确!!!\r\n";
stable += " return 0;\r\n";
stable += "}\r\n";
}
if(languagesele.value == ".SIM"){
stable += GetCRCTableArrayFunction(crcvalue, BitSize, 1);
}
idTextBox.value = stable;
ChangeidTextBox();
if (languagesele.value == ".C" || languagesele.value == ".SIM") {
if((errstring == "") && (crcvalue == fucstring)){
if(confirm(crcName + "多项式表格和C语言都已通过模拟验证,请放心使用!!!"+"\n需要将其复制到剪切板上吗???")){
texteditclipboard();//
}
}
else{
alert(crcName + "多项式表格已通过验证!!!\n表格函数与HotWC3运算模拟验证失败!!!\n" + errstring);
}
}
else {
if(confirm(crcName + "多项式表格已通过验证,请放心使用!!!"+"\n需要将其复制到剪切板上吗???")){
texteditclipboard();//
}
}
}
function GetArrayCRCNumInt(arrayBuffer, crcnum)
{
var str, i, j, k, m, n, crcsize;
k = crcnum;
crcsize = crcnum;
n = 2;
while(k > 2){//最小char
j = 0;
for(i = 0;i < arrayBuffer.length;i ++){
str = arrayBuffer[i];
if(inttohex(0, n) == str.substr(0, n)) j++;
}
if(j != arrayBuffer.length) break;//不能优化
m = crcnum - n;
if((m == 2) || (m == 4)) crcsize = m;
n += 2;
k -= 2;
}
return crcsize;
}
function GetDataTypeString(crcnum)
{
var str = "unsigned ";
switch(crcnum){
case 2:
str += "char";
break;
case 4:
str += "short";
break;
case 6:
str += "long";
break;
case 8:
str += "long";
break;
}
return str;
}
function MakeCRCTableArrayEx(BitSize)
{//双表
var str, stable, stableh, stableh, tblNameh, tblNamel, funcName;
var crcName, dataType, dataTypeh, dataTypel, arrayTypeh, arrayTypel;
var i, j, k, row, col, count, len, val, counth, countl;
var crcbits, crcdir, crcnum, crcnumh, crcnuml;
var arraynumh, arraynuml;
var bith, bitl, bits;
var strdata0, strpoly;
var strinit, strstop;
var strff = "FFFFFFFFFFFFFFFF";
var crcvalue, fucstring, errstring;
var filename, write;
var arrayBufferh = new Array();
var arrayBufferl = new Array();
crcbits = GetCRCTableArrayBitsInt();
crcdir = GetCRCTableArrayDirInt();
crcnum = crcbits / 4;
crcName = selemode1.value + select1.value;
len = GetText12StringLen();
idTextBox.value = "";
ChangeidTextBox();
if(languagesele.value != ".TAB"){
if(len == 0){
alert("明文长度不能为0!!!");
return;
}
else if(len & 1){
alert("明文长度不能是奇数!!!");
return;
}
}
switch(crcbits)
{
case 16:
crcnumh = 2;//crcnumh=2! char,char
crcnuml = 2;//char
col = 16;
dataType = "unsigned char";
break;
case 24://crcnumh=2! char,short
case 32://crcnumh=4! short,short
crcnumh = crcnum - 4;
crcnuml = 4;//short
col = 16;
dataType = "unsigned short";
break;
case 40://crcnumh=2! char,long
case 48://crcnumh=4! short,long
case 64://crcnumh=8! long,long
crcnumh = crcnum - 8;
crcnuml = 8;//long
col = 8;
dataType = "unsigned long";
break;
default:
alert("您选中的CRC" + crcbits + "目前版本不支持双表!!!");
return;
}
errstring = "";
filename = text13.value;//保护文件名
// operatorsele.selectedIndex = 0;
// calculator();//暂时计算一次,得到结果
hotcrc();//运算
// operatorsele.selectedIndex = 13;
text13.value = filename;//恢复文件名
crcvalue = text140.value;
fucstring = GetCRCTableArrayFunctionEx(crcvalue, BitSize, 0);
strdata0 = inttohex(0, crcnum);
strpoly = text130.value;// GetCRCTableArrayPolyString()
strinit = text120.value;// GetCRCTableArrayInitString()
strstop = text170.value;// GetCRCTableArrayStopString()
str = text160.value;// HotCRCPolyTableArray[GetCRCTableArraySelectedIndex()]
stable = GetHotCRCCodeCopyRight() + "//CRC双表" + ((BitSize == 8) ? "大表" : "小表") + "查表算法:\r\n";
stableh = "";
stablel = "";
len = GetText12StringLen();
if (idselecodemode.selectedIndex == 0) len >>>= 1;//太简单,有个测试函数
if (BitSize == 4) row = 16 / col;
else row = 256 / col;
count = row * col;
counth = 0;//高位0的个数
countl = 0;//低位0的个数
funcName = "Get" + str + "_Table";
tblNameh = str.substr(0, str.length - 2 * crcnum - 2) + "_Table_Hi";
tblNamel = str.substr(0, str.length - 2 * crcnum - 2) + "_Table_Lo";
for (i = 0; i < row; i ++)
{
for (j = 0; j < col; j ++)
{
k = i * col + j;
if (BitSize == 4 && crcdir == 0) str = inttohex(0, crcnum - 2) + inttohex(k << 4, 2);
else str = inttohex(0, crcnum - 2) + inttohex(k, 2);
str = GetHotWC3CRCPolyWorkValue(str, strdata0, strpoly, strdata0, crcdir, crcbits, 0);//CRC4~64
arrayBufferh.length++;
arrayBufferh[arrayBufferh.length - 1] = str.substr(0, crcnumh);
if(inttohex(0, crcnumh) == str.substr(0, crcnumh)){
counth ++;
}
arrayBufferl.length++;
arrayBufferl[arrayBufferh.length - 1] = str.substr(crcnumh, crcnuml);
if(inttohex(0, crcnuml) == str.substr(crcnumh, crcnuml)){
countl ++;
}
}
}//for(i)
arraynumh = GetArrayCRCNumInt(arrayBufferh, crcnumh);
arraynuml = GetArrayCRCNumInt(arrayBufferl, crcnuml);
dataTypeh = GetDataTypeString(crcnumh);
dataTypel = GetDataTypeString(crcnuml);
arrayTypeh = GetDataTypeString( arraynumh);
arrayTypel = GetDataTypeString( arraynuml);
stableh += "const " + arrayTypeh + " " + tblNameh + "[" + count + "] = {//特别注意Keil C51请用code替换const";
stablel += "const " + arrayTypel + " " + tblNamel + "[" + count + "] = {//特别注意Keil C51请用code替换const";
if (!discheckbox.checked) {
stableh += "//此表不可逆";
stablel += "//此表不可逆";
}
k = 0;
for (i = 0; i < row; i ++)
{
stableh += "\r\n";
stablel += "\r\n";
for (j = 0; j < col; j ++)
{
if (j){
stableh += ",";
stablel += ",";
}
else{
stableh += " ";
stablel += " ";
}
switch(languagesele.value)
{
case ".TAB":
case ".SIM":
case ".C":
stableh += "0x";
stablel += "0x";
break;
}
stableh += StringHexToString(arrayBufferh[k], arraynumh);
stablel += StringHexToString(arrayBufferl[k], arraynuml);
k++;
if (crcnumh > 8) stableh += "L";
if (crcnuml > 8) stablel += "L";
}
if (i < (row - 1)) if (j){
stableh += ",";
stablel += ",";
}
}//for(i)
stableh += "\r\n};\r\n";
stablel += "\r\n};\r\n";
if(BitSize == 4){//小表
if(counth != 16) counth = 0;
if(countl != 16) countl = 0;
}
else{
if(counth != 256) counth = 0;
if(countl != 256) countl = 0;
}
/*
counth = 0;//高位0的个数
countl = 0;//低位0的个数
*/
if(counth == 0 || languagesele.value == ".TAB"){//高0
stable += stableh + "\r\n";
}
else{
stable += "/*\r\n" + stableh + "*/\r\n";
}
if(countl == 0 || languagesele.value == ".TAB"){
stable += stablel + "\r\n";
}else{
stable += "/*\r\n" + stablel + "*/\r\n";
}
if (languagesele.value == ".C" || languagesele.value == ".SIM")
{
if(crcnuml + crcnumh > 8){
stable += "\r\n" + dataTypeh + " crch;\r\n";
stable += dataTypel + " crcl;\r\n";
}
stable += "//CRC双表" + ((BitSize == 8) ? "大表" : "小表") + "查表算法:\r\n";
if(crcnuml + crcnumh > 8){
stable += "void ";
}
else{
stable += GetDataTypeString(crcnum) + " ";
}
stable += funcName + "(unsigned char *crcBuff, unsigned ";
stable += "int crcLen) {\r\n";
stable += "unsigned int i;\r\n";
stable += "unsigned char crcTemp;\r\n";
if((crcnuml + crcnumh) <= 8){
if(crcnuml == crcnumh){
stable += dataTypeh + " crch, crcl;\r\n";
}
else{
stable += dataTypeh + " crch;\r\n";
stable += dataTypel + " crcl;\r\n";
}
}
stable += " crch = 0x" + strinit.substr(0, crcnumh) + ";\r\n";
stable += " crcl = 0x" + strinit.substr(crcnumh, crcnuml) + ";\r\n";
if(BitSize == 4){//小表
bith = (crcnumh - 1) * 4;
bitl = (crcnuml - 1) * 4;
stable += " for(i = 0; i < (crcLen * 2); i ++){\r\n";
if (crcdir)
{//小表左移
stable += " if (i & 1) crcTemp = crcBuff[i >> 1] & 0x0F;\r\n";
stable += " else crcTemp = crcBuff[i >> 1] >> 4;\r\n";
stable += " crcTemp = (crch >> " + bith + ") ^ crcTemp;\r\n";
stable += " crch = ((crch << 4) | (crcl >> " + bitl + "))";
stable += (counth) ? ";\r\n" : " ^ " + tblNameh + "[crcTemp];\r\n";
stable += " crcl = (crcl << 4)";
stable += (countl) ? ";\r\n" : " ^ " + tblNamel + "[crcTemp];\r\n";
}
else
{//小表右移
stable += " if (i & 1) crcTemp = crcBuff[i >> 1] >> 4;\r\n";
stable += " else crcTemp = crcBuff[i >> 1] & 0x0F;\r\n";
stable += " crcTemp = (crcl & 0x0F) ^ crcTemp;\r\n";
stable += " crcl = ((crcl >> 4) | (crch << " + bitl + "))";
stable += (countl) ? ";\r\n" : " ^ " + tblNamel + "[crcTemp];\r\n";
stable += " crch = (crch >> 4)";
stable += (counth) ? ";\r\n" : " ^ " + tblNameh + "[crcTemp];\r\n";
}
}
else{//大表
stable += " for(i = 0; i < crcLen; i ++){\r\n";
bith = (crcnumh - 2) * 4;
bitl = (crcnuml - 2) * 4;
bits = bith + bitl;
if (crcdir)
{//大表左移
if(bith == 0){
stable += " crcTemp = crch ^ crcBuff[i];\r\n";
}
else{
stable += " crcTemp = (crch >> " + bith + ") ^ crcBuff[i];\r\n";
}
if(bits == 0){//2,2
stable += " crch = crcl";
}
else if(bits == 8){//2,4
stable += " crch = (crcl >> 8)";
}
else {//4,4;4,8
stable += " crch = ((crch << 8) | (crcl >> " + bitl + "))";
}
stable += (counth) ? ";\r\n" : " ^ " + tblNameh + "[crcTemp];\r\n";
if(bitl == 0){
stable += " crcl = ";
stable += (countl) ? "0;\r\n" : tblNamel + "[crcTemp];\r\n";
}
else{
stable += " crcl = (crcl << 8)";
stable += (countl) ? ";\r\n" : " ^ " + tblNamel + "[crcTemp];\r\n";
}
}
else
{//大表右移
stable += " crcTemp = crcl ^ crcBuff[i];\r\n";
if(bitl == 0){//2,2
stable += " crcl = crch";
}
else{//4,4;4,8;8,8
stable += " crcl = ((crcl >> 8) | (crch << " + bitl + "))";
}
stable += (countl) ? ";\r\n" : " ^ " + tblNamel + "[crcTemp];\r\n";
if(bith == 0){
stable += " crch = ";
stable += (counth) ? "0;\r\n" : tblNameh + "[crcTemp];\r\n";
}
else{
stable += " crch = (crch >> 8)";
stable += (counth) ? ";\r\n" : " ^ " + tblNameh + "[crcTemp];\r\n";
}
}
}
stable += " }\r\n";
if (hextoint(strstop)){
stable += " crch ^= 0x" + strstop.substr(0, crcnumh ) + ";\r\n";
stable += " crcl ^= 0x" + strstop.substr(crcnumh, crcnuml) + ";\r\n";
}
if((crcnuml + crcnumh) <= 8){
stable += " return ";
stable += "(" + GetDataTypeString(crcnum) +")";
stable += "(crch << " + (crcnuml * 4) + ") | crcl;\r\n";
}
stable += "}\r\n";
stable += "int main(){\r\n//数据格式:";
stable += idselecodemode.value;
stable += "\r\n";
if((crcnuml + crcnumh) > 8){
stable += dataTypeh + " crchi;\r\n";
stable += dataTypel + " crclo;\r\n";
}
else{
stable += GetDataTypeString(crcnum) + " crc;\r\n";
}
stable += "const unsigned char dataTable[] = ";
if (text12.value == "")
{
if (idselecodemode.selectedIndex) stable += '\"0123456789ABCDEF\"';
else stable += '{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}"';
}
else
{
if (idselecodemode.selectedIndex) stable += '"' + text12.value + '"';
else
{
stable += '{';
stable += '\r\n';
j = 0;
for (i = 0; i < GetText12StringLen(); i += 2)
{
if(j == 0) stable += " ";
stable += "0x" + text12.value.substr(i, 2);
if(i < (GetText12StringLen() - 2)) {
stable += ", ";
j ++;
if(j == 16) {
stable += '\r\n';
j = 0;
}
}
}
stable += '\r\n}';
}
}
stable += ";//特别注意Keil C51请用code替换const\r\n";
stable += " ";
if((crcnuml + crcnumh) <= 8){
stable += "crc = ";
}
stable += funcName + "((unsigned char *)dataTable, sizeof(dataTable)";
if (idselecodemode.selectedIndex) stable += " - 1";
stable += ");\r\n";
if((crcnuml + crcnumh) > 8){
stable += " crchi = crch;\r\n";
stable += " crclo = crcl;\r\n";
}
stable += "//表格函数返回crc=0x" + fucstring;
if(crcvalue == fucstring){
stable += ",与HotWC3运算相同";
}
else{
stable += ",HotWC3运算crc=0x" + crcvalue;
}
if(errstring) stable += "。验证失败!" + errstring;
stable += "\r\n";
if((crcnuml + crcnumh) > 8){
stable += " while(crchi | crclo | 1);//死循环,请在此处设置断点,验证函数返回值crc是否正确!!!\r\n";
}
else{
stable += " while(crc | 1);//死循环,请在此处设置断点,验证函数返回值crc是否正确!!!\r\n";
}
stable += " return 0;\r\n";
stable += "}\r\n";
}
if(languagesele.value == ".SIM"){
stable += GetCRCTableArrayFunctionEx(crcvalue, BitSize, 1);
}
idTextBox.value = stable;
ChangeidTextBox();
if (languagesele.value == ".C" || languagesele.value == ".SIM") {
if((errstring == "") && (crcvalue == fucstring)){
if(confirm(crcName + "多项式表格和C语言都已通过模拟验证,请放心使用!!!"+"\n需要将其复制到剪切板上吗???")){
texteditclipboard();//
}
}
else{
alert(crcName + "多项式表格已通过验证!!!\n表格函数与HotWC3运算模拟验证失败!!!\n" + errstring);
}
}
else {
if(confirm(crcName + "多项式表格已通过验证,请放心使用!!!"+"\n需要将其复制到剪切板上吗???")){
texteditclipboard();//
}
}
}
var g_text12_count = 0;
function clearinputtext()
{
switch(g_text12_count & 3)
{
case 0:
case 1:
g_text12_Storage = StringInvertlToString(g_text12_Storage);//反序
text12.value = g_text12_Storage;
break;
case 2:
text12.value = "";
g_text12_count++;
break;
}
g_text12_count++;
}
function clearoutputtext()
{
if(idoutputtext.value != "采集"){
if (text13.value != "") text13.value = "";
else {
getcrcrandom13();
}
}
else if (text13.value != "") {
var crcbits, crcnum;
var str, ptr;
var len, i;
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;//取CRCn
str = text13.value;
len = str.length;
if(len % crcnum == 0){
ptr = "";
for(i = 0;i < len;i += crcnum){
ptr += StringReversalToString(str.substr(i, crcnum));
}
text13.value = ptr;
}
}
}
function Changeresulttext()
{
if(operatorsele.selectedIndex == 0)
{
text140.value = HexStringFormat(text140.value);
if((text140.value.length > 0 ) && (text140.value.length != GetCRCTableArrayBitsInt() / 4))
{
alert("结果位数不对!!!");
}
}
}
function GetCRCNxTabSelect()
{
var selindex;
/*
selindex=000单表大表
selindex=001单表小表
selindex=010双表大表
selindex=011双表小表
selindex=100算法大表
selindex=101算法小表
*/
selindex = (crcnxsele.selectedIndex << 1) | (crctabsele.selectedIndex & 1);
return selindex;
}
function clearresulttext()
{
var str = text140.value;
switch(text140Count){
case 0://小端
str = text140text;
str = StringDisInvertlToString(str);
break;
case 1://大端反转
str = text140text;
str = StringReversalToString(str);
break;
case 2://小端反转
str = text140text;
str = StringDisInvertlToString(str);
str = StringReversalToString(str);
break;
case 3://大端
str = text140text;
break;
}
text140Count++;
text140Count &= 3;
text140.value = str;
}
function clearpolytext()
{
SetCRCTableArraySelectedchecked();//选择HotCRC
SetCRCTableArrayPolyString(StringReversalToString(text130.value));//权值反转
WriteCRCTableArrayTextString();
}
function Changedisplayout()
{
if (displayout.checked){
displayoutlabel.style.color = "red";
}
else{
displayoutlabel.style.color = "blue";
}
}
function Changedischeck()
{
var str, len;
str = text150.value.toUpperCase();
len = str.length;
if (discheckbox.checked){
if(str.substr(len - 2, 2) != "+1") str += "+1";
}
else{
if(str.substr(len - 2, 2) == "+1") str = str.substr(0, len - 2);
}
text150.value = str;
SetCRCTableArrayPolyTextString();
WriteCRCTableArrayTextString();
}
function Changepolytext()
{
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
if(!patrn.test(text130.value)) {
alert("请输入16进制数!!!");
text130.value = GetCRCTableArrayPolyString();
}
else {
text130.value = text130.value.toUpperCase();
if (text130.value.length == GetCRCTableArrayBitsInt() / 4)
{
SetCRCTableArrayPolyString(text130.value);
WriteCRCTableArrayTextString();
}
else
{
alert("出值位数不对!!!");
text130.value = GetCRCTableArrayPolyString();
text130.value.focus();
text130.value.select();
}
}
text140Count = 0;
text140text = text140.value;
}
function clearstrikbittext()
{
var crcbits, crcnum;
var str, ptr;
var len;
if(!discheckbox.checked) {
alert("CRC不可逆!!!无法制造出CRC碰撞!!!");
return;
}
operatorsele.selectedIndex = 0;//CRC基本运算
idbcalculator.value = "运算";
idbrevert.value = "还原";
strikbittext.value = "0";
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;//取CRCn
str = text13.value;
len = str.length;
if (len > crcnum) {
ptr = "";
for (i = 0; i < len - crcnum; i ++){
ptr += getrandomnum(1);
}
text13.value = ptr + str.substr(len - crcnum, crcnum);
}
else alert("不可能发生CRC碰撞!!!");
revert();//还原即可碰撞
}
function XXEncodeToHex(hexstring)
{
var i, hexstr;
hexstr = "";
for (i = 0; i < hexstring.length; i += 6)
{
hexstr += XXEncodeToHexStr(hexstring.substr(i, 6));
}
return hexstr;//输出4N个字符
}
function XXEncodeToHexStr(hexstr)
{
var i, len, c, a, t, x1, x2, x3, x4, encode, hexstring;
var basestr = "+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=";
len = Math.min(hexstr.length, 6);//输入3个字节
encode = hexstr.substr(0, 6);
hexstring = "";
for (i = len; i < 6; i ++)
{
encode += "0";
}
if(len & 1) len ++;
c = hextoint(encode.substr(0, 2));
a = hextoint(encode.substr(2, 2));
t = hextoint(encode.substr(4, 2));
if(len == 6) {
x1 = c >>> 2;
x2 = ((c & 0x03) << 4) | (a >>> 4);
x3 = ((a & 0x0f) << 2) | (t >>> 6);
x4 = t & 0x3f;
hexstring = inttohex(basestr.charCodeAt(x1), 2);
hexstring += inttohex(basestr.charCodeAt(x2), 2);
hexstring += inttohex(basestr.charCodeAt(x3), 2);
hexstring += inttohex(basestr.charCodeAt(x4), 2);
}
else if(len == 4) {
x1 = c >>> 2;
x2 = ((c & 0x03) << 4) | (a >>> 4);
x3 = (a & 0x0f) << 2;
hexstring = inttohex(basestr.charCodeAt(x1), 2);
hexstring += inttohex(basestr.charCodeAt(x2), 2);
hexstring += inttohex(basestr.charCodeAt(x3), 2);
hexstring += inttohex(basestr.charCodeAt(64), 2);//=
}
else if(len == 2) {
x1 = c >>> 2;
x2 = (c & 0x03) << 4;
hexstring = inttohex(basestr.charCodeAt(x1), 2);
hexstring += inttohex(basestr.charCodeAt(x2), 2);
hexstring += inttohex(basestr.charCodeAt(64), 2);//=
hexstring += inttohex(basestr.charCodeAt(64), 2);//=
}
return hexstring;//输出4个字符
}
function HexToXXEncode(hexstr)
{
var i, str, hexstrString;
hexstrString = "";
for (i = 0; i < hexstr.length; i += 8)
{
hexstrString += HexStrToXXEncode(hexstr.substr(i, 8));
}
return hexstrString;//输出3N个字节
}
function HexStrToXXEncode(basehexstr)
{//输入4个字节
var c, a, t, x1, x2, x3, x4, str, hexstr;
str = HexToAscii(basehexstr);//4个字符
x1 = GetXXEncodeValue(str.substr(0, 1));
x2 = GetXXEncodeValue(str.substr(1, 1));
x3 = GetXXEncodeValue(str.substr(2, 1));
x4 = GetXXEncodeValue(str.substr(3, 1));
hexstr = "";
if(str.substr(3, 1) != "=") {
c = (x1 << 2) | (x2 >>> 4);
a = ((x2 & 0xf) << 4) | (x3 >>> 2);
t = ((x3 & 0x03) << 6) | x4;
hexstr = inttohex(c, 2);
hexstr += inttohex(a, 2);
hexstr += inttohex(t, 2);
}
else if(str.substr(2, 1) != "=") {
c = (x1 << 2) | (x2 >>> 4);
a = ((x2 & 0xf) << 4) | (x3 >>> 2);
hexstr = inttohex(c, 2);
hexstr += inttohex(a, 2);
}
else {
c = (x1 << 2) | (x2 >>> 4);
hexstr = inttohex(c, 2);
}
return hexstr;//输出3个字节
}
function GetXXEncodeValue(ch)
{
var value = 0;
if((ch >= "A") && (ch <= "Z")) {
value = ch.charCodeAt(0) - 0x41 + 12;
}
else if((ch >= "a") && (ch <= "z")) {
value = ch.charCodeAt(0) - 0x61 + 12 + 26;
}
else if((ch >= "0") && (ch <= "9")) {
value = ch.charCodeAt(0) - 0x30 + 2;
}
else if(ch == "+") {
value = 0;
}
else if(ch == "-") {
value = 1;
}
return value;
}
function Base64ToHex(hexstring)
{
var i, hexstr;
hexstr = "";
for (i = 0; i < hexstring.length; i += 6)
{
hexstr += Base64ToHexStr(hexstring.substr(i, 6));
}
return hexstr;//输出4N个字符
}
function Base64ToHexStr(hexstr)
{
var i, len, c, a, t, x1, x2, x3, x4, encode, hexstring;
var basestr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
len = Math.min(hexstr.length, 6);//输入3个字节
encode = hexstr.substr(0, 6);
hexstring = "";
for (i = len; i < 6; i ++)
{
encode += "0";
}
if(len & 1) len ++;
c = hextoint(encode.substr(0, 2));
a = hextoint(encode.substr(2, 2));
t = hextoint(encode.substr(4, 2));
if(len == 6) {
x1 = c >>> 2;
x2 = ((c & 0x03) << 4) | (a >>> 4);
x3 = ((a & 0x0f) << 2) | (t >>> 6);
x4 = t & 0x3f;
hexstring = inttohex(basestr.charCodeAt(x1), 2);
hexstring += inttohex(basestr.charCodeAt(x2), 2);
hexstring += inttohex(basestr.charCodeAt(x3), 2);
hexstring += inttohex(basestr.charCodeAt(x4), 2);
}
else if(len == 4) {
x1 = c >>> 2;
x2 = ((c & 0x03) << 4) | (a >>> 4);
x3 = (a & 0x0f) << 2;
hexstring = inttohex(basestr.charCodeAt(x1), 2);
hexstring += inttohex(basestr.charCodeAt(x2), 2);
hexstring += inttohex(basestr.charCodeAt(x3), 2);
hexstring += inttohex(basestr.charCodeAt(64), 2);//=
}
else if(len == 2) {
x1 = c >>> 2;
x2 = (c & 0x03) << 4;
hexstring = inttohex(basestr.charCodeAt(x1), 2);
hexstring += inttohex(basestr.charCodeAt(x2), 2);
hexstring += inttohex(basestr.charCodeAt(64), 2);//=
hexstring += inttohex(basestr.charCodeAt(64), 2);//=
}
return hexstring;//输出4个字符
}
function HexToBase64(hexstr)
{
var i, str, hexstrString;
hexstrString = "";
for (i = 0; i < hexstr.length; i += 8)
{
hexstrString += HexStrToBase64(hexstr.substr(i, 8));
}
return hexstrString;//输出3N个字节
}
function HexStrToBase64(basehexstr)
{//输入4个字节
var c, a, t, x1, x2, x3, x4, str, hexstr;
str = HexToAscii(basehexstr);//4个字符
x1 = GetBase64Value(str.substr(0, 1));
x2 = GetBase64Value(str.substr(1, 1));
x3 = GetBase64Value(str.substr(2, 1));
x4 = GetBase64Value(str.substr(3, 1));
hexstr = "";
if(str.substr(3, 1) != "=") {
c = (x1 << 2) | (x2 >>> 4);
a = ((x2 & 0xf) << 4) | (x3 >>> 2);
t = ((x3 & 0x03) << 6) | x4;
hexstr = inttohex(c, 2);
hexstr += inttohex(a, 2);
hexstr += inttohex(t, 2);
}
else if(str.substr(2, 1) != "=") {
c = (x1 << 2) | (x2 >>> 4);
a = ((x2 & 0xf) << 4) | (x3 >>> 2);
hexstr = inttohex(c, 2);
hexstr += inttohex(a, 2);
}
else{
c = (x1 << 2) | (x2 >>> 4);
hexstr = inttohex(c, 2);
}
return hexstr;//输出3个字节
}
function GetBase64Value(ch)
{
var value = 0;
if((ch >= "A") && (ch <= "Z")) {
value = ch.charCodeAt(0) - 0x41;
}
else if((ch >= "a") && (ch <= "z")) {
value = ch.charCodeAt(0) - 0x61 + 26;
}
else if((ch >= "0") && (ch <= "9")) {
value = ch.charCodeAt(0) - 0x30 + 52;
}
else if(ch == "+") {
value = 62;
}
else if(ch == "/") {
value = 63;
}
return value;
}
function UUEncodeToHex(hexstring)
{
var i, hexstr;
hexstr = "";
for (i = 0; i < hexstring.length; i += 6)
{
hexstr += UUEncodeToHexStr(hexstring.substr(i, 6));
}
return hexstr;//输出4N个字符
}
function UUEncodeToHexStr(hexstr)
{
var i, len, c, a, t, x1, x2, x3, x4, encode, hexstring;
var basestr = "";
for(i = 32;i <=96;i ++) basestr += String.fromCharCode(i);
len = Math.min(hexstr.length, 6);//输入3个字节
encode = hexstr.substr(0, 6);
hexstring = "";
for (i = len; i < 6; i ++)
{
encode += "0";
}
if(len & 1) len ++;
c = hextoint(encode.substr(0, 2));
a = hextoint(encode.substr(2, 2));
t = hextoint(encode.substr(4, 2));
if(len == 6) {
x1 = c >>> 2;
x2 = ((c & 0x03) << 4) | (a >>> 4);
x3 = ((a & 0x0f) << 2) | (t >>> 6);
x4 = t & 0x3f;
hexstring = inttohex(basestr.charCodeAt(x1), 2);
hexstring += inttohex(basestr.charCodeAt(x2), 2);
hexstring += inttohex(basestr.charCodeAt(x3), 2);
hexstring += inttohex(basestr.charCodeAt(x4), 2);
}
else if(len == 4) {
x1 = c >>> 2;
x2 = ((c & 0x03) << 4) | (a >>> 4);
x3 = (a & 0x0f) << 2;
hexstring = inttohex(basestr.charCodeAt(x1), 2);
hexstring += inttohex(basestr.charCodeAt(x2), 2);
hexstring += inttohex(basestr.charCodeAt(x3), 2);
hexstring += inttohex(basestr.charCodeAt(64), 2);//=
}
else if(len == 2) {
x1 = c >>> 2;
x2 = (c & 0x03) << 4;
hexstring = inttohex(basestr.charCodeAt(x1), 2);
hexstring += inttohex(basestr.charCodeAt(x2), 2);
hexstring += inttohex(basestr.charCodeAt(64), 2);//=
hexstring += inttohex(basestr.charCodeAt(64), 2);//=
}
return hexstring;//输出4个字符
}
function HexToUUEncode(hexstr)
{
var i, str, hexstrString;
hexstrString = "";
for (i = 0; i < hexstr.length; i += 8)
{
hexstrString += HexStrToUUEncode(hexstr.substr(i, 8));
}
return hexstrString;//输出3N个字节
}
function HexStrToUUEncode(basehexstr)
{//输入4个字节
var c, a, t, x1, x2, x3, x4, str, hexstr;
str = HexToAscii(basehexstr);//4个字符
x1 = GetUUEncodeValue(str.substr(0, 1));
x2 = GetUUEncodeValue(str.substr(1, 1));
x3 = GetUUEncodeValue(str.substr(2, 1));
x4 = GetUUEncodeValue(str.substr(3, 1));
hexstr = "";
if(str.substr(3, 1) != "`") {
c = (x1 << 2) | (x2 >>> 4);
a = ((x2 & 0xf) << 4) | (x3 >>> 2);
t = ((x3 & 0x03) << 6) | x4;
hexstr = inttohex(c, 2);
hexstr += inttohex(a, 2);
hexstr += inttohex(t, 2);
}
else if(str.substr(2, 1) != "`") {
c = (x1 << 2) | (x2 >>> 4);
a = ((x2 & 0xf) << 4) | (x3 >>> 2);
hexstr = inttohex(c, 2);
hexstr += inttohex(a, 2);
}
else {
c = (x1 << 2) | (x2 >>> 4);
hexstr = inttohex(c, 2);
}
return hexstr;//输出3个字节
}
function GetUUEncodeValue(ch)
{
var value = 0;
if((ch >= " ") && (ch <= "_")) {
value = ch.charCodeAt(0) - 0x20;
}
return value;
}
function QPCodeToHex(hexstring) {
var i, value, str, hexstr;
hexstr = "";
for (i = 0; i < hexstring.length; i += 2)
{
value = hextoint(hexstring.substr(i, 2));
if ((value >= 33 && value <= 60) || (value >= 62 && value <= 126)) {
str = String.fromCharCode(value);
}
else {
str = "=" + hexstring.substr(i, 2);
}
hexstr += str;
}
hexstr= AsciiToHex(hexstr);
return hexstr;
}
function HexToQPCode(hexstr) {
var i, str, value, ch ,hexstrString;
hexstrString = "";
i = 0;
while(i < hexstr.length)
{
str = hexstr.substr(i, 2);
value = hextoint(str);
ch = String.fromCharCode(value);
if(ch != "=") {
i += 2;
}
else {
ch = hexstr.substr(i + 2, 4);
str = HexToAscii(ch);
i += 6;
}
hexstrString += str;
}
return hexstrString;//输出3N个字节
}
function CodeStringToHex(codestr, index) {
var str = "";
switch(index) {
case 0://hex
str = HexStringFormat(codestr);//???
break;
case 1://ascii
str = AsciiToHex(codestr);
break;
case 2://gb2312-80
str = GB2312ToHex(codestr);
break;
case 3://unicode
str = UniCodeToHex(codestr);
break;
case 4://utf-8
str = UTF_8ToHex(codestr);
break;
case 5://hotcode
str = HotCodeToHex(codestr);
break;
case 6://base64
str = HotCodeToHex(codestr);
str = Base64ToHex(str);
break;
case 7://UUEncode
str = HotCodeToHex(codestr);
str = UUEncodeToHex(str);
break;
case 8://XXEncode
str = HotCodeToHex(codestr);
str = XXEncodeToHex(str);
break;
case 9://Quoted-printable
str = HotCodeToHex(codestr);
str = QPCodeToHex(str);
break;
}
return str;
}
function HexToCodeString(hexstr, index) {
var str = "";
switch(index) {
case 0://Hex
str = hexstr;
break;
case 1://ascii
str = HexToAscii(hexstr);
break;
case 2://gb2312-80
str = HexToGB2312(hexstr);
break;
case 3://unicode
str = HexToUniCode(hexstr);
break;
case 4://utf-8
str = HexToUTF_8(hexstr);
break;
case 5://hotcode
str = HexToHotCode(hexstr);
break;
case 6://base64
str = HexToBase64(hexstr);
str = HexToHotCode(str);
break;
case 7://UUEncode
str = HexToUUEncode(hexstr);
str = HexToHotCode(str);
break;
case 8://XXEncode
str = HexToXXEncode(hexstr);
str = HexToHotCode(str);
break;
case 9://Quoted-printable
str = HexToQPCode(hexstr);
str = HexToHotCode(str);
break;
}
return str;
}
function HotWC3OutputModeStringTest()
{
var str;
var n, len, index;
var strArray = new Array();
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
var valArray = new Array();
var result = false;
str = wc3output.value;//取密文流
if(str.length == 0) {
alert("密文是空的不能解密!!!");
}
else{
if(TestIE()) strArray = str.split("\r\n");
else strArray = str.split("\n");
for(n = strArray.length - 1;n >= 0;n--){
str = strArray[n];//取组密文
if(str.substr(0, 3) == "***"){//查找密钥和编码格式
str = StringRight(str, str.length - 3);
if(TestHotWC3Password(str)){
if(setHotWC3Password(str)){
alert("请注意:新密码已设置成功!!!");
}
}
}
}
index = idseleoutmode.selectedIndex;
for(n = 0; n < strArray.length; n++){
str = strArray[n];//取组密文
len = str.length;
if(str.substr(0, 3) == "==="){//CRC32
if(!((len == 11) && patrn.test(str.substr(3, len - 3)))){//CRC32格式错误
alert("第" + (n + 1) + "行密文" + idseleoutmode.value + "编码输出CRC格式错误!!!");
return result;
}
hotwc3CRC32checkbox.checked = true;
}
else if(str.substr(0, 3) == "***"){//128位密钥
str = StringRight(str, str.length - 3);
if(TestHotWC3Password(str)){
setHotWC3Password(str);//设置新密码
}
}
else if(str.substr(0, 3) == "???"){
break;//标题退出
}
else{
//密文测试
result = HotWC3OutputModeTest(str, index);
if(!result){
alert("第" + (n + 1) + "行密文" + idseleoutmode.value + "编码输出格式错误!!!");
return result;
}
else{
//长度判断
switch(index) {
case 0://hex
result = (len & 1) == 0;//两个字节
break;
case 1://base64
case 2://UUEncode
case 3://XXEncode
result = (len & 3) == 0;//四个字节
break;
case 4://Quoted-printable
result = true;//很难判断
break;
}
if(!result) {
alert("第" + (n + 1) + "行密文" + idseleoutmode.value + "编码输出长度错误!!!");
return result;
}
}
}
}
}
return result;
}
function HotWC3OutputModeTest(codestr, index)
{
var result = false;
switch(index) {
case 0://hex
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
break;
case 1://base64
// var patrn = /^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=]+$/;//正则表达式
var patrn = /^[A-Za-z0-9+/=]+$/;//正则表达式
break;
case 2://UUEncode
// var patrn = /^[ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`]+$/;//正则表达式
var patrn = /^[\x20-\x60]+$/;//正则表达式
break;
case 3://XXEncode
var patrn = /^[+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=]+$/;//正则表达式
// var patrn = /^[+-0-9A-Za-z=]+$/;//正则表达式
break;
case 4://Quoted-printable
var patrn = /^[\x21-\x7e]+$/;//正则表达式
break;
case 5://
return true;
break;
}
if(codestr.length == 0) result = true;
else result = patrn.test(codestr);
return result;
}
function CodeStringExToHex(codestr, index) {
var str = "";
switch(index) {
case 0://hex
str = codestr;
break;
case 1://base64
str = Base64ToHex(codestr);
break;
case 2://UUEncode
str = UUEncodeToHex(codestr);
break;
case 3://XXEncode
str = XXEncodeToHex(codestr);
break;
case 4://Quoted-printable
str = QPCodeToHex(codestr);
break;
case 5://BASE4096
str = codestr;
break;
}
return str;
}
function HexToCodeExString(hexstr, index) {
var str = "";
switch(index) {
case 0://Hex
str = hexstr;
break;
case 1://base64
str = HexToBase64(hexstr);
break;
case 2://UUEncode
str = HexToUUEncode(hexstr);
break;
case 3://XXEncode
str = HexToXXEncode(hexstr);
break;
case 4://Quoted-printable
str = HexToQPCode(hexstr);
break;
case 5://BASE4096
str = hexstr;
break;
}
return str;
}
function StringToHex(stringstr) {
var hexstr;
var i, num;
hexstr = "";
for(i = 0;i < stringstr.length; i++) {
num = stringstr.charCodeAt(i);
hexstr += inttohex(num, 2);
}
return hexstr;
}
function AsciiToHex(asciistr) {
var hexstr;
var i, num;
hexstr = "";
for(i = 0;i < asciistr.length; i++) {
num = asciistr.charCodeAt(i);
num &= 0x7f;
hexstr += inttohex(num, 2);
}
return hexstr;
}
function HexToString(hexstr) {
var str,stringstr;
var i, num;
stringstr = "";
for(i = 0;i < hexstr.length; i+=2) {
str = hexstr.substr(i, 2);
num = hextoint(str);
stringstr += String.fromCharCode(num);
}
return stringstr;
}
function HexToAscii(hexstr) {
var str,asciistr;
var i, num;
asciistr = "";
for(i = 0;i < hexstr.length; i+=2) {
str = hexstr.substr(i, 2);
num = hextoint(str);
num &= 0x7f;
asciistr += String.fromCharCode(num);
}
return asciistr;
}
function GB2312ToHex(asciistr) {
var str,hexstr;
var i, num;
hexstr = "";
i = 0;
while(i < asciistr.length) {
num = asciistr.charCodeAt(i);
if(num < 0x80) {
hexstr += inttohex(num, 2);
}
else {
if(TestIE()) {
str = asciistr.substr(i, 2);
hexstr += AscToHexString(str);
}
i ++;
}
i ++;
}
return hexstr;
}
function HexToGB2312(hexstr) {
var str,asciistr;
var i, num;
gb2312str = "";
i = 0;
while(i < hexstr.length) {
str = hexstr.substr(i, 2);
num = hextoint(str);
if (num < 0x80) {
if(num == 0) break;//0字符不解码
gb2312str += String.fromCharCode(num);
}
else {
if(TestIE()) {
str = hexstr.substr(i, 4);
gb2312str += HexToAscString(str);
}
i += 2;
}
i+=2;
}
return gb2312str;
}
function UniCodeToHex(unicodestr) {
var str,hexstr;
var i, num;
hexstr = "";
str = unicodestr;
for(i = 0;i < str.length; i++) {
num = str.charCodeAt(i);
hexstr += inttohex(num, 4);
}
return hexstr;
}
function HexToUniCode(hexstr) {
var str,uncodestr;
var i, num;
uncodestr = "";
for(i = 0;i < hexstr.length; i+=4) {
str = hexstr.substr(i, 4);
num = hextoint(str);
uncodestr += String.fromCharCode(num);
}
uncodestr = unescape(uncodestr);
return uncodestr;
}
function UTF_8ToHex(codestr) {
var str,hexstr;
var i, num;
hexstr = "";
str = encodeURIComponent(codestr);
// str = encodeURI(codestr);
i = 0;
while(i < str.length)
{
num = str.charCodeAt(i);
if(num != 0x25) {
hexstr += inttohex(num, 2);
i ++;
}
else {
hexstr += str.substr(i + 1, 2);
i += 3;
}
}
return hexstr;
}
function HexToUTF_8(hexstr) {
var str,ch,uncodestr;
var i, num;
var patrn = /[!`()*-._0-9a-zA-Z]/;//encodeURIComponent()正则表达式
//var patrn = /[!#[ DISCUZ_CODE_8 ]amp;'()*+,-./:;=?@_~0-9a-zA-Z]/;//encodeURI()正则表达式
uncodestr = "";
for(i = 0;i < hexstr.length; i+=2) {
str = hexstr.substr(i, 2);
num = hextoint(str);
if(num == 0) break;//0字符不解码
ch = String.fromCharCode(num);
if(patrn.test(ch)){
uncodestr += ch;
}
else {
uncodestr += "%" + str;
}
}
uncodestr = decodeURIComponent(uncodestr);
// uncodestr = decodeURI(uncodestr);
return uncodestr;
}
function HexToBase4096(hexstr) {
var str,ptr,ch,uncodestr;
var i, j, num;
uncodestr = "";
for(i = 0;i < hexstr.length; i+=6) {//三个字节
str = hexstr.substr(i, 6);
str = StringLeft0(str, 6);
ptr = str.substr(2, 1);
ptr += str.substr(0, 2);
num = hextoint(ptr);
num += 0xae00;
ptr = inttohex(num, 4);
uncodestr += HexToHotCode(ptr);
ptr = str.substr(3, 1);
ptr += str.substr(4, 2);
num = hextoint(ptr);
num += 0xae00;
ptr = inttohex(num, 4);
uncodestr += HexToHotCode(ptr);
}
// uncodestr = unescape(uncodestr);
return uncodestr;
}
function Base4096ToHex(hotcodestr) {
var str, ptr, ctr, i, j, num, hexstr;
hexstr = HotCodeToHex(hotcodestr);
str = "";
for(i = 0;i < hexstr.length;i +=8) {
num = hextoint(hexstr.substr(i, 4)) - 0xae00;
ptr = inttohex(num, 4);
ctr = ptr.substr(2, 2) + ptr.substr(1, 1);
num = hextoint(hexstr.substr(i + 4, 4)) - 0xae00;
ptr = inttohex(num, 4);
ctr += ptr.substr(1, 1) + ptr.substr(2, 2);
while(ctr.substr(ctr.length - 2, 2) == "00"){
ctr = ctr.substr(0, ctr.length - 2);
}
str += ctr;
}
return str;
}
function HotCodeToHex(hotcodestr) {
var str,ptr,hexstr;
var i, num;
hexstr = "";
str = hotcodestr;
i = 0;
for(i = 0;i < str.length;i ++) {
num = str.charCodeAt(i);
if(num < 0x80) {//字符,.[]-+
hexstr += inttohex(num, 2);
}
else if(num < 0x100){
num -= (0x0080 - 0x2580);//0x80-0x80+2580
num += 0x6000;
hexstr += inttohex(num, 4);
}
else {//汉字
if(num >= 0xff00) {//全角ascii,全角中英文标点等
num -= (0xff00 - 0x2800);
}
else if (num >= 0xfe30 && num <= 0xfe4f) {
num -= (0xfe30 - 0x9fc0);
}
else if (num >= 0xf900 && num <= 0xfaff) {
num -= (0xf900 - 0x2c00);
}
else if (num >= 0x2000 && num <= 0x9fff) {
}
else {
num = 0x3000;//空格
}
num += 0x6000;
ptr = inttohex(num, 4);
hexstr += ptr;
}
}
return hexstr;
}
function HexToHotCode(hexstr) {
var str,hotcodestr;
var i, num;
hotcodestr = "";
i = 0;
while(i < hexstr.length) {
str = hexstr.substr(i, 2);
num = hextoint(str);
if (num < 0x80) {//
if(num == 0) break;//0字符不解码
hotcodestr += String.fromCharCode(num);
i += 2;
}
else {
str = hexstr.substr(i, 4);
num = hextoint(str);
num -= 0x6000;
if (num > 0x2580 && num <= 0x25ff) {
num -= (0x2580 - 0x0080);
}
else {
if (num > 0x2800 && num <= 0x28ff) {
num -= (0x2800 - 0xff00);
}
else if (num > 0x9fc0 && num <= 0x9fdf) {
num -= (0x9fc0 - 0xfe30);
}
else if (num > 0x2c00 && num <= 0x2dff) {
num -= (0x2c00 - 0xf900);
}
}
hotcodestr += String.fromCharCode(num);
i += 4;
}
}
return hotcodestr;
}
function LoadDateTextString(){
//得到日期密钥HotWC3TextString_0_3.value
var century, year, month, day, week, daycount;
var tiangan, dizhi;//天干,地支
var tgstr, distr;
var value,str;
//pwy?? if(!checkconvert.checked) return;//不从日期中换算出:天地密钥,星期密钥,三角密钥,日期密钥,HotWC3是标准的128位密码体系
//下面是从日期(22位密码)中换算出:天地密钥,星期密钥,三角密钥,日期密钥,HotWC3是非标准的86位密码体系
//取10进制格式的日期:百年,十年,月日
century = parseInt(year1000.value) * 10 + parseInt(year100.value);//0~99
year = parseInt(year10.value) * 10 + parseInt(year1.value);//0~99
month = parseInt(monthselect.value);//1~12
day = parseInt(dayselect.value);//1~31
str = inttohex((Math.floor(century / 10) << 4) | (century % 10), 2);
str += inttohex((Math.floor(year / 10) << 4) | (year % 10), 2);
str += inttohex((Math.floor(month / 10) << 4) | (month % 10), 2);
str += inttohex((Math.floor(day / 10) << 4) | (day % 10), 2);
SetCRCTextString(0, 3, str);//日期密钥
}
function HotWC3LoadProc()
{
document.write('<h3>雁塔菜农HotPower@163.com 2023.3.18于西安雁塔菜地</h3>');
document.write('<input type="file" id="idHotWC3File" onchange="HotWC3HandleFiles()" style="display:none">');
document.write('<input type="file" id="idHotWC3FileEx" onchange="HotWC3HandleFilesEx()" style="display:none">');
document.write('<input type="file" id="idCRCFile" onchange="CRCHandleFiles()" style="display:none">');
document.write('<input type="file" id="idHexFile" onchange="HexHandleFiles()" style="display:none">');
/////////////////////////
year1000.selectedIndex = parseInt(datevar.getFullYear() / 1000);
year100.selectedIndex = parseInt((datevar.getFullYear() / 100) % 10);
year10.selectedIndex = parseInt((datevar.getFullYear() / 10) % 10);
year1.selectedIndex = parseInt(datevar.getFullYear() % 10);
monthselect.selectedIndex = parseInt(datevar.getMonth());
dayselect.selectedIndex = parseInt(datevar.getDate() - 1);
radioTextMode.checked = true;
MakeCRCXXXXLPolyTextString();
LoadPasswordTable();
LoadCRCTextString(8);//标题只读
LoadCRCTextString(7);//装载1024位HotWC3密码的密钥
hotwc3();//HotWC3初始密钥推导过程(推导出:日期密钥,天地密钥,星期密钥,三角密钥)
// text160.value = "CRC16L_1021_FFFF_0000";
// formattext160();
// hotcrc();//运算
WriteCRCTableArrayTextString();//选择CRC16_CCITT
localStoragecheckbox.checked = TestLS();
if(localStoragecheckbox.checked){
localStoragelabel.style.color = "red";
lbhotwc3browsecount.style.color = "red";
}
else{
localStoragelabel.style.color = "blue";
lbhotwc3browsecount.style.color = "blue";
}
filecheckbox.checked = TestIE() || TestFILE();
if(filecheckbox.checked){
filelabel.style.color = "red";
}
else{
filelabel.style.color = "blue";
}
iecheckbox.checked = TestIE();
if(TestIE()){
TestHotWC3Folder();
}
if(iecheckbox.checked){
ielabel.style.color = "red";
}
else{
ielabel.style.color = "blue";
}
hotwc3wificheckbox.checked = TestWF();
hotwc3onlinecheckbox.checked = TestOL();
if(hotwc3onlinecheckbox.checked){
hotwc3onlinelabel.style.color = "red";
hotwc3onlinelabel.innerHTML = "在线";
HotWC3Countlabel.style.color = "red";
}
else{
hotwc3onlinelabel.style.color = "blue";
hotwc3onlinelabel.innerHTML = "离线";
HotWC3Countlabel.style.color = "blue";
}
ioscheckbox.checked = TestiOS();
if(ioscheckbox.checked){
ioslabel.style.color = "red";
}
else{
ioslabel.style.color = "blue";
}
adrcheckbox.checked = TestAdr();
if(adrcheckbox.checked){
adrlabel.style.color = "red";
}
else{
adrcheckbox.style.color = "blue";
}
wincheckbox.checked = TestWIN();
if(wincheckbox.checked){
winlabel.style.color = "red";
}
else{
winlabel.style.color = "blue";
}
setInterval(systimeout, 1000);//实时钟,苹果不行???
wc3input.value = "推荐关注菜农微信公众号:菜农工具!";
hotwc3passex();//加密
hotwc3Keycheckbox.checked = false;
wc3input.value = "请点击解密看看菜农说些什么?";
ChangeidinputHotWC3TextBox();
if(!TestCRCTableArrayPolyArray()){
alert("HotCRCPolyTableArray[]表格被改写!请看主编辑框内的序号修复!!!");
}
selebuttonhelp();
UpdateCRCTextString(0);//选择CRC0
// HotWC3WindowsMenu(0, 1);//主界面
HotWC3WindowsMenu(3, 1);//CRC计算器
if(TestLS()){
if(localStorage["HotWC3_HotPower"] != "19591119"){
localStorage["HotWC3_HotPower"] = "19591119";
localStorage["HotWC3_Count"] = 1;
alert("欢迎您首次使用HotWC3,欢迎光临指导!!!");
}
else{
localStorage["HotWC3_Count"]++;
}
hotwc3browsecount.value=localStorage["HotWC3_Count"];
}
// HotWC3Ajax("", "HotWC3_Count", 250);//调试
HotWC3Ajax("HotWC3Count", "HotWC3_Count", 250);//计数器,读写CSV文件
//alert(GetHotWC3CRCPolyWorkString("CRC4L_3_0_0", "1", 0));
//alert(StringXORToStringLeft("F","3"));
//alert(StringMoveToStringLeft("1234", 1));
}
function GetHotWC3BrowseCount()
{
EditDisplayworkfieldset.style.display = "";//编辑显示
HotWC3Ajax("idTextBox", "HotWC3_Count", 888);//读CSV文件
}
function LoadHotCRCPolyTableArray(str)
{
if(TestCRCTableArrayPolyArrayString(str)){
HotCRCPolyTableArray.length++;
HotCRCPolyTableArray[HotCRCPolyTableArray.length - 1] = str;
}
else{
alert("装载HotCRCPolyTableArray[" + "\"" + str + "\"]表格错误!!!");
}
}
function TestHotWC3Folder()
{
var foldername = "C:\\HotWC3";
var err;
if(!FolderExists(foldername)){
CreateFolder(foldername);
if(TestLS()){
if(!localStorage["HotWC3_Folder"]){
localStorage["HotWC3_Folder"] = foldername;
}
}
}
return;
}
function FolderExists(foldername)
{
var Fso;
var strfoldername;
Fso = new ActiveXObject("Scripting.FileSystemObject");
try{
strfoldername = Fso.GetFolder(foldername);
}
catch(exception)
{
switch(exception.number)
{
case -2146828212://路径未找到
strfoldername = "";
break;
default://其它所有错误
strfoldername = "";
break;
}
}
return (strfoldername != "");
}
function CreateFolder(foldername)
{
var Fso;
Fso = new ActiveXObject("Scripting.FileSystemObject");
Fso.CreateFolder(foldername);
return (FolderExists(foldername) != "");
}
function DeleteFolder(foldername)
{
var Fso;
Fso = new ActiveXObject("Scripting.FileSystemObject");
Fso.DeleteFolder(foldername);
return (FolderExists(foldername) == "");
}
function FileExists(filename)
{
var Fso;
Fso = new ActiveXObject("Scripting.FileSystemObject");
return Fso.FileExists(filename);
}
function FileDelete(filename)
{
var Fso, txtFile;
Fso = new ActiveXObject("Scripting.FileSystemObject");
txtFile = Fso.GetFile(filename);
txtFile.Delete();
}
function ReadFile(filename)
{
var str;
var Fso, txtFile;
Fso = new ActiveXObject("Scripting.FileSystemObject");
txtFile = Fso.OpenTextFile(filename, 1);
str = txtFile.ReadAll();
txtFile.Close();
return str;
}
function WriteFile(filename, str)
{
var Fso, txtFile;
Fso = new ActiveXObject("Scripting.FileSystemObject");
txtFile = Fso.OpenTextFile(filename, 2, 1);
txtFile.write(str);
txtFile.Close();
}
function crcpolysettimeoutxxx()
{
var str, ptr;
var strArray = new Array();
var valArray = new Array();
//取出需要初值碰撞的参数
str = _text_array[_count_argc];//穷举初值碰撞
if(str.substr(str.length - 1, 1) == "!") {//穷举
str = str.substr(0, str.length - 1);
}
else {//放弃穷举
_count_argc++;//穷举初值碰撞指针
_count_argcx = 0;
if(_count_argc < _text_array.length) {//
setTimeoutID = setTimeout(crcpolysettimeoutxxx, 5);
}
else {
if(g_respolystring != "") {
text160.value = g_respolystring;
SetCRCTableArrayPolyFormatString();
WriteCRCTableArrayTextString();
}
var d = new Date();
idTextBox.value += "\n" + "穷举初值碰撞结束时间:" + d.toLocaleTimeString();
ChangeidTextBox();
idnxcrcstart.value = "穷举";
}
return;
}
//设置
strArray = str.split("_");
ptr = strArray[5];//取明文[0]+结果[1]+格式[2]
valArray = ptr.split("~");
text12.value = valArray[0];//明文
text140.value = valArray[1];//结果
_text140_value = valArray[1];//结果
_text120_value = strArray[2];//初值
strArray[3] = strArray[2];//覆盖出值
strArray.length--;
str = strArray.join("_");
str = str.substr(0, str.length - 1);
text160.value = str;//改写简写式
SetCRCTableArrayPolyFormatString();
setTimeoutID = setTimeout(crcpolysettimeoutyyy, 5);
}
function crcpolysettimeoutyyy()
{
var crcbits, crcnum;
var startvalue, val, i;
var str, ptr;
var strArray = new Array();
var valArray = new Array();
var tabArray = new Array(4);
var initpatrn = /^[05AF]+$/;//正则表达式
tabArray[0] = "0000000000000000";
tabArray[1] = "5555555555555555";
tabArray[2] = "AAAAAAAAAAAAAAAA";
tabArray[3] = "FFFFFFFFFFFFFFFF";
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
do {
if(idnxcrcstart.value == "穷举") {
var d = new Date();
idTextBox.value += "\n" + "结束时间:" + d.toLocaleTimeString();
ChangeidTextBox();
return;
}
// calculator();
hotcrc();//运算
if(_text140_value == text140.value) {//找到初值
str = _text_array[_count_argc];//穷举初值碰撞
strArray = str.split("_");
ptr = strArray[5];//取明文[0]+结果[1]+格式[2]
valArray = ptr.split("~");
if((_count_argcx == 0) && (valArray.length > 2)) {//$
idTextBox.value += "\n" + valArray[2].substr(0, valArray[2].length - 1);//参数
}
idTextBox.value += "\n" + text160.value;//简写式
if(discheckbox.checked) {
idTextBox.value += " CRC可逆";
}
else {
idTextBox.value += " CRC不可逆";
}
if(discheckbox.checked) {//可逆
idTextBox.value += "(穷举初值碰撞<" + _count_argc + ">)";//穷举初值碰撞
}
else{
idTextBox.value += "(穷举初值碰撞<" + _count_argc + "_" + _count_argcx + ">)";//穷举初值碰撞
}
if(initpatrnTest(text120.value) && initpatrnTest(text170.value)) {
if(g_respolystring == "") g_respolystring = text160.value;
idTextBox.value += "(可信度高!!!)";
}
_count_argcx++;
if(discheckbox.checked) {//可逆
_text120_value = text120.value;
break;
}
}//pwy?
text120.value = StringINCToString(text120.value);
SetCRCTableArrayInitString(text120.value);
if(text120.value.substr(crcnum - 1, 1) == "0") {
break;
}
}while(_text120_value != text120.value);
if(_text120_value != text120.value) {//初值不相等继续
setTimeoutID = setTimeout(crcpolysettimeoutyyy, 5);//继续穷举
}
else {
_count_argc++;//穷举初值碰撞
_count_argcx = 0;
if(_count_argc < _text_array.length) {//穷举初值碰撞
setTimeoutID = setTimeout(crcpolysettimeoutxxx, 5);//下一个碰撞
}
else {
if(g_respolystring != "") {
text160.value = g_respolystring;
SetCRCTableArrayPolyFormatString();
WriteCRCTableArrayTextString();
}
var d = new Date();
idTextBox.value += "\n" + "结束时间:" + d.toLocaleTimeString();
ChangeidTextBox();
idnxcrcstart.value = "穷举";
}
}
}
function crctextformat(crcstr)
{
var patrn = /^[\r 0-9a-fA-F]+$/;//正则表达式
var str,i, j;
var strArray = new Array();
var valArray = new Array();
var strArrayFormat= new Array();
str = "";
if(TestIE()) strArray = crcstr.split("\r\n");
else strArray = crcstr.split("\n");
j = 0;
for(i = 0;i < strArray.length;i ++)
{
if(strArray[i].length > 0) {//去掉空行
if(patrn.test(strArray[i])){//16进制数
strArrayFormat[j++] = HexStringFormat(strArray[i]);
}
else if(strArray[i].substr(0, 1) == "[ DISCUZ_CODE_0 ]quot;) {//格式
strArrayFormat[j++] = strArray[i];
}
else if (strArray[i].substr(strArray[i].length - 1, 1) == "#" || strArray[i].substr(strArray[i].length - 1, 1) == "^") {//初值,变异//pwy
if(patrn.test(strArray[i].substr(0, strArray[i].length - 1))){
strArrayFormat[j++] = strArray[i].toUpperCase();
}
else if(strArray[i].indexOf("-") > 0){
valArray = strArray[i].split("-");
if(valArray.length == 2) {
if((valArray[0].length + 1) == valArray[1].length) {
if(patrn.test(valArray[0]) && patrn.test(valArray[1].substr(0, valArray[1].length - 1))){
strArrayFormat[j++] = strArray[i].toUpperCase();
}
}
}
}
}
else if(strArray[i].indexOf("-") > 0){
valArray = strArray[i].split("-");
if(valArray.length == 2) {
if(valArray[0].length == valArray[1].length) {
if(patrn.test(valArray[0]) && patrn.test(valArray[1])){
strArrayFormat[j++] = strArray[i].toUpperCase();
}
}
}
}
else break;//退出
}
}
if(j > 0) {
if(TestIE()) str = strArrayFormat.join("\r\n");
else str = strArrayFormat.join("\n");
}
return str;
}
function crceditformat(formatstr)
{
var crcbits, crcnum;
var str, ptr, ctr, i, j, len, err;
var sstr, pptr, cctr, val, ibit, val;
var strArray = new Array();
var patrn = /^[\r0-9a-fA-F]+$/;//正则表达式
var tabArray = new Array(4);
tabArray[0] = "0000000000000000";
tabArray[1] = "5555555555555555";
tabArray[2] = "AAAAAAAAAAAAAAAA";
tabArray[3] = "FFFFFFFFFFFFFFFF";
crcbits = GetCRCTableArrayBitsInt();
crcnum = crcbits / 4;
str = "";
err = 0;
if(operatorsele.selectedIndex == 12){//CRC算法逆向
if((GetText12StringLen() == 4* crcnum) && (text13.value.length == 5* crcnum)) {//明文长度=权值长度的4倍
if(patrn.test(text12.value) && patrn.test(text13.value)){//16进制数
err = 1;
for(i = 0; i < 4; i ++){
if (str == "") str = text12.value.substr(i * crcnum, crcnum) + text13.value.substr(i * len, crcnum);
else str += "\n" + text12.value.substr(i * crcnum, crcnum) + text13.value.substr(i * crcnum, crcnum);
}
str += "\n" + text12.value + text13.value.substr(4 * crcnum, crcnum);
str += "\n" + text130.value;//权值
for(i = 0; i < 4; i ++){
str += "\n" + tabArray[i].substr(0, crcnum) + "#";//初值
}
for(i = 0; i < 3; i ++){
sstr = tabArray[i].substr(0, crcnum);//0000
sstr = StringINCToString(sstr);//0001
pptr = tabArray[i + 1].substr(0, crcnum);//5555
pptr = StringDECToString(pptr);//5554
str += "\n" + sstr + "-" + pptr + "#";//初值0000-FFFF#
}
ptr = text160.value;
strArray = ptr.split("_");//简写式
ctr = strArray[0];
str += "\n" + "$,,,," + ctr.substr(ctr.length - 1, 1) + "A," + ctr.substr(3, ctr.length - 4);
}
}
else{
alert("请在密文处再填写计算整个明文的结果,或再点击采样按钮后穷举!!!");
}
}
else{
g_textmode ++;
if(err == 0){
if(formatstr != ""){
str = formatstr;
}
else{
for(i = 0; i < 3; i ++) {//给出3组测试数据和结果
getcrcrandom12(g_textmode & 7);
if(g_textmode & 1){
if (nxshiftcheckbox.checked){
j = Math.floor(Math.random() * 10) << 2;
ptr = text12.value;
text12.value += StringReversalToString(ptr.substr(i * 2, j));//反转
}
}
hotcrc();
sstr = text12.value;
if(anticheckbox.checked){
sstr = StringInvertlToString(sstr);//反序
}
pptr = StringQjDisInvertlToString(text140.value);
if(invercheckbox.checked){
if (str == "") str = pptr + sstr;
else str += "\n" + pptr + sstr;
}
else{
if (str == "") str = sstr + pptr;
else str += "\n" + sstr + pptr;
}
}
}
}
len = text130.value.length;
sstr = "";
pptr = "";
if (nxshiftcheckbox.checked) {//自定义权值
for(i = 0; i < HotCRCPolyTableArray.length; i ++){
ptr = HotCRCPolyTableArray[i];//CRC4R_C_0_0
strArray = ptr.split("_");
ptr = strArray[1];//取权值
if(ptr.length == crcnum){
if(sstr.indexOf(ptr) < 0){
sstr += "\n" + ptr;
}
}
}
if(sstr.indexOf(text130.value) < 0){
sstr += "\n" + text130.value;
}
strArray = sstr.split("\n");
for(i = 0; i < strArray.length; i ++){
ptr = strArray[i];
ptr = StringReversalToString(ptr);//反转
if(sstr.indexOf(ptr) < 0) {
pptr += "\n" + ptr;
}
}
}
else{//循环权值
sstr = "\n" + text130.value;
sstr += "-" + StringDECToString(text130.value);
}
str += sstr + pptr;
if(!nxautocheckbox.checked){//自定义初值出值
if((err == 0) && (g_textmode & 1)){
str += "\n" + tabArray[0].substr(0, crcnum) + "-" + tabArray[3].substr(0, crcnum) + "#";
}
else {
sstr = "";
for(i = 0; i < HotCRCPolyTableArray.length; i ++){
ptr = HotCRCPolyTableArray[i];//CRC4R_C_0_0
strArray = ptr.split("_");
ptr = strArray[2];//取初值
if(ptr.length == crcnum){
if(sstr.indexOf(ptr) < 0){
sstr += "\n" + ptr + "#";
}
ptr = strArray[3];//取出值
if(sstr.indexOf(ptr) < 0){
sstr += "\n" + ptr + "#";
}
}
}
if(sstr.indexOf(text120.value) < 0){
sstr += "\n" + text120.value + "#";
}
if(sstr.indexOf(text170.value) < 0){
sstr += "\n" + text170.value + "#";
}
str += sstr;
}
}
else{
for (i = 0; i < 4; i ++)
{
str += "\n" + tabArray[i].substr(0, crcnum) + "#";
}
}
val = (select1.selectedIndex + 1) * 4;
if(anticheckbox.checked) sstr = "@";
else sstr = "";
if(invercheckbox.checked) pptr = "+";
else pptr = "";
if(val > 8){
str += "\n" + "$,," + pptr +",!" + sstr +",LA," + val;
str += "\n" + "$,," + pptr +",!" + sstr +",La," + val;
str += "\n" + "$,," + pptr +",!" + sstr +",RA," + val;
str += "\n" + "$,," + pptr +",!" + sstr +",Ra," + val;
}
else if(val > 4){
str += "\n" + "$,," + pptr +",!" + sstr +",L," + val;
str += "\n" + "$,," + pptr +",!" + sstr +",R," + val;
}
else{
str += "\n" + "$,," + pptr +",!" + sstr +",1L," + val;
str += "\n" + "$,," + pptr +",!" + sstr +",1R," + val;
}
}
if(str != "") {
str += "\n" + "请按穷举键开始穷举CRC多项式!!!";
}
idTextBox.value = str;
ChangeidTextBox();
}
function LoadHotCRCPolyTable(key)
{
var i, str, count = 0;
if(key){
if(!(TestLS() && confirm("请您确认是否初始化HotCRC多项式???"))){
return;
}
}
HotCRCPolyTableArray[0x00] = "CRC4R_C_0_0";
HotCRCPolyTableArray[0x01] = "CRC4L_3_0_0";
HotCRCPolyTableArray[0x02] = "CRC8R_E0_00_00";
HotCRCPolyTableArray[0x03] = "CRC8L_31_00_00";
HotCRCPolyTableArray[0x04] = "CRC12R_F01_000_000";
HotCRCPolyTableArray[0x05] = "CRC12L_80F_000_000";
HotCRCPolyTableArray[0x06] = "CRC16R_A001_FFFF_0000";
HotCRCPolyTableArray[0x07] = "CRC16L_1021_FFFF_0000";
HotCRCPolyTableArray[0x08] = "CRC20R_A0010_00000_00000";//
HotCRCPolyTableArray[0x09] = "CRC20L_10211_00000_00000";//
HotCRCPolyTableArray[0x0a] = "CRC24R_800063_FFFFFF_FFFFFF";
HotCRCPolyTableArray[0x0b] = "CRC24L_864CFB_B704CE_000000";
HotCRCPolyTableArray[0x0c] = "CRC28R_8000631_0000000_0000000";//
HotCRCPolyTableArray[0x0d] = "CRC28L_864CFB1_0000000_0000000";//
HotCRCPolyTableArray[0x0e] = "CRC32R_82F63B78_FFFFFFFF_FFFFFFFF";
HotCRCPolyTableArray[0x0f] = "CRC32L_1EDC6F41_FFFFFFFF_FFFFFFFF";
HotCRCPolyTableArray[0x10] = "CRC36R_82F63B781_000000000_000000000";//
HotCRCPolyTableArray[0x11] = "CRC36L_1EDC6F411_000000000_000000000";//
HotCRCPolyTableArray[0x12] = "CRC40R_9000412000_FFFFFFFFFF_FFFFFFFFFF";
HotCRCPolyTableArray[0x13] = "CRC40L_0004820009_0000000000_0000000000";
HotCRCPolyTableArray[0x14] = "CRC44R_90004120001_00000000000_00000000000";
HotCRCPolyTableArray[0x15] = "CRC44L_00048200091_00000000000_00000000000";
HotCRCPolyTableArray[0x16] = "CRC48R_D28DB3FA4AAD_000000000000_000000000000";
HotCRCPolyTableArray[0x17] = "CRC48L_D28DB3FA4AAD_000000000000_000000000000";
HotCRCPolyTableArray[0x18] = "CRC52R_9000412000111_0000000000000_0000000000000";
HotCRCPolyTableArray[0x19] = "CRC52L_0004820009111_0000000000000_0000000000000";
HotCRCPolyTableArray[0x1a] = "CRC56R_90004120001111_00000000000000_00000000000000";
HotCRCPolyTableArray[0x1b] = "CRC56L_00048200091111_00000000000000_00000000000000";
HotCRCPolyTableArray[0x1c] = "CRC60R_900041200011111_000000000000000_000000000000000";
HotCRCPolyTableArray[0x1d] = "CRC60L_000482000911111_000000000000000_000000000000000";
HotCRCPolyTableArray[0x1e] = "CRC64R_C96C5795D7870F42_0000000000000000_FFFFFFFFFFFFFFFF";
HotCRCPolyTableArray[0x1f] = "CRC64L_000000000000001B_0000000000000000_0000000000000000";
if(TestLS()){
for(i = 0;i < 0x20;i++){
str = "HotWC3_PolyTable" + "_" + i;
if((key == 0) && localStorage[str]){
HotCRCPolyTableArray[i] = localStorage[str];
}
else {
localStorage[str] = HotCRCPolyTableArray[i];
if(localStorage[str] == HotCRCPolyTableArray[i]) count++;
}
}
if(key > 0){
if(count == 0x20){
alert("初始化HotCRC多项式成功!!!");
location.reload();//刷新页面,重新启动
}
else{
alert("初始化HotCRC多项式失败!!!");
}
}//key
}
}
function SaveHotCRCPolyTable()
{
var i, str, count = 0;
if(TestLS()){
if(!confirm("请您确认是否初保存HotCRC多项式???")){
return;
}
for(i = 0;i < 0x20;i++){
str = "HotWC3_PolyTable" + "_" + i;
localStorage[str] = HotCRCPolyTableArray[i];
if(localStorage[str] == HotCRCPolyTableArray[i]) count++;
}
if(count == 0x20){
alert("保存HotCRC多项式成功!!!");
}
else{
alert("保存HotCRC多项式失败!!!");
}
}
}
function LoadHotWC3PasswordTable()
{
var i, str;
LoadHotWC3CRCTextString("78-96-9E98-20090808-19591119-19790413");//CRC8
LoadHotWC3CRCTextString("1F-33-13B0-18931226-19760909-19491001");//CRC16
LoadHotWC3CRCTextString("5B-5F-0E88-18890420-19450430-19901003");//CRC24
LoadHotWC3CRCTextString("58-0A-870E-18871031-19750405-19121010");//CRC32
LoadHotWC3CRCTextString("9B-8B-2648-17690815-18210505-18790714");//CRC40
LoadHotWC3CRCTextString("B1-46-8668-17320222-17991214-17760704");//CRC48
LoadHotWC3CRCTextString("10-96-9BE4-18790314-19550418-19480514");//CRC56
LoadHotWC3CRCTextString("2B-DD-5F0F-19071205-19710913-19491001");//CRC64
// MakeCRCXXXXLPolyTextString();
// LoadPasswordTable();
}
function systimeout()
{
var systemdate = new Date();
hotwc3wificheckbox.checked = TestWF();
if(hotwc3wificheckbox.checked){
hotwc3wifilabel.style.color = "red";
}
else{
hotwc3wifilabel.style.color = "blue";
}
var str = systemdate.getMinutes().toString();
var ptr = systemdate.getSeconds().toString();
timetext.value = systemdate.getHours() + ":" + StringRight0(str, 2) + ":" + StringRight0(ptr, 2);
}
//EndHide-->
</script>
<script>
<!--Hide
//开始运行!!!
LoadHotCRCPolyTable(0);
//在此添加标准CRC简写式:
LoadHotCRCPolyTableArray("CRC4L_3_0_0");//crc4_itu
LoadHotCRCPolyTableArray("CRC8L_07_00_00");//crc8_pec
LoadHotCRCPolyTableArray("CRC8R_8C_00_00");//crc8_maxim
LoadHotCRCPolyTableArray("CRC8L_07_00_55");//crc8_itu
LoadHotCRCPolyTableArray("CRC8R_E0_FF_00");//crc8_rohc
LoadHotCRCPolyTableArray("CRC8L_07_FF_00");//crc8_rohcx
LoadHotCRCPolyTableArray("CRC12L_80F_000_000");//crc12
LoadHotCRCPolyTableArray("CRC16R_A001_0000_0000");//crc16
LoadHotCRCPolyTableArray("CRC16R_A001_FFFF_0000");//crc16_modbus
LoadHotCRCPolyTableArray("CRC16R_A001_FFFF_FFFF");//crc16_usb
LoadHotCRCPolyTableArray("CRC16L_1021_FFFF_0000");//crc16_ccitt
LoadHotCRCPolyTableArray("CRC16R_1021_0000_0000");//crc16_xmodem
LoadHotCRCPolyTableArray("CRC16L_1021_0000_0000");//crc16_zmodem
LoadHotCRCPolyTableArray("CRC16L_8005_0000_0000");//crc16_ibm
LoadHotCRCPolyTableArray("CRC16L_8005_AAAA_0000");//crc16_ibmx
LoadHotCRCPolyTableArray("CRC16R_8408_FFFF_FFFF");//crc16_x25
LoadHotCRCPolyTableArray("CRC16R_8408_FFFF_0000");//crc16_x25x
LoadHotCRCPolyTableArray("CRC16R_A6BC_0000_FFFF");//crc16_dnp
LoadHotCRCPolyTableArray("CRC24L_864CFB_B704CE_000000");//crc24
LoadHotCRCPolyTableArray("CRC24R_DA6000_555555_000000");//crc24_ble
LoadHotCRCPolyTableArray("CRC32R_EDB88320_FFFFFFFF_FFFFFFFF");//crc32
LoadHotCRCPolyTableArray("CRC32R_EDB88320_FFFFFFFF_00000000");//crc32_jamcrc
LoadHotCRCPolyTableArray("CRC32L_04C11DB7_FFFFFFFF_00000000");//crc32_mpeg2
LoadHotCRCPolyTableArray("CRC32L_04C11DB7_FFFFFFFF_FFFFFFFF");//crc32_bzip2
LoadHotCRCPolyTableArray("CRC32L_1EDC6F41_FFFFFFFF_FFFFFFFF");//crc32_sctp
LoadHotCRCPolyTableArray("CRC48L_D28DB3FA4AAD_000000000000_000000000000");//crc48_etcs
LoadHotCRCPolyTableArray("CRC64R_D800000000000000_0000000000000000_0000000000000000");//crc64
LoadHotCRCPolyTableArray("CRC64L_42F0E1EBA9EA3693_FFFFFFFFFFFFFFFF_FFFFFFFFFFFFFFFF");//crc64_ecma
LoadHotWC3PasswordTable();
LoadHotWC3CRCWorkString("9E-19790413-78-1949");//CRC8左半边密钥流
LoadHotWC3CRCWorkString("98-19591119-96-1001");//CRC8右半边密钥流
LoadHotWC3CRCWorkString("9E98-1979041319600816-78A6-19491001");//CRC16左半边密钥流
LoadHotWC3CRCWorkString("2340-1959111919591119-9683-19491001");//CRC16右半边密钥流
LoadHotWC3CRCWorkString("9E9823-197904131960081619600906-78A626-194910011949");//CRC24左半边密钥流
LoadHotWC3CRCWorkString("404730-195911191959111919591119-9683CB-100119491001");//CRC24右半边密钥流
LoadHotWC3CRCWorkString("9E982340-19790413196008161960090619860614-78A62604-1949100119491001");//CRC32左半边密钥流
LoadHotWC3CRCWorkString("473021C8-19591119195911191959111919591119-9683CB8F-1949100119491001");//CRC32右半边密钥流
LoadHotWC3CRCWorkString("9E98234047-1979041319600816196009061986061419790413-78A6260478-19491001194910011949");//CRC40左半边密钥流
LoadHotWC3CRCWorkString("3021C89E98-1959111919591119195911191959111919591119-9683CB8F96-10011949100119491001");//CRC40右半边密钥流
LoadHotWC3CRCWorkString("9E9823404730-197904131960081619600906198606141979041319600816-78A6260478A6-194910011949100119491001");//CRC48左半边密钥流
LoadHotWC3CRCWorkString("21C89E982340-195911191959111919591119195911191959111919591119-9683CB8F9683-194910011949100119491001");//CRC48右半边密钥流
LoadHotWC3CRCWorkString("9E982340473021-19790413196008161960090619860614197904131960081619600906-78A6260478A626-1949100119491001194910011949");//CRC56左半边密钥流
LoadHotWC3CRCWorkString("C89E9823404730-19591119195911191959111919591119195911191959111919591119-9683CB8F9683CB-1001194910011949100119491001");//CRC56右半边密钥流
LoadHotWC3CRCWorkString("9E982340473021C8-1979041319600816196009061986061419790413196008161960090619860614-78A6260478A62604-19491001194910011949100119491001");//CRC64左半边密钥流
LoadHotWC3CRCWorkString("9E982340473021C8-1959111919591119195911191959111919591119195911191959111919591119-9683CB8F9683CB8F-19491001194910011949100119491001");//CRC64右半边密钥流
LoadHotWC3CRCPolyString("12_12_12_12_12_12_12");//CRC8(权值,初值,出值,方向,明文,密文,差分)
LoadHotWC3CRCPolyString("1234_1234_1234_1234_1234_1234_1234");//CRC16(权值,初值,出值,方向,差分)
LoadHotWC3CRCPolyString("123456_123456_123456_123456_123456_123456_123456");//CRC24(权值,初值,出值,方向,明文,密文,差分)
LoadHotWC3CRCPolyString("12345678_12345678_12345678_12345678_12345678_12345678_12345678");//CRC32(权值,初值,出值,方向,明文,密文,差分)
LoadHotWC3CRCPolyString("1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890");//CRC40(权值,初值,出值,方向,明文,密文,差分)
LoadHotWC3CRCPolyString("123456789012_123456789012_123456789012_123456789012_123456789012_123456789012_123456789012");//CRC48(权值,初值,出值,方向,明文,密文,差分)
LoadHotWC3CRCPolyString("12345678901234_12345678901234_12345678901234_12345678901234_12345678901234_12345678901234_12345678901234");//CRC56(权值,初值,出值,方向,明文,密文,差分)
LoadHotWC3CRCPolyString("1234567890123456_1234567890123456_1234567890123456_1234567890123456_1234567890123456_1234567890123456_1234567890123456");//CRC64(权值,初值,出值,方向,明文,密文,差分)
HotWC3LoadProc();
//EndHide-->
</script>
</body>
</html>