当前位置:首页 > 嵌入式 > 嵌入式硬件

#include <p16f877.inc>
  ;
  global decrypt
  global key0,key1,key2,key3,key4,key5,key6,key7
  global csr0,csr1,csr2,csr3,csr4,csr5,csr6,csr7,csr8
  ;
  #define hop1 csr0 ; ﹚竡 hop1~4 单? csr1~4
  #define hop2 csr1
  #define hop3 csr2
  #define hop4 csr3
  #define max_code_length .72
  #define code_length .66
  ;
  udata_shr ; difine csr0:csr7 on share memory
  csr0 res 1 ; hopping code 钡μ?纗??既?竟 (lsb)
  csr1 res 1
  csr2 res 1
  csr3 res 1
  csr4 res 1
  csr5 res 1
  csr6 res 1
  csr7 res 1
  csr8 res 1 ; hopping code 钡μ?纗??既?竟 (msb)
  ;
  encrypt_data udata 0x20
  key0 res 1 ; 64-bit 秆盞じン戈? (lsb)
  key1 res 1
  key2 res 1
  key3 res 1
  key4 res 1
  key5 res 1
  key6 res 1
  key7 res 1
  ;
  udata
  cnt0 res 1
  cnt1 res 1
  hop_length res 1
  mask res 1
  keeloq_temp res 1
  ;
  ;
  keeloq_code code
  ;
  ;*****************************************************
  ;**** rotate csrs register right 1 bit
  ;*****************************************************
  rot_csrs
  rrf csr8,f
  rrf csr7,f
  rrf csr6,f
  rrf csr5,f
  rrf csr4,f
  rrf csr3,f
  rrf csr2,f
  rrf csr1,f
  rrf csr0,f
  return
  ;
  ;
  ;
  ;
  ;****************************************************************
  ;
  ; function : decrypt ()
  ;
  ; description : decrypts 32 bit [hop1:hop4] using [csr0:csr7]
  ;
  ;****************************************************************
  decrypt
  banksel cnt1
  movlw (.11+1) ; outer loop 11+1 times
  movwf cnt1 ; outer loop 11+1 times
  decrypt_outer
  movlw .48 ; inner loop 48 times
  movwf cnt0 ; inner loop 48 times
  decrypt_inner
  clrwdt ; reset watchdog timer
  movfw cnt1 ; last 48 loops restore the key
  xorlw .1 ; last 48 loops restore the key
  btfsc status,z ; last 48 loops restore the key
  goto rotate_key ; last 48 loops restore the key
  ; the lookup table is compressed into in 4 bytes to save space
  ; use the 3 low index bits to make up an 8-bit bit mask
  ; use the 2 high index bits to look up the value in the table
  ; use the bit mask to isolate the correct bit in the byte
  ; part of the reason for this scheme is because normal table
  ; lookup requires an additional stack level
  bcf status,c ; clear carry (for the left shift)
  movlw .1 ; initialise mask = 1
  btfsc hop3,3 ; shift mask 4x if bit 2 set
  movlw b"00010000" ; shift mask 4x if bit 2 set
  movwf mask ; initialise mask = 1
  btfss hop2,0 ; shift mask another 2x if bit 1 set
  goto $+3
  rlf mask,f
  rlf mask,f
  btfsc hop1,0 ; shift mask another 1x if bit 0 set
  rlf mask,f
  ; mask has now been shifted 0-7 times according to bits 2:1:0
  movlw high table
  movwf pclath
  movlw low table
  movwf keeloq_temp
  movlw 0 ; table index = 0
  btfsc hop4,1
  iorlw .2 ; if bit 3 set add 2 to the table index
  btfsc hop4,6
  iorlw .4 ; if bit 4 set add 4 to the table index
  addwf keeloq_temp,w
  btfsc status,c
  incf pclath,f
  movwf pcl ; add the index to the program counter
  ; [ must be in lower half of page ]
  table
  movlw 0x2e ; bits 4:3 were 00
  goto table_end ; end of lookup
  movlw 0x74 ; bits 4:3 were 01
  goto table_end ; end of lookup
  movlw 0x5c ; bits 4:3 were 10
  goto table_end ; end of lookup
  movlw 0x3a ; bits 4:3 were 11
  table_end
  andwf mask,1 ; isolate the correct bit
  movlw 0 ; copy the bit to bit 7
  btfss status,z ; copy the bit to bit 7
  movlw b"1000

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

单片机是一种嵌入式系统,它是一块集成电路芯片,内部包含了处理器、存储器和输入输出接口等功能。

关键字: 单片机 编写程序 嵌入式

在现代电子技术的快速发展中,单片机以其高度的集成性、稳定性和可靠性,在工业自动化、智能家居、医疗设备、航空航天等诸多领域得到了广泛应用。S32单片机,作为其中的佼佼者,其引脚功能丰富多样,是实现与外部设备通信、控制、数据...

关键字: s32单片机引脚 单片机

在微控制器领域,MSP430与STM32无疑是两颗璀璨的明星。它们各自凭借其独特的技术特点和广泛的应用领域,在市场上占据了重要的位置。本文将深入解析MSP430与STM32之间的区别,探讨它们在不同应用场景下的优势和局限...

关键字: MSP430 STM32 单片机

在嵌入式系统开发、调试和测试过程中,J-Link作为一种高效的调试工具,为开发者提供了极大的便利。然而,要想充分发挥J-Link的功能,首先需要正确安装其驱动程序。本文将详细介绍J-Link驱动的安装过程,并深入解析其中...

关键字: jlink 嵌入式系统 嵌入式开发

该系列产品有助于嵌入式设计人员在更广泛的系统中轻松实现USB功能

关键字: 单片机 嵌入式设计 USB

与谷歌的合作使 Nordic 能够在 nRF Connect SDK 中嵌入开发人员软件,以构建与安卓移动设备兼容的谷歌Find My Device和未知跟踪器警报服务

关键字: 谷歌 SoC 嵌入式开发

单片机编程语言是程序员与微控制器进行交流的桥梁,它们构成了单片机系统的软件开发基石,决定着如何有效、高效地控制和管理单片机的各项资源。随着微控制器技术的不断发展,针对不同应用场景的需求,形成了丰富多样的编程语言体系。本文...

关键字: 单片机 微控制器

单片机,全称为“单片微型计算机”或“微控制器”(Microcontroller Unit,简称MCU),是一种高度集成化的电子器件,它是现代科技领域的关键组件,尤其在自动化控制、物联网、消费电子、汽车电子、工业控制等领域...

关键字: 单片机 MCU

STM32是由意法半导体公司(STMicroelectronics)推出的基于ARM Cortex-M内核的32位微控制器系列,以其高性能、低功耗、丰富的外设接口和强大的生态系统深受广大嵌入式开发者喜爱。本文将详细介绍S...

关键字: STM32 单片机

嵌入式开发作为当今电子工程和信息技术领域的核心分支,涵盖了广泛的软硬件技术和系统集成方法,用于构建高性能、低成本、低功耗、体积小巧且功能专一的嵌入式系统。这些系统无处不在,从微型传感器节点到复杂的工业控制设备,从日常使用...

关键字: 嵌入式开发 Python
关闭
关闭