223 lines
7.2 KiB
Text
223 lines
7.2 KiB
Text
/* ARM assembly AARCH64 Raspberry PI 3B */
|
|
/* program vignere64.s */
|
|
|
|
/*******************************************/
|
|
/* Constantes */
|
|
/*******************************************/
|
|
/* for this file see task include a file in language AArch64 assembly*/
|
|
.include "../includeConstantesARM64.inc"
|
|
|
|
.equ BUFFERSIZE, 2000
|
|
/*******************************************/
|
|
/* Macros */
|
|
/*******************************************/
|
|
//.include "../../ficmacros64.inc" // for developer debugging
|
|
|
|
|
|
/*******************************************/
|
|
/* Initialized data */
|
|
/*******************************************/
|
|
.data
|
|
szMessDebutPgm: .asciz "Program 64 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
|
|
sBuffex1: .skip BUFFERSIZE
|
|
sBuffex2: .skip BUFFERSIZE
|
|
/*******************************************/
|
|
/* code section */
|
|
/*******************************************/
|
|
.text
|
|
.global main
|
|
main:
|
|
ldr x0,qAdrszMessDebutPgm
|
|
bl affichageMess
|
|
ldr x0,qAdrszMessString // display message
|
|
bl affichageMess
|
|
ldr x0,qAdrszString1 // display string
|
|
bl affichageMess
|
|
ldr x0,qAdrszString1 // string address
|
|
ldr x1,qAdrszKey1 // key
|
|
ldr x2,qAdrsBuffex1 // encrypted buffer
|
|
bl encrypt
|
|
cmp x0,#0
|
|
ble 99f
|
|
ldr x0,qAdrszMessEncrip
|
|
bl affichageMess
|
|
ldr x0,qAdrsBuffex1 // display encrypted buffer
|
|
bl affichageMess
|
|
|
|
ldr x0,qAdrsBuffex1 // encrypted buffer
|
|
ldr x1,qAdrszKey1 // key
|
|
ldr x2,qAdrsBuffex2 // decrypted buffer
|
|
bl decrypt
|
|
ldr x0,qAdrszMessDecrip
|
|
bl affichageMess
|
|
ldr x0,qAdrsBuffex2 // display decrypted buffer
|
|
bl affichageMess
|
|
ldr x0,qAdrszCarriageReturn
|
|
bl affichageMess
|
|
|
|
ldr x0,qAdrszMessFinOK
|
|
bl affichageMess
|
|
b 100f
|
|
99:
|
|
ldr x0,qAdrszMessError // error
|
|
bl affichageMess
|
|
mov x0, #1
|
|
100: // standard end of the program
|
|
mov x0, #0 // return code
|
|
mov x8,EXIT
|
|
svc 0 // perform system call
|
|
qAdrszMessString: .quad szMessString
|
|
qAdrszMessDecrip: .quad szMessDecrip
|
|
qAdrszMessEncrip: .quad szMessEncrip
|
|
qAdrszString1: .quad szString1
|
|
qAdrsBuffex1: .quad sBuffex1
|
|
qAdrsBuffex2: .quad sBuffex2
|
|
qAdrszKey1: .quad szKey1
|
|
qAdrszMessDebutPgm: .quad szMessDebutPgm
|
|
qAdrszMessFinOK: .quad szMessFinOK
|
|
qAdrszCarriageReturn: .quad szCarriageReturn
|
|
qAdrszMessError: .quad szMessError
|
|
/******************************************************************/
|
|
/* encrypt strings */
|
|
/******************************************************************/
|
|
/* x0 contains the address of the string1 */
|
|
/* x1 contains key address
|
|
/* x2 contains the address of the encrypted string */
|
|
/* x0 return buffer lenght */
|
|
encrypt:
|
|
stp x3,lr,[sp,-16]! // save registers
|
|
stp x4,x5,[sp,-16]! // save registers
|
|
stp x6,x7,[sp,-16]! // save registers
|
|
stp x8,x9,[sp,-16]! // save registers
|
|
mov x3,#0 // counter byte string 1
|
|
mov x5,#0 // counter byte buffer
|
|
1:
|
|
mov x4,#0 // counter byte key
|
|
2:
|
|
cmp x5,#BUFFERSIZE // max length buffer ?
|
|
bge 99f
|
|
ldrb w6,[x1,x4] // load a byte
|
|
cmp x6,#0 // end key ?
|
|
beq 1b
|
|
sub x6,x6,#'A' // character rang in alfabet
|
|
add x4,x4,#1
|
|
3:
|
|
ldrb w7,[x0,x3] // load byte string 1
|
|
cmp w7,#0 // zero final ?
|
|
bne 4f
|
|
strb w7,[x2,x5]
|
|
mov x0,x5
|
|
b 100f
|
|
4:
|
|
cmp x7,#65 // < A ?
|
|
cinc x3,x3,lt
|
|
blt 3b
|
|
cmp x7,#90 // > Z
|
|
bgt 5f
|
|
add x7,x7,x6 // add key
|
|
sub x8,x7,26
|
|
cmp x7,#90 // > Z
|
|
csel x7,x8,x7,gt
|
|
strb w7,[x2,x5] // store result
|
|
add x5,x5,#1
|
|
add x3,x3,#1 // other byte of string
|
|
b 2b // other byte of key
|
|
5:
|
|
cmp x7,#97 // < a ?
|
|
cinc x3,x3,lt
|
|
blt 3b
|
|
cmp x7,#122 //> z
|
|
cinc x3,x3,gt
|
|
bgt 3b
|
|
sub x7,x7,#32 // convert minuscul to majuscule
|
|
add x7,x7,x6 // add key
|
|
cmp x7,#90 // if > Z
|
|
ble 6f
|
|
sub x7,x7,#26 // - alphaget size
|
|
6:
|
|
strb w7,[x2,x5] // store result
|
|
add x5,x5,#1
|
|
add x3,x3,#1
|
|
b 2b
|
|
|
|
99:
|
|
mov x0,#-1 // error
|
|
|
|
100:
|
|
ldp x8,x9,[sp],16 // restaur registers
|
|
ldp x6,x7,[sp],16 // restaur registers
|
|
ldp x4,x5,[sp],16 // restaur registers
|
|
ldp x3,lr,[sp],16 // restaur registers
|
|
ret
|
|
/******************************************************************/
|
|
/* decrypt strings */
|
|
/******************************************************************/
|
|
/* x0 contains the address of the encrypted string1 */
|
|
/* x1 contains the key */
|
|
/* x2 contains the address of the decrypted buffer */
|
|
decrypt:
|
|
stp x3,lr,[sp,-16]! // save registers
|
|
stp x4,x5,[sp,-16]! // save registers
|
|
stp x6,x7,[sp,-16]! // save registers
|
|
stp x8,x9,[sp,-16]! // save registers
|
|
mov x3,#0 // counter byte string 1
|
|
mov x5,#0 // counter byte buffer
|
|
|
|
1:
|
|
mov x4,#0 // counter byte key
|
|
2:
|
|
ldrb w6,[x1,x4] // load byte key
|
|
cmp w6,#0 // end key
|
|
beq 1b
|
|
sub x6,x6,#'A'
|
|
add x4,x4,#1
|
|
3:
|
|
ldrb w7,[x0,x3] // load byte string 1
|
|
cmp x7,#0 // zero final ?
|
|
bne 4f
|
|
strb w7,[x2,x5]
|
|
mov x0,x5
|
|
b 100f
|
|
4:
|
|
cmp x7,#65 // < A ?
|
|
cinc x3,x3,lt
|
|
blt 3b
|
|
cmp x7,#90 // > Z
|
|
cinc x3,x3,gt // no minuscul
|
|
bgt 3b
|
|
sub x7,x7,x6 // add key
|
|
add x8,x7,26
|
|
cmp x7,#65 // < A
|
|
csel x7,x8,x7,lt
|
|
strb w7,[x2,x5]
|
|
add x5,x5,#1
|
|
add x3,x3,#1 // other byte of string
|
|
b 2b // other byte of key
|
|
|
|
|
|
100:
|
|
ldp x8,x9,[sp],16 // restaur registers
|
|
ldp x6,x7,[sp],16 // restaur registers
|
|
ldp x4,x5,[sp],16 // restaur registers
|
|
ldp x3,lr,[sp],16 // restaur registers
|
|
ret
|
|
|
|
/***************************************************/
|
|
/* ROUTINES INCLUDE */
|
|
/***************************************************/
|
|
/* for this file see task include a file in language AArch64 assembly*/
|
|
.include "../includeARM64.inc"
|