其他:DES算法的ST7单片机实现程序2 [zlf341] [16次] 01-7-18 下午 10:42:05
;*******************Standard permutation function***********
STANDARD_PERMUTATION:
LD A,#8
LD Byte_Buf2,A
P LD A,#8
LD Byte_Buf1,A
LD X,Input
LD A,(X)
LD X,Output
INC Input
P1 RLC A
RRC (X)
INC X
DEC Byte_Buf1
JRNE P1
DEC Byte_Buf2
JRNE P
RET
;**************** BYTES XOR FUNCTION**************
XOR_FUNCTION
LD X,Input
AGAIN LD A,[Output]
XOR A,(X)
LD [Output],A
INC Output
INC X
DEC Table_index
JRNE AGAIN
RET
;****************S REPLACEMENT FUNCTION***********
S_FUNCTION:
LD A,#8 ;????????????
LD Byte_Buf1,A
LD A,#S_Buf
LD Output,A
LD A,#S_ADR
LD Input,A
STEP LD A,[Input]
AND A,#%10000100
CP A,#$84
JRNE CMP0
LD A,#3
JP CMP2
CMP0 CP A,#$80
JRNE CMP1
LD A,#2
JP CMP2
CMP1 CP A,#$04
JRNE CMP2
LD A,#1
CMP2 LD X,#8
MUL X,A
LD Byte_Buf2,A
LD A,Byte_Buf1
DEC A
LD X,#32
MUL X,A
ADD A,Byte_Buf2
LD Byte_Buf2,A
LD A,[Input]
RLC A
AND A,#$F0
SWAP A
CP A,#8
JRUGE STEP0
ADD A,Byte_Buf2
LD X,A
LD A,(S_TABLE,X)
JP STEP1
STEP0 SUB A,#8
ADD A,Byte_Buf2
LD X,A
LD A,(S_TABLE,X)
SWAP A
STEP1 AND A,#$F
LD [Output],A
INC Input
INC Output
DEC Byte_Buf1
JRNE STEP
RET
;****************F FUNCTION****** ;**READY FOR E REPLACEMENT FUNCTION**
F_FUNCTION:
LD A,#E_Buf ;**READY FOR E REPLACEMENT FUNCTION**
LD Output,A ;
LD A,#E_Length
LD LENGTH,A
LD A,#E_TABLE.L
LD TH_L,A
LD A,#E_TABLE.H
LD TH_H,A
LD A,#E_ADR
LD Input,A ;
CALL Permutation_FUN ;
LD A,#XOR1_Buf ;**READY FOR XOR**
LD Output,A
LD A,#XOR1_ADR
LD Input,A ;
LD A,#8
LD Table_index,A ;DO XOR 8 TIMES.
CALL XOR_FUNCTION
CALL S_FUNCTION ;**READY FOR S
REPLACEMENT FUNCTION**
LD A,#P_Buf ;**READY FOR P REPLACEMENT FUNCTION**
LD Output,A ;
LD A,#P_Length
LD LENGTH,A
LD A,#P_TABLE.L
LD TH_L,A
LD A,#P_TABLE.H
LD TH_H,A
LD A,#P_ADR
LD Input,A ;
CALL Permutation_FUN
RET
;**************************************
IP_EXCHANGE
DC.B $0,$6B,$68,$6B,$6E,$6F,$69,$6F,$6C
FIP_EXCHANGE
DC.B $0,$6A,$69,$6E,$6B,$6E,$6D,$6C,$6A
PC1_EXCHANGE
DC.B $0,$59,$5B,$5B,$5C,$5A,$5D,$59,$5E,$58,$5F
REPEAT_TABLE
DC.B $0,$6B,$6F,$6A,$6E,$69,$6D,$68,$6C
PC2_TABLE
DC.B $36,$85,$66,$15,$87,$47,$0F,$0F
DC.B $67,$54,$26,$37,$45,$76,$0F,$0F
DC.B $25,$65,$56,$57,$74,$17,$0F,$0F
DC.B $16,$27,$64,$55,$46,$77,$0F,$0F
DC.B $42,$11,$63,$82,$61,$60,$0F,$0F
DC.B $73,$52,$21,$81,$43,$51,$0F,$0F
DC.B $12,$41,$62,$50,$33,$80,$0F,$0F
DC.B $71,$32,$31,$13,$83,$53,$0F,$0F
RLC_TABLE DC.B 0,1,2,2,2,2,2,2
DC.B 1,2,2,2,2,2,2,1,1
RLC_TABLE1 DC.B 0,27,26,26,26,26,26,
DC.B 26,27,26,26,26,26,26,26,27,28
S_TABLE
DC.B $3E,$0A4,$6D,$0C1,$52,$9F,$0B,$78
DC.B $0A0,$6F,$0C7,$0B4,$9E,$52,$3D,$81
DC.B $0F4,$0C1,$9E,$78,$3D,$0A6,$52,$0B
DC.B $5F,$0BC,$38,$0E2,$0A4,$09,$61,$0D7
DC.B $9F,$71,$28,$0DE,$0C6,$0B,$53,$0A4
DC.B $0C3,$0D,$14,$A7,$6F,$92,$0B8,$5E
DC.B $50,$8E,$0C7,$6B,$9A,$34,$2D,$0F1
DC.B $0BD,$68,$7A,$0C1,$03,$5F,$0E4,$92
DC.B $1A,$0D0,$0C9,$7E,$0B6,$43,$2F,$85
DC.B $2D,$87,$50,$0E9,$0C3,$0B4,$0F6,$1A
DC.B $0BD,$16,$24,$0C9,$58,$0AF,$0E3,$70
DC.B $41,$0FA,$0ED,$36,$0B6,$59,$28,$0C7
DC.B $17,$2D,$8E,$53,$0B0,$0C6,$49,$0FA
DC.B $4D,$78,$2B,$0C5,$16,$0AF,$0E0,$93
DC.B $0FA,$16,$39,$0E0,$5C,$2B,$87,$4D
DC.B $93,$4F,$50,$0B6,$0CA,$71,$2D,$0E8
DC.B $82,$5C,$34,$0F1,$0D7,$0A,$0EB,$96
DC.B $5E,$0B,$0F2,$0AC,$34,$97,$8D,$61
DC.B $0F4,$92,$0C1,$5B,$6A,$3D,$07,$0E8
DC.B $6B,$0F8,$0C,$97,$0A1,$4E,$52,$3D
DC.B $0C,$0D1,$3A,$4F,$E9,$72,$56,$0B8
DC.B $6A,$1F,$0D4,$0E2,$07,$0BC,$39,$85
DC.B $79,$0E,$4F,$0A5,$12,$0D8,$0BC,$63
DC.B $0B4,$0E3,$12,$7C,$69,$05,$8F,$0DA
DC.B $34,$0CB,$92,$7E,$5F,$0A0,$68,$1D
DC.B $0ED,$30,$5B,$0C7,$24,$0F9,$81,$6A
DC.B $0A1,$0F4,$6B,$8D,$0C,$53,$97,$2E
DC.B $96,$5B,$0D,$0F8,$0E1,$24,$3A,$0C7
DC.B $0AD,$92,$38,$0E4,$56,$0F,$0CB,$71
DC.B $0C1,$05F,$6D,$0B8,$0A,$0E3,$97,$24
DC.B $07,$6B,$0A4,$0D1,$0F9,$3C,$5E,$82
DC.B $0F2,$0C1,$9E,$07,$34,$5A,$68,$0BD
E_TABLE
DC.B $10,$83,$73,$63,$53,$43,$0F,$0F
DC.B $53,$43,$33,$23,$13,$82,$0F,$0F
DC.B $13,$82,$72,$62,$52,$42,$0F,$0F
DC.B $52,$42,$32,$22,$12,$81,$0F,$0F
DC.B $12,$81,$71,$61,$51,$41,$0F,$0F
DC.B $51,$41,$31,$21,$11,$80,$0F,$0F
DC.B $11,$80,$70,$60,$50,$40,$0F,$0F
DC.B $50,$40,$30,$20,$10,$83,$0F,$0F
P_TABLE
DC.B $14,$26,$13,$42,$40,$15,$11,$43
DC.B $47,$24,$22,$31,$46,$33,$20,$35
DC.B $37,$16,$12,$34,$10,$21,$27,$45
DC.B $23,$44,$30,$36,$32,$25,$17,$41
segment byte at FFE0-FFFF 'vectit'
DC.W 0 ;FFE0-FFE1h location
DC.W 0 ;FFE2-FFE3h location
DC.W 0 ;FFE4-FFE5h location
DC.W 0 ;FFE6-FFE7h location
DC.W 0 ;FFE8-FFE9h location
DC.W 0 ;FFEA-FFEBh location
DC.W 0 ;FFEC-FFEDh location
DC.W 0 ;FFEE-FFEFh location
DC.W 0 ;FFF0-FFF1h location
DC.W 0 ;FFF2-FFF3h location
DC.W 0 ;FFF4-FFF5h location
DC.W 0 ;FFF6-FFF7h location
DC.W 0 ;FFF8-FFF9h location
DC.W 0 ;FFFA-FFFBh location
DC.W 0 ;FFFC-FFFDh location
.reset DC.W main ;FFFE-FFFFh location
; This last line refers to the first line.
; It used by the compiler/linker to determine code zone
END ; Be aware of the fact that the END directive should not
; stand on the left of the page like the labels's names.
点击这里回复这篇贴子>>
_____________________________________________________________________________
Copyright?,C51BBS论坛 2000-2001