#include "hotwc3.h"
/*-----------------------------------------------------------------------
函数CRCR8(macro_U8_arg1, macro_U8_arg2, macro_U8_arg3)
入口:
macro_U8_arg1 初值
macro_U8_arg2 权
macro_U8_arg3 明文
出口:
macro_U8_Result CRCR8结果
-----------------------------------------------------------------------*/
U8_Function_Arg3 (CRCR8, macro_U8_arg1, macro_U8_arg2, macro_U8_arg3)
begin
#define CRCR8_LOOP -15
#define CRCR8_NEXT size_XRL_A_Rn()
asm_MOV_B(8),//设置8位计数器
//CRCR8_LOOP:
asm_MOV_A_Rn(macro_U8_arg3),//取明文
asm_XRL_A_Rn(macro_U8_arg1),//异或初值
asm_RRC_A(),//右移CRC8一位,注意ACC.0移入CY
asm_MOV_A_Rn(macro_U8_arg1),//再取初值
asm_JNC(CRCR8_NEXT),//CY为0不异或权,跳过下句
asm_XRL_A_Rn(macro_U8_arg2),//异或权
//CRC8R_NEXT:
asm_RRC_A(),//将CY移入ACC.7
asm_MOV_Rn_A(macro_U8_arg1),//保存本次结果
asm_MOV_A_Rn(macro_U8_arg3),//再取明文
asm_RR_A(),//准备下一位
asm_MOV_Rn_A(macro_U8_arg3),//保存明文,注意已改变
asm_DJNZ_B(CRCR8_LOOP),//未完继续到CRCR8_LOOP
/*---------------------------------------------
//将初值安排在Arg1可节省下面2句
asm_MOV_A_Rn(macro_U8_arg1),//取结果
asm_MOV_Rn_A(macro_U8_Result),//送返回值
----------------------------------------------*/
U8_return_result()//结果已在macro_U8_Result中
end;
/*-----------------------------------------------------------------------
函数dCRCR8(macro_U8_arg1, macro_U8_arg2, macro_U8_arg3)
入口:
macro_U8_arg1 初值
macro_U8_arg2 权
macro_U8_arg3 明文
出口:
macro_U8_Result CRCR8结果
-----------------------------------------------------------------------*/
U8_Function_Arg3 (dCRCR8, macro_U8_arg1, macro_U8_arg2, macro_U8_arg3)
begin
#define dCRCR8_LOOP -20
#define dCRCR8_NEXT 9
asm_MOV_B(8),//设置8位计数器
//dCRCR8_LOOP:
asm_MOV_A_Rn(macro_U8_arg1),//取初值
asm_RLC_A(),//左移CRC8一位,注意ACC.7移入CY
asm_MOV_Rn_A(macro_U8_arg1),
asm_MOV_A_Rn(macro_U8_arg3),//取密文
asm_RLC_A(),//左移CRC8一位,注意上次CY移入ACC.0
asm_JNC(dCRCR8_NEXT),
asm_XRL_A_Rn(macro_U8_arg2),//异或权
asm_XCH_A_Rn(macro_U8_arg2),
asm_MOV_C_ACC_0(),
asm_XCH_A_Rn(macro_U8_arg2),
asm_JC(size_CPL_BIT()),
asm_CPL_ACC_0(),
//dCRCR8_NEXT:
asm_MOV_Rn_A(macro_U8_arg3),//保存本次结果
asm_DJNZ_B(dCRCR8_LOOP),//未完继续到dCRCR8_LOOP
U8_return_A()//送返回值
end;
/*-----------------------------------------------------------------------
函数CRCL8(macro_U8_arg1, macro_U8_arg2, macro_U8_arg3)
入口:
macro_U8_arg1 初值
macro_U8_arg2 权
macro_U8_arg3 明文
出口:
macro_U8_Result CRCR8结果
-----------------------------------------------------------------------*/
U8_Function_Arg3 (CRCL8, macro_U8_arg1, macro_U8_arg2, macro_U8_arg3)
begin
#define CRCL8_LOOP -15
#define CRCL8_NEXT size_XRL_A_Rn()
asm_MOV_B(8),//设置8位计数器
//CRCL8_LOOP:
asm_MOV_A_Rn(macro_U8_arg3),//取明文
asm_XRL_A_Rn(macro_U8_arg1),//异或初值
asm_RLC_A(),//左移CRC8一位,注意ACC.7移入CY
asm_MOV_A_Rn(macro_U8_arg1),//再取初值
asm_JNC(CRCL8_NEXT),//CY为0不异或权,跳过下句
asm_XRL_A_Rn(macro_U8_arg2),//异或权
//CRC8R_NEXT:
asm_RLC_A(),//将CY移入ACC.0
asm_MOV_Rn_A(macro_U8_arg1),//保存本次结果
asm_MOV_A_Rn(macro_U8_arg3),//再取明文
asm_RL_A(),//准备下一位
asm_MOV_Rn_A(macro_U8_arg3),//保存明文,注意已改变
asm_DJNZ_B(CRCL8_LOOP),//未完继续到CRCL8_LOOP
/*---------------------------------------------
//将初值安排在Arg1可节省下面2句
asm_MOV_A_Rn(macro_U8_arg1),//取结果
asm_MOV_Rn_A(macro_U8_Result),//送返回值
----------------------------------------------*/
U8_return_result()//结果已在macro_U8_Result中
end;
/*-----------------------------------------------------------------------
函数dCRCL8(macro_U8_arg1, macro_U8_arg2, macro_U8_arg3)
入口:
macro_U8_arg1 初值
macro_U8_arg2 权
macro_U8_arg3 明文
出口:
macro_U8_Result CRCR8结果
-----------------------------------------------------------------------*/
U8_Function_Arg3 (dCRCL8, macro_U8_arg1, macro_U8_arg2, macro_U8_arg3)
begin
#define dCRCL8_LOOP -20
#define dCRCL8_NEXT 9
asm_MOV_B(8),//设置8位计数器
//dCRCL8_LOOP:
asm_MOV_A_Rn(macro_U8_arg1),//取初值
asm_RRC_A(),//右移CRC8一位,注意ACC.0移入CY
asm_MOV_Rn_A(macro_U8_arg1),
asm_MOV_A_Rn(macro_U8_arg3),//取密文
asm_RRC_A(),//右移CRC8一位,注意上次CY移入ACC.7
asm_JNC(dCRCL8_NEXT),
asm_XRL_A_Rn(macro_U8_arg2),//异或权
asm_XCH_A_Rn(macro_U8_arg2),
asm_MOV_C_ACC_7(),
asm_XCH_A_Rn(macro_U8_arg2),
asm_JC(size_CPL_BIT()),
asm_CPL_ACC_7(),
//dCRCL8_NEXT:
asm_MOV_Rn_A(macro_U8_arg3),//保存本次结果
asm_DJNZ_B(dCRCL8_LOOP),//未完继续到dCRCL8_LOOP
U8_return_A(),//A送返回值
end;
/*-----------------------------------------------------------------------
函数Week(macro_U16_arg1, macro_U8_arg2, macro_U8_arg3)
入口:
macro_U16_arg1 年(0x00~0x9999)BCD码
macro_U8_arg2 月(0x01~0x12)BCD码
macro_U8_arg3 日(0x01~0x31)BCD码
出口:
macro_U8_Result 星期(0~6)
长度: 82字节
-----------------------------------------------------------------------*/
U8_Function_Arg3 (Week, macro_U16_arg1, macro_U8_arg2, macro_U8_arg3)
begin
#define Week_LOOP -20
asm_MOV_R1(4),//将百年、年、月、日的BCD码换成二进制数
//Week_LOOP:
asm_MOV_A(0x4f),//DataBuffer偏移,程序长度
//分别取出macro_U16H_arg1,macro_U16L_arg1macro_U8_arg2, macro_U8_arg3
asm_MOVC_A_aDPTR(),
asm_MOV_R0_A(),
asm_MOV_A_iR0(),
asm_ANL_A(0x0f),
asm_XCH_A_iR0(),
asm_SWAP_A(),
asm_ANL_A(0x0f),
asm_MOV_B(10),
asm_MUL_AB(),
asm_ADD_A_iR0(),
asm_MOV_iR0_A(),
asm_INC_DPTR(),
asm_DJNZ_R1(Week_LOOP),//四次未完继续
//(星期=百年%4*5+年+年/4+(13*月+8)/5+日)%7,特别注意1月2月的年为"去年"
asm_CJNE_Rn(macro_U8_arg2, 0x03, 0),//判断月
asm_JNC(size_MOV_A_Rn() + size_ORL_A() + size_MOV_Rn_A() \
+ size_DEC_Rn() + size_CJNE_Rn() + size_DEC_Rn()),//月
//月<=2
asm_MOV_A_Rn(macro_U8_arg2),
asm_ORL_A(0x04),//1月2月同5月六月表
asm_MOV_Rn_A(macro_U8_arg2),
asm_DEC_Rn(macro_U16L_arg1),//1月2月的年为"去年"
asm_CJNE_Rn(macro_U16L_arg1, 0xff, size_DEC_Rn()),//Week_Start
asm_DEC_Rn(macro_U16H_arg1),
//Week_Start:
//百年%4*5
asm_MOV_A_Rn(macro_U16H_arg1),//百年
asm_ANL_A(0x03),
asm_MOV_Rn_A(macro_U16H_arg1),//百年%4
asm_CLR_C(),
asm_RLC_A(),
asm_CLR_C(),
asm_RLC_A(),//百年%4*4
asm_ORL_A_Rn(macro_U16H_arg1),//百年%4*5
asm_MOV_Rn_A(macro_U16H_arg1),//保存(百年%4*5),最大值3*5=15
//年+年/4
asm_MOV_A_Rn(macro_U16L_arg1),//年
asm_CLR_C(),
asm_RRC_A(),
asm_CLR_C(),
asm_RRC_A(),
asm_ADD_A_Rn(macro_U16L_arg1),//年+年/4
asm_MOV_Rn_A(macro_U16L_arg1),//保存(年+年/4),最大值99+25=124
asm_MOV_A_Rn(macro_U8_arg2),//月
asm_MOV_B(13),
asm_MUL_AB(),//13*月->A
asm_MOV_B(8),
asm_ADD_A_B(),//13*月+8
asm_MOV_B(5),
asm_DIV_AB(),//(13*月+8)/5 商->A
asm_MOV_Rn_A(macro_U8_arg2),//保存((13*月+8)/5)最大值33
//日
asm_ADD_A_Rn(macro_U8_arg3),//日,最大值31
asm_ADDC_A_Rn(macro_U16H_arg1),//(百年%4*5),最大值15
asm_ADDC_A_Rn(macro_U16L_arg1),//(年+年/4),最大值99+25=124
/*
此时ACC最大为15+124+33+31=203,
注意,蔡勒公式内无203.-2*C可能会越界,菜农给出的蔡勒公式完整表述:
W = (203+C/4-2*C+Y+Y/4+(13*M+8)/5+D)%7
菜农星期公式:
W = ( C%4*5+Y+Y/4+(13*M+8)/5+D)%7
*/
asm_MOV_B(7),//取余数%7
asm_DIV_AB(),
asm_XCH_A_B(),
U8_return_A(),//送返回值(星期)
//数据区DataBuffer
asm_DB(macro_U16H_arg1),
asm_DB(macro_U16L_arg1),
asm_DB(macro_U8_arg2),
asm_DB(macro_U8_arg3)
end;
/*-----------------------------------------------------------------------
函数Triangle(macro_U8_arg1)
入口:
macro_U8_arg1 三角值
出口:
macro_U16_Result 三角密码
长度: 字节
-----------------------------------------------------------------------*/
U16_Function_Arg1 (Triangle, macro_U8_arg1)
begin
asm_MOV_A_Rn(macro_U8_arg1),//取三角值
asm_MOV_B(2),
asm_MUL_AB(),//BA
asm_ADD_A_DPL(),
asm_MOV_DPL_A(),
asm_MOV_A_B(),
asm_ADDC_A_DPH(),
asm_MOV_DPH_A(),
asm_MOV_A(0x18),
asm_MOVC_A_aDPTR(),//大端,先取高8位
asm_MOV_Rn_A(macro_U16H_Result),//三角密码高8位
asm_MOV_A(0x19),
asm_MOVC_A_aDPTR(),//大端,后取低8位
asm_MOV_Rn_A(macro_U16L_Result),//三角密码低8位
U16_return_result(),
//DataBuffer:
/*《三角恋爱密码表》
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00 8002 0003 8006 0008 800C 000F 8014 0018 801E 0023 802A 0030 8038 003F 8048 0050
82 03 86 08* 8C 0F 94 18 9E* 23 AA* 30 B8 3F C8 50
01 805A 0063 806E 0078 8084 008F 809C 00A8 80B6 00C3 80D2 00E0 80F0 00FF 8110 0120
DA* 63 EE* 78 04 8F 1C A8 36 C3 52 E0 70 FF 91 21
02 8132 0143 8156 0168 817C 018F 81A4 01B8 81CE 01E3 81FA 0210 8228 023F 8258 0270
B3 42 D7 69 FD 8E 25 B9 4F E2 7B 12 AA* 3D DA* 72
03 828A 02A3 82BE 02D8 82F4 030F 832C 0348 8366 0383 83A2 03C0 83E0 03FF 8420 0440
08* A1 3C DA* 76 0C AF 4B E5* 80 21 C3 63 CF A4 44
04 8462 0483 84A6 04C8 84EC 050F 8534 0558 857E 05A3 85CA 05F0 8618 063F 8668 0690
E6 87 22 CC 68 0A B1 5D FB A4 48 F5 9E* 39 EE* 96
05 86BA 06E3 870E 0738 8764 078F 87BC 07E8 8816 0843 8872 08A0 88D0 08FF 8930 0960
34 E5* 89 3E E3 88 3B EF 9E 4B FA A8 58 F7 B9 69
06 8992 09C3 89F6 0A28 8A5C 0A8F 8AC4 0AF8 8B2E 0B63 8B9A 0BD0 8C08 0C3F 8C78 0CB0
1B CA 7F 22 D6 85 4E F2 A5 68 11 DB 84 33 F4 BC
07 8CEA 0D23 8D5E 0D98 8DD4 0E0F 8E4C 0E88 8EC6 0F03 8F42 0F80 8FC0 0FFF 9040 1080
66 2E D3 95
08 90C2 1103 9146 1188 91CC 120F 9254 1298 92DE 1323 936A 13B0 93F8 143F 9488 14D0
09 951A 1563 95AE 15F8 9644 168F 96DC 1728 9776 17C3 9812 1860 98B0 18FF 9950 19A0
0A 99F2 1A43 9A96 1AE8 9B3C 1B8F 9BE4 1C38 9C8E 1CE3 9D3A 1D90 9DE8 1E3F 9E98 1EF0
0B 9F4A 1FA3 9FFE 2058 A0B4 210F A16C 21C8 A226 2283 A2E2 2340 A3A0 23FF A460 24C0
0C A522 2583 A5E6 2648 A6AC 270F A774 27D8 A83E 28A3 A90A 2970 A9D8 2A3F AAA8 2B10
0D AB7A 2BE3 AC4E 2CB8 AD24 2D8F ADFC 2E68 AED6 2F43 AFB2 3020 B090 30FF B170 31E0
0E B252 32C3 B336 33A8 B41C 348F B504 3578 B5EE 3663 B6DA 3750 B7C8 383F B8B8 3930
0F B9AA 3A23 BA9E 3B18 BB94 3C0F BC8C 3D08 BD86 3E03 BE82 3F00 BF80 3FFF C080 4100
*/
//00 8002 0003 8006 0008 800C 000F 8014 0018 801E 0023 802A 0030 8038 003F 8048 0050
asm_DW(0x8002), asm_DW(0x0003), asm_DW(0x8006), asm_DW(0x0008),
asm_DW(0x800C), asm_DW(0x000F), asm_DW(0x8014), asm_DW(0x0018),
asm_DW(0x801E), asm_DW(0x0023), asm_DW(0x802A), asm_DW(0x0030),
asm_DW(0x8038), asm_DW(0x003F), asm_DW(0x8048), asm_DW(0x0050),
//01 805A 0063 806E 0078 8084 008F 809C 00A8 80B6 00C3 80D2 00E0 80F0 00FF 8110 0120
asm_DW(0x805A), asm_DW(0x0063), asm_DW(0x806E), asm_DW(0x0078),
asm_DW(0x8084), asm_DW(0x008F), asm_DW(0x809C), asm_DW(0x00A8),
asm_DW(0x80B6), asm_DW(0x00C3), asm_DW(0x80D2), asm_DW(0x00E0),
asm_DW(0x80F0), asm_DW(0x00FF), asm_DW(0x8110), asm_DW(0x0120),
//02 8132 0143 8156 0168 817C 018F 81A4 01B8 81CE 01E3 81FA 0210 8228 023F 8258 0270
asm_DW(0x8132), asm_DW(0x0143), asm_DW(0x8156), asm_DW(0x0168),
asm_DW(0x817C), asm_DW(0x018F), asm_DW(0x81A4), asm_DW(0x01B8),
asm_DW(0x81CE), asm_DW(0x01E3), asm_DW(0x81FA), asm_DW(0x0210),
asm_DW(0x8228), asm_DW(0x023F), asm_DW(0x8258), asm_DW(0x0270),
//03 828A 02A3 82BE 02D8 82F4 030F 832C 0348 8366 0383 83A2 03C0 83E0 03FF 8420 0440
asm_DW(0x828A), asm_DW(0x02A3), asm_DW(0x82BE), asm_DW(0x02D8),
asm_DW(0x82F4), asm_DW(0x030F), asm_DW(0x832C), asm_DW(0x0348),
asm_DW(0x8366), asm_DW(0x0383), asm_DW(0x83A2), asm_DW(0x03C0),
asm_DW(0x83E0), asm_DW(0x03FF), asm_DW(0x8420), asm_DW(0x0440),
//04 8462 0483 84A6 04C8 84EC 050F 8534 0558 857E 05A3 85CA 05F0 8618 063F 8668 0690
asm_DW(0x8462), asm_DW(0x0483), asm_DW(0x84A6), asm_DW(0x04C8),
asm_DW(0x84EC), asm_DW(0x050F), asm_DW(0x8534), asm_DW(0x0558),
asm_DW(0x857E), asm_DW(0x05A3), asm_DW(0x85CA), asm_DW(0x05F0),
asm_DW(0x8618), asm_DW(0x063F), asm_DW(0x8668), asm_DW(0x0690),
//05 86BA 06E3 870E 0738 8764 078F 87BC 07E8 8816 0843 8872 08A0 88D0 08FF 8930 0960
asm_DW(0x86BA), asm_DW(0x06E3), asm_DW(0x870E), asm_DW(0x0738),
asm_DW(0x8764), asm_DW(0x078F), asm_DW(0x87BC), asm_DW(0x07E8),
asm_DW(0x8816), asm_DW(0x0843), asm_DW(0x8872), asm_DW(0x08A0),
asm_DW(0x88D0), asm_DW(0x08FF), asm_DW(0x8930), asm_DW(0x0960),
//06 8992 09C3 89F6 0A28 8A5C 0A8F 8AC4 0AF8 8B2E 0B63 8B9A 0BD0 8C08 0C3F 8C78 0CB0
asm_DW(0x8992), asm_DW(0x09C3), asm_DW(0x89F6), asm_DW(0x0A28),
asm_DW(0x8A5C), asm_DW(0x0A8F), asm_DW(0x8AC4), asm_DW(0x0AF8),
asm_DW(0x8B2E), asm_DW(0x0B63), asm_DW(0x8B9A), asm_DW(0x0BD0),
asm_DW(0x8C08), asm_DW(0x0C3F), asm_DW(0x8C78), asm_DW(0x0CB0),
//07 8CEA 0D23 8D5E 0D98 8DD4 0E0F 8E4C 0E88 8EC6 0F03 8F42 0F80 8FC0 0FFF 9040 1080
asm_DW(0x8CEA), asm_DW(0x0D23), asm_DW(0x8D5E), asm_DW(0x0D98),
asm_DW(0x8DD4), asm_DW(0x0E0F), asm_DW(0x8E4C), asm_DW(0x0E88),
asm_DW(0x8EC6), asm_DW(0x0F03), asm_DW(0x8F42), asm_DW(0x0F80),
asm_DW(0x8FC0), asm_DW(0x0FFF), asm_DW(0x9040), asm_DW(0x1080),
//08 90C2 1103 9146 1188 91CC 120F 9254 1298 92DE 1323 936A 13B0 93F8 143F 9488 14D0
asm_DW(0x90C2), asm_DW(0x1103), asm_DW(0x9146), asm_DW(0x1188),
asm_DW(0x91CC), asm_DW(0x120F), asm_DW(0x9254), asm_DW(0x1298),
asm_DW(0x92DE), asm_DW(0x1323), asm_DW(0x936A), asm_DW(0x13B0),
asm_DW(0x93F8), asm_DW(0x143F), asm_DW(0x9488), asm_DW(0x14D0),
//09 951A 1563 95AE 15F8 9644 168F 96DC 1728 9776 17C3 9812 1860 98B0 18FF 9950 19A0
asm_DW(0x951A), asm_DW(0x1563), asm_DW(0x95AE), asm_DW(0x15F8),
asm_DW(0x9644), asm_DW(0x168F), asm_DW(0x96DC), asm_DW(0x1728),
asm_DW(0x9776), asm_DW(0x17C3), asm_DW(0x9812), asm_DW(0x1860),
asm_DW(0x98B0), asm_DW(0x18FF), asm_DW(0x9950), asm_DW(0x19A0),
//0A 99F2 1A43 9A96 1AE8 9B3C 1B8F 9BE4 1C38 9C8E 1CE3 9D3A 1D90 9DE8 1E3F 9E98 1EF0
asm_DW(0x99F2), asm_DW(0x1A43), asm_DW(0x9A96), asm_DW(0x1AE8),
asm_DW(0x9B3C), asm_DW(0x1B8F), asm_DW(0x9BE4), asm_DW(0x1C38),
asm_DW(0x9C8E), asm_DW(0x1CE3), asm_DW(0x9D3A), asm_DW(0x1D90),
asm_DW(0x9DE8), asm_DW(0x1E3F), asm_DW(0x9E98), asm_DW(0x1EF0),
//0B 9F4A 1FA3 9FFE 2058 A0B4 210F A16C 21C8 A226 2283 A2E2 2340 A3A0 23FF A460 24C0
asm_DW(0x9F4A), asm_DW(0x1FA3), asm_DW(0x9FFE), asm_DW(0x2058),
asm_DW(0xA0B4), asm_DW(0x210F), asm_DW(0xA16C), asm_DW(0x21C8),
asm_DW(0xA226), asm_DW(0x2283), asm_DW(0xA2E2), asm_DW(0x2340),
asm_DW(0xA3A0), asm_DW(0x23FF), asm_DW(0xA460), asm_DW(0x24C0),
//0C A522 2583 A5E6 2648 A6AC 270F A774 27D8 A83E 28A3 A90A 2970 A9D8 2A3F AAA8 2B10
asm_DW(0xA522), asm_DW(0x2583), asm_DW(0xA5E6), asm_DW(0x2648),
asm_DW(0xA6AC), asm_DW(0x270F), asm_DW(0xA774), asm_DW(0x27D8),
asm_DW(0xA83E), asm_DW(0x28A3), asm_DW(0xA90A), asm_DW(0x2970),
asm_DW(0xA9D8), asm_DW(0x2A3F), asm_DW(0xAAA8), asm_DW(0x2B10),
//0D AB7A 2BE3 AC4E 2CB8 AD24 2D8F ADFC 2E68 AED6 2F43 AFB2 3020 B090 30FF B170 31E0
asm_DW(0xAB7A), asm_DW(0x2BE3), asm_DW(0xAC4E), asm_DW(0x2CB8),
asm_DW(0xAD24), asm_DW(0x2D8F), asm_DW(0xADFC), asm_DW(0x2E68),
asm_DW(0xAED6), asm_DW(0x2F43), asm_DW(0xAFB2), asm_DW(0x3020),
asm_DW(0xB090), asm_DW(0x30FF), asm_DW(0xB170), asm_DW(0x31E0),
//0E B252 32C3 B336 33A8 B41C 348F B504 3578 B5EE 3663 B6DA 3750 B7C8 383F B8B8 3930
asm_DW(0xB252), asm_DW(0x32C3), asm_DW(0xB336), asm_DW(0x33A8),
asm_DW(0xB41C), asm_DW(0x348F), asm_DW(0xB504), asm_DW(0x3578),
asm_DW(0xB5EE), asm_DW(0x3663), asm_DW(0xB6DA), asm_DW(0x3750),
asm_DW(0xB7C8), asm_DW(0x383F), asm_DW(0xB8B8), asm_DW(0x3930),
//0F B9AA 3A23 BA9E 3B18 BB94 3C0F BC8C 3D08 BD86 3E03 BE82 3F00 BF80 3FFF C080 4100
asm_DW(0xB9AA), asm_DW(0x3A23), asm_DW(0xBA9E), asm_DW(0x3B18),
asm_DW(0xBB94), asm_DW(0x3C0F), asm_DW(0xBC8C), asm_DW(0x3D08),
asm_DW(0xBD86), asm_DW(0x3E03), asm_DW(0xBE82), asm_DW(0x3F00),
asm_DW(0xBF80), asm_DW(0x3FFF), asm_DW(0xC080), asm_DW(0x4100)
end;
/*-----------------------------------------------------------------------
函数BufferCRC8(unsigned char* crcBuffer, unsigned int crcLength, unsigned int crcInitValuePower)
入口:
unsigned char* arg1 待计算CRC区域指针
unsigned int arg2 待计算CRC长度
出口:
macro_U16_Result 三角密码
长度: 字节
-----------------------------------------------------------------------*/
unsigned char BufferCRC8(unsigned int crcBuffer, unsigned int crcLength, unsigned int crcInitValuePower)
{
HRESULT __result = 0;
unsigned char *crcBufferPtr;
unsigned char crcInitValue, crcInitPower;
unsigned int i;
crcBufferPtr = (unsigned char *)crcBuffer;
crcInitValue = crcInitValuePower >> 8;
crcInitPower = crcInitValuePower & 0xff;
for (i = 0; i < crcLength; i ++)
{
if (crcInitValue >= crcInitPower)
{
crcInitValue = wc3Function.Vtbl.CRCL8(crcInitValue, crcInitPower, crcBufferPtr[i]);//初值,权, 明文
}
else
{
crcInitValue = wc3Function.Vtbl.CRCR8(crcInitValue, crcInitPower, crcBufferPtr[i]);//初值,权, 明文
}
crcBufferPtr[i] = crcInitValue;
}
return __result;
}
unsigned char HotWC3(IHotWc3Com_Interface *pWC3)
{
HRESULT __result = S_OK;
//unsigned char* wcPassword;
unsigned char *wcBuffer;
unsigned char wcInitValue, wcInitPower;
unsigned char wcWeek, wcKey;
unsigned int wcTriangle;
unsigned int i;
// wcPassword = pWC3->wcPassword;
wcWeek = pWC3->Vtbl.Week((pWC3->wcPassword[0] << 8) | pWC3->wcPassword[1], pWC3->wcPassword[2], pWC3->wcPassword[3]);
// wcWeek *= 17;
for (i = 0; i < 4; i ++)
{
// pWC3->wcPassword[i] += wcWeek;
// wcWeek ^= pWC3->wcPassword[i];//计算星期密钥
}
wcKey = wcWeek;//三角密码值
wcBuffer = pWC3->wcBuffer;
for (i = 0; i < pWC3->wcLength; i ++)
{
wcKey ^= pWC3->wcPassword[(i & 0x03) ^ 0x03];
wcKey ^= (i & 0x03) & 0xff;
wcTriangle = pWC3->Vtbl.Triangle(wcKey);//计算三角密码
wcInitValue = wcTriangle >> 8;//初值
wcInitPower = wcTriangle & 0xff;//权
if (wcInitValue >= wcInitPower)
{
wcInitValue = pWC3->Vtbl.CRCL8(wcInitValue, wcInitPower, wcBuffer[i]);//初值,权, 明文
}
else
{
wcInitValue = pWC3->Vtbl.CRCR8(wcInitValue, wcInitPower, wcBuffer[i]);//初值,权, 明文
}
wcKey = wcInitValue;//内部密文输出
wcInitValue ^= pWC3->wcPassword[(i & 0x03) ^ 0x03];
wcInitValue ^= (i & 0x03) & 0xff;
wcBuffer[i] = wcInitValue;//外部密文输出
}
return __result;
}
unsigned char HotWC3d(IHotWc3Com_Interface *pWC3)
{
HRESULT __result = S_OK;
//unsigned char* wcPassword;
unsigned char *wcBuffer;
unsigned char wcInitValue, wcInitPower;
unsigned char wcWeek, wcKey;
unsigned int wcTriangle;
unsigned int i;
// wcPassword = pWC3->wcPassword;
wcWeek = pWC3->Vtbl.Week((pWC3->wcPassword[0] << 8) | pWC3->wcPassword[1], pWC3->wcPassword[2], pWC3->wcPassword[3]);
// wcWeek *= 17;
for (i = 0; i < 4; i ++)
{
// pWC3->wcPassword[i] += wcWeek;
// wcWeek ^= pWC3->wcPassword[i];//计算星期密钥
}
wcKey = wcWeek;//三角密码值
wcBuffer = pWC3->wcBuffer;
for (i = 0; i < pWC3->wcLength; i ++)
{
wcKey ^= pWC3->wcPassword[(i & 0x03) ^ 0x03];
wcKey ^= (i & 0x03) & 0xff;
wcTriangle = pWC3->Vtbl.Triangle(wcKey);//计算三角密码
wcInitValue = wcTriangle >> 8;//初值
wcInitPower = wcTriangle & 0xff;//权
if (wcInitValue >= wcInitPower)
{
wcInitValue = pWC3->Vtbl.CRCL8(wcInitValue, wcInitPower, wcBuffer[i]);//初值,权, 明文
}
else
{
wcInitValue = pWC3->Vtbl.CRCR8(wcInitValue, wcInitPower, wcBuffer[i]);//初值,权, 明文
}
wcKey = wcInitValue;//内部密文输出
wcInitValue ^= pWC3->wcPassword[(i & 0x03) ^ 0x03];
wcInitValue ^= (i & 0x03) & 0xff;
wcBuffer[i] = wcInitValue;//外部密文输出
}
return __result;
}
const ptrInterface(IHotWc3Com_Interface, wc3Function)//装载COM接口函数指针
begin//开始按顺序装载函数
// (unsigned char (*)(pIHotWc3Com_Interface pWC3))HotWC3,
ptrFunction_Arg1(unsigned char, HotWC3, pIHotWc3Com_Interface pWC3),
// (unsigned char (*)(pIHotWc3Com_Interface pWC3))HotWC3d,
ptrFunction_Arg1(unsigned char, HotWC3d, pIHotWc3Com_Interface pWC3),
// (unsigned char (*)(unsigned int crcBuffer, unsigned int crcLength, unsigned int crcInitValuePower))BufferCRC8,
ptrFunction_Arg3(unsigned char, BufferCRC8, unsigned int crcBuffer, unsigned int crcLength, unsigned int crcInitValuePower),
// (unsigned char (*)(unsigned char arg1, unsigned char arg2, unsigned char arg3))CRCR8,
ptrFunction_Arg3(unsigned char, CRCR8, unsigned char arg1, unsigned char arg2, unsigned char arg3),
// (unsigned char (*)(unsigned char arg1, unsigned char arg2, unsigned char arg3))CRCL8,
ptrFunction_Arg3(unsigned char, CRCL8, unsigned char arg1, unsigned char arg2, unsigned char arg3),
// (unsigned char (*)(unsigned char arg1, unsigned char arg2, unsigned char arg3))dCRCR8,
ptrFunction_Arg3(unsigned char, dCRCR8, unsigned char arg1, unsigned char arg2, unsigned char arg3),
// (unsigned char (*)(unsigned char arg1, unsigned char arg2, unsigned char arg3))dCRCL8,
ptrFunction_Arg3(unsigned char, dCRCL8, unsigned int arg1, unsigned char arg2, unsigned char arg3),
// (unsigned char (*)(unsigned int arg1, unsigned char arg2, unsigned char arg3))Week,
ptrFunction_Arg3(unsigned char, Week, unsigned int arg1, unsigned char arg2, unsigned char arg3),
// (unsigned int (*)(unsigned char arg1))Triangle,
ptrFunction_Arg1(unsigned char, Triangle, unsigned char arg1),
end;//结束装载 |
|