c++ – How can I write a code in arm assembley incrept and decrept string and invert the first and second bits of the ASCII code of each character?

In this Question , I need to implement a simple encryption and decryption algorithm in ARM assembly. Given a text message (string) stored in the memory, the encryption program gets the ASCII code of each character and apply this method
*the method is: Invert the first and the second bits of the ASCII code of each character.
The encrypted character is stored back in a different location in the memory.

I have to write two assembly programs; encryption and decryption. The encryption program takes the text message stored in the memory at specific address and applies the encryption method on every single character and then stores the encrypted message in a different location in the memory. The decryption program takes the encrypted message and applies the reverse of the encryption process, which is called the key.

there are many solutions that I dont know which of them is the correct one ..and I don’t know if they are in Arm or ox86 assembly since I have started studying Assembly from few days
please tell me which of them is correct in Arm assembly and can be run in keil version 4
and I want you two know that all of these solutions missing something ( missing applying the invert method that the question asked to apply it )

the first sol:

segment code

start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,stacktop

%define encoderkey 'hello'
%strlen enkey encoderkey

main1:

    mov ah,00
    int 16h

    mov dl,al
        
        cmp al, 'q'           
        jz done

    mov ah,enkey
    add dl, ah

    mov ah,2
    int 0x21

jmp main1

done:
    mov ax,0x4c00
    int 0x21

segment data


segment stack stack
resb 64
stacktop:



segment code

start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,stacktop

%define encoderkey 'hello'
%strlen enkey encoderkey

main1:

    mov ah,00
    int 16h

    mov dl,al
        
        cmp al, 'q'           
        jz done

    mov ah,-5
    add dl, ah

    mov ah,2
    int 0x21

jmp main1

done:
    mov ax,0x4c00
    int 0x21

segment data


segment stack stack
resb 64
stacktop:

segment code

start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,stacktop

%define encoderkey 'hello'
%strlen enkey encoderkey

main1:

    mov dx,info1
    mov ah,9
    int 0x21

    mov dx,info2
    mov ah,9
    int 0x21

    mov dx,blankline
    mov ah,9
    int 0x21

    mov dx,message1
    mov ah,9
    int 0x21

    mov dx,message2
    mov ah,9
    int 0x21

    mov dx,blankline
    mov ah,9
    int 0x21

select:

    mov ah,00
    int 16h

    mov dl,al
        
        cmp al, '1'           
    jz encrypt

    cmp al,'2'
    jz decrypt

encrypt:

    mov dx,message3
    mov ah,9
    int 0x21

    mov dx,blankline
    mov ah,9
    int 0x21

main_encrypt:
    mov ah,00
    int 16h

    mov dl,al
        
        cmp al, 'q'           
    jz done

    mov ah,enkey
    add dl, ah

    mov ah,2
    int 0x21

jmp main_encrypt

decrypt:

    mov dx,message4
    mov ah,9
    int 0x21

    mov dx,blankline
    mov ah,9
    int 0x21

main_decrypt:
    mov ah,00
    int 16h

    mov dl,al
        
        cmp al, 'q'           
    jz done

    mov ah,-enkey
    add dl, ah

    mov ah,2
    int 0x21

jmp main_decrypt

done:
    mov ax,0x4c00
    int 0x21

segment data

info1: db 'Huo CoDec - Programmed by Spiros Kakos (Huo)', 13, 10, '$'
info2: db '(c) Copyright 2005 - All rights reserved', 13, 10, '$'
blankline: db ' ', 13, 10, '$'
message1: db '1 - Encrypt message', 13, 10, '$'
message2: db '2 - Decrypt message', 13, 10, '$'
message3: db 'Encrypting mode (q to exit)...', 13, 10, '$'
message4: db 'Decrypting mode (q to exit)...', 13, 10, '$'

segment stack stack
resb 64
stacktop:

THE 2nd sol:

is in c
is it correct ?
can I convert it to arm assembly using https://godbolt.org/ without problems and which compiler I should use , so the code can work in keil version 4?
compilers examples : ARM gcc 11.1 linux , armv7-a 9.0.0,…..and others

the code in c:

   //Simple C program to encrypt and decrypt a string

