An Assembly Language program two subroutines encrypting and decrypting – IGNOU MCA Assignment 2013

By | April 15, 2014

MASTER OF COMPUTER APPLICATIONS
Course Code : MCSL-017
Course Title : C and Assembly Language Programming
Assignment Number : MCA(1)/L017/Assign/2013 

 

Write a Program in assembly language that has two subroutines: One for encrypting alphabets of a string and second for decrypting the encoded string. In Encryption, simply convert a character /number into its predefined numerical/character value. Decryption is a reverse process of encryption. Write suitable Main program in C that calls these function. Test your program suitably

 

 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

 

program code :

  1.  DATA SEGMENT
  2.     MSG1 DB 10,13,'ENTER STRING HERE :- $'   
  3.     MSG2 DB 10,13,'ENCRYPTED STRING IS :- $'
  4.     MSG3 DB 10,13,'DECRYPTED STRING IS : $'
  5.    
  6.     P1 LABEL BYTE
  7.     M1 DB 0FFH
  8.     L1 DB ?
  9.     P11 DB 0FFH DUP ('$')
  10.    
  11. DATA ENDS
  12. DISPLAY MACRO MSG
  13.     MOV AH,9
  14.     LEA DX,MSG
  15.     INT 21H
  16. ENDM   
  17. CODE SEGMENT
  18.     ASSUME CS:CODE,DS:DATA
  19. START:
  20.         MOV AX,DATA
  21.         MOV DS,AX                
  22.                
  23.         DISPLAY MSG1
  24.        
  25.         LEA DX,P1
  26.         MOV AH,0AH    
  27.         INT 21H
  28.                       
  29.         LEA SI,P11
  30.         MOV CL,L1
  31.         CALL ENCRYPT
  32.        
  33.         DISPLAY MSG2
  34.         DISPLAY P11
  35.                                
  36.         LEA SI,P11
  37.         MOV CL,L1
  38.         CALL ENCRYPT
  39.        
  40.         DISPLAY MSG3
  41.         DISPLAY P11
  42.        
  43.         MOV AH,4CH
  44.         INT 21H
  45. CODE ENDS
  46. ENCRYPT PROC NEAR
  47.         MOV CH,0       
  48. CHECK1:
  49.         CMP [SI],2FH
  50.         JB DONE1
  51.         CMP [SI],3AH
  52.         JB NUM1
  53.        
  54.         CMP [SI],41H
  55.         JB DONE1
  56.         CMP [SI],5BH
  57.         JB UPR1
  58.        
  59.         CMP [SI],61H
  60.         JB DONE1
  61.         CMP [SI],7BH
  62.         JB LWR1
  63.        
  64. NUM1:    CMP [SI],35H
  65.         JB LNUM1
  66.         SUB [SI],05H
  67.         JMP DONE1
  68.    LNUM1:    
  69.         ADD [SI],05H
  70.         JMP DONE1   
  71.        
  72. UPR1:    CMP [SI],4EH
  73.         JB LUPR1
  74.         SUB [SI],0DH
  75.         JMP DONE1
  76.    LUPR1:    
  77.         ADD [SI],0DH
  78.         JMP DONE1
  79. LWR1:    CMP [SI],6EH
  80.         JB LLWR1
  81.         SUB [SI],0DH
  82.         JMP DONE1
  83.    LLWR1:    
  84.         ADD [SI],0DH
  85.              
  86. DONE1:       
  87.         INC SI
  88.         LOOP CHECK1
  89.        RET
  90. ENCRYPT ENDP
  91. DECRYPT PROC NEAR
  92.         MOV CH,0       
  93. CHECK2:
  94.         CMP [SI],2FH
  95.         JB DONE2
  96.         CMP [SI],3AH
  97.         JB NUM2
  98.        
  99.         CMP [SI],41H
  100.         JB DONE2
  101.         CMP [SI],5BH
  102.         JB UPR2
  103.        
  104.         CMP [SI],61H
  105.         JB DONE2
  106.         CMP [SI],7BH
  107.         JB LWR2
  108.        
  109. NUM2:   CMP [SI],35H
  110.         JB LNUM2
  111.         ADD [SI],05H
  112.         JMP DONE2
  113.    LNUM2:    
  114.         SUB [SI],05H
  115.         JMP DONE2   
  116.        
  117. UPR2:    CMP [SI],4EH
  118.         JB LUPR2
  119.         ADD [SI],0DH
  120.         JMP DONE2
  121.    LUPR2:    
  122.         SUB [SI],0DH
  123.         JMP DONE2
  124. LWR2:    CMP [SI],6EH
  125.         JB LLWR2
  126.         ADD [SI],0DH
  127.         JMP DONE2
  128.    LLWR2:    
  129.         SUB [SI],0DH
  130.              
  131. DONE2:       
  132.         INC SI
  133.         LOOP CHECK2
  134.        RET
  135. DECRYPT ENDP
  136.    
  137. END START

Screen shots :-

Asm_program_Encrpt_Decrypt

Output :-

Asm_program_Encrpt_Decrypt_Output

Leave a Reply