203 lines
6.6 KiB
Text
203 lines
6.6 KiB
Text
/* ARM assembly Raspberry PI */
|
|
/* program vignere.s */
|
|
/* REMARK 1 : this program use routines in a include file
|
|
see task Include a file language arm assembly
|
|
for the routine affichageMess conversion10
|
|
see at end of this program the instruction include */
|
|
|
|
/*******************************************/
|
|
/* Constantes */
|
|
/*******************************************/
|
|
.include "../constantes.inc"
|
|
|
|
.equ BUFFERSIZE, 2000
|
|
/*******************************************/
|
|
/* Macros */
|
|
/*******************************************/
|
|
//.include "../../ficmacros32.inc" @ for developer debugging
|
|
|
|
|
|
/*******************************************/
|
|
/* Initialized data */
|
|
/*******************************************/
|
|
.data
|
|
szMessDebutPgm: .asciz "Program 32 bits start. \n"
|
|
szCarriageReturn: .asciz "\n"
|
|
szMessFinOK: .asciz "Program normal end. \n"
|
|
szMessError: .asciz "\nError Buffer too small!!!\n"
|
|
szMessString: .asciz "String :\n"
|
|
szMessEncrip: .asciz "\nEncrypted :\n"
|
|
szMessDecrip: .asciz "\nDecrypted :\n"
|
|
szString1: .asciz "ABCDEFGHIJKLMNOPQRSTUVWXYZ!.?abcdefghijklmnopqrstuvwxyz"
|
|
//szString1: .asciz "attackatdawn"
|
|
//szString1: .asciz "ATTACKATDAWN"
|
|
szKey1: .asciz "LEMON"
|
|
/*******************************************/
|
|
/* UnInitialized data */
|
|
/*******************************************/
|
|
.bss
|
|
sBuffer1: .skip BUFFERSIZE
|
|
sBuffer2: .skip BUFFERSIZE
|
|
/*******************************************/
|
|
/* code section */
|
|
/*******************************************/
|
|
.text
|
|
.global main
|
|
main:
|
|
ldr r0,iAdrszMessDebutPgm
|
|
bl affichageMess
|
|
ldr r0,iAdrszMessString @ display message
|
|
bl affichageMess
|
|
ldr r0,iAdrszString1 @ display string
|
|
bl affichageMess
|
|
ldr r0,iAdrszString1 @ string address
|
|
ldr r1,iAdrszKey1 @ key
|
|
ldr r2,iAdrsBuffer1 @ encrypted buffer
|
|
bl encrypt
|
|
cmp r0,#0
|
|
ble 99f
|
|
ldr r0,iAdrszMessEncrip
|
|
bl affichageMess
|
|
ldr r0,iAdrsBuffer1 @ display encrypted buffer
|
|
bl affichageMess
|
|
|
|
ldr r0,iAdrsBuffer1 @ encrypted buffer
|
|
ldr r1,iAdrszKey1 @ key
|
|
ldr r2,iAdrsBuffer2 @ decrypted buffer
|
|
bl decrypt
|
|
ldr r0,iAdrszMessDecrip
|
|
bl affichageMess
|
|
ldr r0,iAdrsBuffer2 @ display decrypted buffer
|
|
bl affichageMess
|
|
ldr r0,iAdrszCarriageReturn
|
|
bl affichageMess
|
|
|
|
ldr r0,iAdrszMessFinOK
|
|
bl affichageMess
|
|
b 100f
|
|
99:
|
|
ldr r0,iAdrszMessError @ error
|
|
bl affichageMess
|
|
mov r0, #1
|
|
100: @ standard end of the program
|
|
mov r0, #0 @ return code
|
|
mov r7, #EXIT @ request to exit program
|
|
svc 0 @ perform system call
|
|
iAdrszMessString: .int szMessString
|
|
iAdrszMessDecrip: .int szMessDecrip
|
|
iAdrszMessEncrip: .int szMessEncrip
|
|
iAdrszString1: .int szString1
|
|
iAdrsBuffer1: .int sBuffer1
|
|
iAdrsBuffer2: .int sBuffer2
|
|
iAdrszKey1: .int szKey1
|
|
iAdrszMessDebutPgm: .int szMessDebutPgm
|
|
iAdrszMessFinOK: .int szMessFinOK
|
|
iAdrszCarriageReturn: .int szCarriageReturn
|
|
iAdrszMessError: .int szMessError
|
|
/******************************************************************/
|
|
/* encrypt strings */
|
|
/******************************************************************/
|
|
/* r0 contains the address of the string1 */
|
|
/* r1 contains key address
|
|
/* r2 contains the address of the encrypted string */
|
|
/* r0 return buffer lenght */
|
|
encrypt:
|
|
push {r3-r7,lr} @ save registers
|
|
mov r3,#0 @ counter byte string 1
|
|
mov r5,#0 @ counter byte buffer
|
|
1:
|
|
mov r4,#0 @ counter byte key
|
|
2:
|
|
cmp r5,#BUFFERSIZE @ max length buffer ?
|
|
movge r0,#-1 @ error
|
|
bge 100f
|
|
ldrb r6,[r1,r4] @ load a byte
|
|
cmp r6,#0 @ end key ?
|
|
beq 1b
|
|
sub r6,r6,#'A' @ character rang in alfabet
|
|
add r4,r4,#1
|
|
3:
|
|
ldrb r7,[r0,r3] @ load byte string 1
|
|
cmp r7,#0 @ zero final ?
|
|
streqb r7,[r2,r5]
|
|
moveq r0,r5
|
|
beq 100f
|
|
cmp r7,#65 @ < A ?
|
|
addlt r3,#1
|
|
blt 3b
|
|
cmp r7,#90 @ > Z
|
|
bgt 4f
|
|
add r7,r6 @ add key
|
|
cmp r7,#90 @ > Z
|
|
subgt r7,#26 @ - alphaget size
|
|
strb r7,[r2,r5] @ store result
|
|
add r5,r5,#1
|
|
add r3,r3,#1 @ other byte of string
|
|
b 2b @ other byte of key
|
|
4:
|
|
cmp r7,#97 @ < a ?
|
|
addlt r3,#1
|
|
blt 3b
|
|
cmp r7,#122 @> z
|
|
addgt r3,#1
|
|
bgt 3b
|
|
sub r7,#32 @ convert minuscul to majuscule
|
|
add r7,r6 @ add key
|
|
cmp r7,#90 @ if > Z
|
|
subgt r7,#26 @ - alphaget size
|
|
strb r7,[r2,r5] @ store result
|
|
add r5,r5,#1
|
|
add r3,#1
|
|
b 2b
|
|
|
|
100:
|
|
pop {r3-r7,lr} @ restaur registers
|
|
bx lr @ return
|
|
/******************************************************************/
|
|
/* decrypt strings */
|
|
/******************************************************************/
|
|
/* r0 contains the address of the encrypted string1 */
|
|
/* r1 contains the key */
|
|
/* r2 contains the address of the decrypted buffer */
|
|
decrypt:
|
|
push {r3-r7,lr} @ save registers
|
|
mov r3,#0 @ counter byte string 1
|
|
mov r5,#0 @ counter byte buffer
|
|
|
|
1:
|
|
mov r4,#0 @ counter byte key
|
|
2:
|
|
ldrb r6,[r1,r4] @ load byte key
|
|
cmp r6,#0 @ end key
|
|
beq 1b
|
|
sub r6,r6,#'A'
|
|
add r4,r4,#1
|
|
3:
|
|
ldrb r7,[r0,r3] @ load byte string 1
|
|
cmp r7,#0 @ zero final ?
|
|
streqb r7,[r2,r5]
|
|
moveq r0,r5
|
|
beq 100f
|
|
cmp r7,#65 @ < A ?
|
|
addlt r3,#1
|
|
blt 3b
|
|
cmp r7,#90 @ > Z
|
|
addgt r3,#1 @ no minuscul
|
|
bgt 3b
|
|
sub r7,r6 @ add key
|
|
cmp r7,#65 @ < A
|
|
addlt r7,#26 @
|
|
strb r7,[r2,r5]
|
|
add r5,r5,#1
|
|
add r3,r3,#1 @ other byte of string
|
|
b 2b @ other byte of key
|
|
|
|
|
|
100:
|
|
pop {r3-r7,lr} @ restaur registers
|
|
bx lr @ return
|
|
|
|
/***************************************************/
|
|
/* ROUTINES INCLUDE */
|
|
/***************************************************/
|
|
.include "../affichage.inc"
|