#include <stdio.h>

int main()
{
   int i, x;
   char str(100);

   printf("nPlease enter a string:t");
   gets(str);

   printf("nPlease choose following options:n");
   printf("1 = Encrypt the string.n");
   printf("2 = Decrypt the string.n");
   scanf("%d", &x);

   //using switch case statements
   switch(x)
   {
   case 1:
      for(i = 0; (i < 100 && str(i) != ''); i++)
        str(i) = str(i) + 3; //the key for encryption is 3 that is added to ASCII value

      printf("nEncrypted string: %sn", str);
      break;

   case 2:
      for(i = 0; (i < 100 && str(i) != ''); i++)
        str(i) = str(i) - 3; //the key for encryption is 3 that is subtracted to ASCII value

      printf("nDecrypted string: %sn", str);
      break;

   default:
      printf("nErrorn");
   }
   return 0;
}

the 3rd sol :

DATA SEGMENT
    MSG1 DB 10,13,’ENTER STRING HERE :- $’   
    MSG2 DB 10,13,’ENCRYPTED STRING IS :- $’
    MSG3 DB 10,13,’DECRYPTED STRING IS : $’
   
    P1 LABEL BYTE
    M1 DB 0FFH
    L1 DB ?
    P11 DB 0FFH DUP (‘$’)
   
DATA ENDS


 
DISPLAY MACRO MSG
    MOV AH,9
    LEA DX,MSG
    INT 21H
ENDM   
CODE SEGMENT
    ASSUME CS:CODE,DS:DATA
START:
        MOV AX,DATA
        MOV DS,AX                
               
        DISPLAY MSG1
       
        LEA DX,P1
        MOV AH,0AH    
        INT 21H
                      
        LEA SI,P11
        MOV CL,L1
        CALL ENCRYPT
       
        DISPLAY MSG2
        DISPLAY P11
                               
        LEA SI,P11
        MOV CL,L1
        CALL ENCRYPT
       
        DISPLAY MSG3
        DISPLAY P11
       
        MOV AH,4CH
        INT 21H
CODE ENDS


 
ENCRYPT PROC NEAR
        MOV CH,0       
CHECK1:
        CMP (SI),2FH
        JB DONE1
        CMP (SI),3AH
        JB NUM1
       
        CMP (SI),41H
        JB DONE1
        CMP (SI),5BH
        JB UPR1
       
        CMP (SI),61H
        JB DONE1
        CMP (SI),7BH
        JB LWR1
       
NUM1:    CMP (SI),35H
        JB LNUM1
        SUB (SI),05H
        JMP DONE1
   LNUM1:    
        ADD (SI),05H
        JMP DONE1   
       
UPR1:    CMP (SI),4EH
        JB LUPR1
        SUB (SI),0DH
        JMP DONE1
   LUPR1:    
        ADD (SI),0DH
        JMP DONE1


 
LWR1:    CMP (SI),6EH
        JB LLWR1
        SUB (SI),0DH
        JMP DONE1
   LLWR1:    
        ADD (SI),0DH
             
DONE1:       
        INC SI
        LOOP CHECK1
       RET
ENCRYPT ENDP

DECRYPT PROC NEAR
        MOV CH,0       
CHECK2:
        CMP (SI),2FH
        JB DONE2
        CMP (SI),3AH
        JB NUM2
       
        CMP (SI),41H
        JB DONE2
        CMP (SI),5BH
        JB UPR2
       
        CMP (SI),61H
        JB DONE2
        CMP (SI),7BH
        JB LWR2
       
NUM2:   CMP (SI),35H
        JB LNUM2
        ADD (SI),05H
        JMP DONE2
   LNUM2:    
        SUB (SI),05H
        JMP DONE2   
       
UPR2:    CMP (SI),4EH
        JB LUPR2
        ADD (SI),0DH
        JMP DONE2
   LUPR2:    
        SUB (SI),0DH
        JMP DONE2


 
LWR2:    CMP (SI),6EH
        JB LLWR2
        ADD (SI),0DH
        JMP DONE2
   LLWR2:    
        SUB (SI),0DH
             
DONE2:       
        INC SI
        LOOP CHECK2
       RET
DECRYPT ENDP
   
