Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
394
Task/Bifid-cipher/AArch64-Assembly/bifid-cipher.aarch64
Normal file
394
Task/Bifid-cipher/AArch64-Assembly/bifid-cipher.aarch64
Normal file
|
|
@ -0,0 +1,394 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program bifid64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
|
||||
.equ MESSSIZE, 2000
|
||||
.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"
|
||||
//szString1: .asciz "ABCD"
|
||||
szString2: .asciz "FLEEATONCE"
|
||||
szString3: .asciz "The invasion will start on the first of January"
|
||||
|
||||
szPolybe1: .ascii "ABCDE"
|
||||
.ascii "FGHIK"
|
||||
.ascii "LMNOP"
|
||||
.ascii "QRSTU"
|
||||
.asciz "VWXYZ"
|
||||
|
||||
szPolybe2: .ascii "BGWKZ"
|
||||
.ascii "QPNDS"
|
||||
.ascii "IOAXE"
|
||||
.ascii "FCLUM"
|
||||
.asciz "THYVR"
|
||||
|
||||
/*******************************************/
|
||||
/* UnInitialized data */
|
||||
/*******************************************/
|
||||
.bss
|
||||
.align 4
|
||||
tabiposX: .skip 8 * MESSSIZE
|
||||
tabiposY: .skip 8 * MESSSIZE
|
||||
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,qAdrszPolybe1 // Polybe key
|
||||
ldr x2,qAdrsBuffex1 // encrypted buffer result
|
||||
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,qAdrszPolybe1 // Polybe 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,qAdrszMessString // display message
|
||||
bl affichageMess
|
||||
ldr x0,qAdrszString2 // display string
|
||||
bl affichageMess
|
||||
ldr x0,qAdrszString2 // string address
|
||||
ldr x1,qAdrszPolybe2 // Polybe key
|
||||
ldr x2,qAdrsBuffex1 // encrypted buffer result
|
||||
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,qAdrszPolybe2 // Polybe 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,qAdrszMessString // display message
|
||||
bl affichageMess
|
||||
ldr x0,qAdrszString1 // display string
|
||||
bl affichageMess
|
||||
ldr x0,qAdrszString1 // string address
|
||||
ldr x1,qAdrszPolybe2 // Polybe key
|
||||
ldr x2,qAdrsBuffex1 // encrypted buffer result
|
||||
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,qAdrszPolybe2 // Polybe 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,qAdrszMessString // display message
|
||||
bl affichageMess
|
||||
ldr x0,qAdrszString3 // display string
|
||||
bl affichageMess
|
||||
ldr x0,qAdrszString3 // string address
|
||||
ldr x1,qAdrszPolybe1 // Polybe key
|
||||
ldr x2,qAdrsBuffex1 // encrypted buffer result
|
||||
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,qAdrszPolybe1 // Polybe 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
|
||||
qAdrszPolybe1: .quad szPolybe1
|
||||
qAdrszString2: .quad szString2
|
||||
qAdrszString3: .quad szString3
|
||||
qAdrszPolybe2: .quad szPolybe2
|
||||
qAdrsBuffex1: .quad sBuffex1
|
||||
qAdrsBuffex2: .quad sBuffex2
|
||||
qAdrszMessDebutPgm: .quad szMessDebutPgm
|
||||
qAdrszMessFinOK: .quad szMessFinOK
|
||||
qAdrszCarriageReturn: .quad szCarriageReturn
|
||||
qAdrszMessError: .quad szMessError
|
||||
/******************************************************************/
|
||||
/* encrypt strings */
|
||||
/******************************************************************/
|
||||
/* r0 contains the address of the string1 */
|
||||
/* r1 contains Polybe area address
|
||||
/* r2 contains the address of the encrypted string */
|
||||
/* r0 return buffer lenght */
|
||||
encrypt:
|
||||
stp x1,lr,[sp,-16]! // save registers
|
||||
stp x2,x3,[sp,-16]! //
|
||||
stp x4,x5,[sp,-16]! //
|
||||
stp x6,x7,[sp,-16]! //
|
||||
stp x8,x9,[sp,-16]! //
|
||||
stp x10,x11,[sp,-16]! //
|
||||
mov x3,#0 // counter byte string 1
|
||||
mov x5,#0 // counter byte buffer
|
||||
1:
|
||||
ldrb w7,[x0,x3] // load byte string 1
|
||||
cmp x7,#0 // zero final ?
|
||||
beq 4f
|
||||
cmp x7,#65 // < A ?
|
||||
cinc x3,x3,lt
|
||||
blt 1b
|
||||
cmp x7,#90 // > Z
|
||||
ble 2f
|
||||
|
||||
cmp x7,#97 // < a ?
|
||||
cinc x3,x3,lt
|
||||
blt 1b
|
||||
cmp x7,#122 //> z
|
||||
cinc x3,x3,gt
|
||||
bgt 1b
|
||||
sub x7,x7,#32 // convert minuscul to majuscule
|
||||
2:
|
||||
mov x11,'I'
|
||||
cmp x7,#'J' // change J to I
|
||||
csel x7,x11,x7,eq
|
||||
ldr x11,qAdrtabiposX
|
||||
ldr x12,qAdrtabiposY
|
||||
mov x6,#0
|
||||
mov x9,#5
|
||||
3: // loop to search char in polybe square
|
||||
ldrb w8,[x1,x6] // load byte polybe
|
||||
cmp x8,x7 // equal ?
|
||||
cinc x6,x6,ne
|
||||
bne 3b
|
||||
udiv x10,x6,x9 // compute coordonnés
|
||||
msub x8,x10,x9,x6
|
||||
strb w10,[x11,x5] // save X position
|
||||
strb w8,[x12,x5] // save Y position
|
||||
add x5,x5,#1 // increment indice
|
||||
add x3,x3,#1
|
||||
b 1b // and loop
|
||||
|
||||
4:
|
||||
mov x6,#0
|
||||
mov x8,x5
|
||||
mov x5,#0
|
||||
mov x3,#5
|
||||
5: // convert position line 1 in char
|
||||
ldrb w9,[x11,x6]
|
||||
add x6,x6,#1
|
||||
cmp x6,x8 // first line end ?
|
||||
csel x6,xzr,x6,ge
|
||||
bge 7f // jmp for second line
|
||||
|
||||
ldrb w7,[x11,x6] // compute rank with position X and Y
|
||||
mul x9,x3,x9
|
||||
add x9,x9,x7
|
||||
ldrb w9,[x1,x9] // load polybe char
|
||||
strb w9,[x2,x5]
|
||||
add x5,x5,#1
|
||||
|
||||
add x6,x6,#1
|
||||
cmp x6,x8
|
||||
blt 5b
|
||||
|
||||
mov x6,#0
|
||||
6: // convert position line 2 in char
|
||||
ldrb w9,[x12,x6]
|
||||
add x6,x6,#1
|
||||
7:
|
||||
ldrb w7,[x12,x6] // compute rank with position X and Y
|
||||
mul x9,x3,x9
|
||||
add x9,x9,x7
|
||||
ldrb w9,[x1,x9] // load polybe char
|
||||
strb w9,[x2,x5]
|
||||
add x5,x5,#1
|
||||
add x6,x6,#1
|
||||
cmp x6,x8
|
||||
blt 6b
|
||||
|
||||
mov x9,#0 // zero final
|
||||
strb w9,[x2,x5]
|
||||
mov x0,x5
|
||||
100:
|
||||
ldp x10,x11,[sp],16 // restau registers
|
||||
ldp x8,x9,[sp],16 //
|
||||
ldp x6,x7,[sp],16 //
|
||||
ldp x4,x5,[sp],16 //
|
||||
ldp x2,x3,[sp],16 //
|
||||
ldp x1,lr,[sp],16 //
|
||||
ret
|
||||
qAdrtabiposX: .quad tabiposX
|
||||
qAdrtabiposY: .quad tabiposY
|
||||
/******************************************************************/
|
||||
/* decrypt strings */
|
||||
/******************************************************************/
|
||||
/* r0 contains the address of the encrypted string1 */
|
||||
/* r1 contains Polybe area address
|
||||
/* r2 contains the address of the decrypted string */
|
||||
/* r0 return buffer lenght */
|
||||
decrypt:
|
||||
stp x1,lr,[sp,-16]! // save registers
|
||||
stp x2,x3,[sp,-16]! //
|
||||
stp x4,x5,[sp,-16]! //
|
||||
stp x6,x7,[sp,-16]! //
|
||||
stp x8,x9,[sp,-16]! //
|
||||
stp x10,x11,[sp,-16]! //
|
||||
mov x3,#0 // counter byte string 1
|
||||
mov x5,#0 // counter byte result buffer
|
||||
1:
|
||||
ldrb w7,[x0,x3] // load byte string 1
|
||||
cmp x7,#0 // zero final ?
|
||||
csel x0,x5,x0,eq
|
||||
beq 4f
|
||||
|
||||
cmp x7,#65 // < A ?
|
||||
cinc x3,x3,lt
|
||||
blt 1b
|
||||
cmp x7,#90 // > Z
|
||||
ble 2f
|
||||
|
||||
cmp x7,#97 // < a ?
|
||||
cinc x3,x3,lt
|
||||
blt 1b
|
||||
cmp x7,#122 //> z
|
||||
cinc x3,x3,gt
|
||||
bgt 1b
|
||||
sub x7,x7,#32 // convert minuscul to majuscule
|
||||
2:
|
||||
ldr x11,qAdrtabiposX
|
||||
mov x6,#0
|
||||
mov x9,#5
|
||||
3: // loop to search char in polybe square
|
||||
ldrb w8,[x1,x6] // load byte polybe
|
||||
cmp x8,x7
|
||||
cinc x6,x6,ne
|
||||
bne 3b
|
||||
|
||||
udiv x10,x6,x9
|
||||
msub x8,x10,x9,x6
|
||||
strb w10,[x11,x5]
|
||||
add x5,x5,#1
|
||||
strb w8,[x11,x5]
|
||||
add x5,x5,#1
|
||||
|
||||
add x3,x3,#1
|
||||
b 1b
|
||||
|
||||
4:
|
||||
mov x6,#0 // start indice first line
|
||||
lsr x8,x5,#1
|
||||
mov x10,x8 // start indice second line
|
||||
mov x5,#0
|
||||
mov x3,#5
|
||||
|
||||
5:
|
||||
ldrb w9,[x11,x6] // load position
|
||||
ldrb w7,[x11,x10]
|
||||
mul x9,x3,x9 // compute rank
|
||||
add x9,x9,x7
|
||||
ldrb w9,[x1,x9] // load polybe byte
|
||||
strb w9,[x2,x5] // and store to result
|
||||
add x5,x5,#1
|
||||
add x10,x10,#1
|
||||
add x6,x6,#1
|
||||
cmp x6,x8 // end ?
|
||||
blt 5b
|
||||
|
||||
mov x9,#0 // 0 final
|
||||
strb w9,[x2,x5]
|
||||
mov x0,x5
|
||||
100:
|
||||
ldp x10,x11,[sp],16 // restaur registers
|
||||
ldp x8,x9,[sp],16 //
|
||||
ldp x6,x7,[sp],16 //
|
||||
ldp x4,x5,[sp],16 //
|
||||
ldp x2,x3,[sp],16 //
|
||||
ldp x1,lr,[sp],16 //
|
||||
ret
|
||||
|
||||
/***************************************************/
|
||||
/* ROUTINES INCLUDE */
|
||||
/***************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeARM64.inc"
|
||||
Loading…
Add table
Add a link
Reference in a new issue