END START

the 4th sol.:

int 21h
read1:mov si,offset chr
mov ah,01h
int 21h
mov (si),al
inc si
mov al,24h
mov (si),al
mov bx,00
mov si,offset buf
mov ax,00
mov di,offset chr
check:mov al,(si)
cmp al,(di)
je count
cmp al,'$'
je dis
inc si
jmp check
count:inc bl
inc si
jmp check
dis:mov strlen,bl
lea si,res
mov ax,00
mov al,strlen
call hex2asc
lea dx,msg3
mov ah,09h
int 21h
lea dx,res
mov ah,09h
int 21h
ou:mov ax,4c00h
int 21h
main endp
hex2asc proc near
push ax
push bx
push cx
push dx
push si
mov cx,00h
mov bx,0Ah
rpt1: mov dx,00
div bx
add dl,'0'
push dx
inc cx
cmp ax,0Ah
jge rpt1
add al,'0'
mov (si),al
rpt2: pop ax
inc si
mov (si),al
loop rpt2
inc si
mov al,'$'
mov (si),al
pop si
pop dx
pop cx
pop bx
pop ax
ret
hex2asc endp
end
     


Prg(strrev.asm)
Title reversing a string
dosseg
.model small
.stack
.data
msg1 db 13,10,"Enter a string with dolar symbol as a break:$"
msg2 db 13,10,"Reverse of a string is:$"
strg db 20 DUP(0)
restr db 20 DUP(0)
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
mov di,00
lea dx,msg1
mov ah,09h
int 21h
read:mov ah,01h
int 21h
cmp al,24h
je next
inc di
mov strg(di),al
jmp read
next: mov si,00
start:cmp di,0
je dmsg2
mov al,strg(di)
mov restr(si),al
inc si
dec di
jmp start
dmsg2:lea dx,msg2
mov ah,09h
int 21h
dis:mov al,restr(di)
cmp al,0
je ou
mov dl,al
mov ah,02h
int 21h
inc di
jmp dis
ou: mov ax,4c00h
int 21h
main endp

the 5th sol. is in c++
is it correct ?
can I convert it to arm assembly using https://godbolt.org/ without problems and which compiler I should use , so the code can work in keil version 4?
compilers examples : ARM gcc 11.1 linux , armv7-a 9.0.0,…..and others

the code in c++:

// C++ to invert the characters
//using encryption and decryption algorithm
#include <bits/stdc++.h>
using namespace std;
// Function to encrypt the string
string encryption(string s)
{
int l = s.length();
int b = ceil(sqrt(l));
int a = floor(sqrt(l));
string encrypted;
if (b * a < l) {
if (min(b, a) == b) {
b = b + 1;
}
else {
a = a + 1;
}
}
// Matrix to invert the characters
// Encrypted String
char arr(a)(b);
memset(arr, ' ', sizeof(arr));
int k = 0;
// matrix of characters
for (int j = 0; j < a; j++) {
for (int i = 0; i < b; i++) {
if (k < l){
arr(j)(i) = s(k);
}
k++;
}
}
// encrypted string


for (int j = 0; j < b; j++) {
for (int i = 0; i < a; i++) {
encrypted = encrypted +
arr(i)(j);
}
}
return encrypted;
}
// Function to decrypt the string
string decryption(string s){
int l = s.length();
int b = ceil(sqrt(l));
int a = floor(sqrt(l));
string decrypted;
char arr(a)(b);
memset(arr, ' ', sizeof(arr));
int k = 0;
// column-wise matrix
for (int j = 0; j < b; j++) {
for (int i = 0; i < a; i++) {
if (k < l){
arr(j)(i) = s(k);
}
k++;
}
}
// decrypted string
for (int j = 0; j < a; j++) {
for (int i = 0; i < b; i++) {
decrypted = decrypted +
arr(i)(j);
}
}
return decrypted;

}
// main Code
int main()
{
string s = ""; //write the characters to be invert
string encrypted;
string decrypted;
//call encryption
// Encryption of String
encrypted = encryption(s);
cout << encrypted << endl;
//call decryption
// Decryption of String
decrypted = decryption(encrypted);
cout << decrypted;
return 0;
}