Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a MARIE program to encode your name and ID as a string The following example of a MARIE string nameID encodes a name

    Write a MARIE program to encode your name and ID as a string The following example of a MARIE string  student submitted image, transcription available belowstudent submitted image, transcription available belowstudent submitted image, transcription available belowstudent submitted image, transcription available belowstudent submitted image, transcription available belowstudent submitted image, transcription available below
 
 
 

Write a MARIE program to encode your name and ID as a string The following example of a MARIE string "nameID" encodes a name and an ID using ASCII characters. The "name" is separated from the ID by an ASCII character "Hex 00A" (New Line). Different parts of a name are separated by another ASCII character "Hex 020" (Space). And, the string is terminated by a dot character. The label "addrNameID" holds the address of the first character of the string. You need to follow this MARIE string while solving the task given below. addrNameID, ADR namelD nameID, HEX 04A HEX 06F HEX 068 HEX 06E HEX 020 HEX 04E HEX 067 HEX 075 HEX 079 HEX 065 HEX 06E HEX 00A HEX 032 HEX 031 HEX 032 HEX 033 HEX 039 HEX 037 HEX 039 HEX 038 HEX 02E ['J' l'o' /'h' /'n' /Space /'N' I'g' l'u' l'y' l'e' /'n' /NL(New Line) /'2' /'1' /'2' /'3' 1'9' ('7' /'9' /'8' Encode a string that includes your full name (first name and last name) and your student ID using ASCII characters. Following the above example, you need to use two labels, one label (e.g. "nameID") to store the first character of the string, and another label (e.g. "addrNameID") to store the address of the first character of the same string. You need to use the ADR command and HEX keywords (like the above example), so that after assembling, your name, ID and the address (of the first character of the string) is stored in MARIE memory. 2.2 Write a MARIE program to print the name and ID using subroutines (15 marks) Prepare a MARIE subroutine called subPrintString that can print the ASCII terminated string of your name and your student ID that you have implemented above. You may use the "Output" instruction to print characters in the MARIE output space. To receive full marks, your program must have a subroutine to print the name and ID string. The subroutine needs to be called from a MARIE main program using a JnS instruction. Hint: In your main program, you need to use a label "StringAdd" that holds the start address of the string (like, addrNameID) that you want to print. Then, you should call the subroutine subPrintString. In the subroutine, the codes should then load a character from the address "StringAdd", print the character, then increment the address by one, and keep doing that upto the character loaded from the address is a' (which signals the end of the string). The output may look similar to the output below. John Nguyen 21239798 2.3 Implementation of Caesar Cipher Substitution to encrypt a string (20 marks) In this section, we are going to implement Caesar Cipher (a type of substitution cipher) encryption that we have learned in the Cryptography lab. It replaces each character in a string by a different character of the alphabet defined by a simple shift. An encryption "Key" using a shift of 3 positions, shown in the table below. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z defghijklmnopqrstuvwx|yz|ab|c This is a very simple form of encryption. Please note the use of lower case alphabets only, and we will encrypt or decrypt only "alphabets". One more example "Key" below is showing a Caesar Cipher with a shift of 5 positions. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z fghijklmnopqrstuvwxyz abcde To encrypt, each letter in the top row is replaced by the corresponding letter in the bottom row, and to decrypt, each letter in the bottom row is replaced by the corresponding letter in the top row. In this part, your task is to implement subroutines that perform Caesar cipher substitution on a string, either performing encryption or decryption (cipher or decipher). You will implement the mapping in MARIE by a lookup table, storing the result of the substitution for each letter. The lookup table below maps an encryption key using a shift of 3 positions. myEncKeylAddr, myEncKeyl, ADR HEX HEX 065 / b HEX 066 / c HEX 067 / d HEX 068 HEX 069 / f HEX 06A / g HEX 06B / h HEX 06C HEX 06D HEX 06E HEX 06F HEX 070 HEX 071 HEX 072 HEX 073/p HEX 074/ q HEX 075 HEX 076 / s HEX 077 / t HEX 078 HEX 079 HEX 07A HEX 061 HEX 062 HEX 063 myEnckey1 064/ a -> d -> e -> -> -> -> / V / W / x / y / z -> j ^ ^ ^ -> k /i -> thi (D / j / k -> / 1 -> / m -> /n -> / 0 HECO 1 m n HQ T S -> -> u < C -> V -> -> -> -> -> -> b -> C W 3 XNQ Z a A subroutine to perform encryption on a string In this task, you will implement a MARIE subroutine called subCaesarEnc that can perform encryption using Caesar cipher substitution on a string whose start address is passed as an argument in the EncryptStr label. You need to use the "name" part of the string referred to in section 2.1 (name/D containing your first name and last name) to encrypt. You need to display the string before and after the encryption process. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table "myEnckey1", and then store that value back into memory (overwriting the original letter). Think about how to get "a value" from a table. E.g., assume that the original letter is 'k', which is the 11th letter in the alphabet. So we need to load the 11th entry in the table- in other words, the entry at address myEncKey1Addr + 10 (which is HEX 06E or DEC 110, or the letter 'n'). The letter 'k' has an ASCII value of HEX 06B (DEC 107). So, how do we determine to add '10' to the address "myEncKey1Addr"? We simply subtract the ASCII value for the letter 'a', which is HEX 061 (DEC 97). So, in decimal notation, "117 - 97 = 10" or in HEX notation, "HEX 06B - HEX 061 = HEX A." The following illustrated example explains the encryption process further. Here, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 070 073 S 061 074 072 069 063 t i a r During the encryption process, the following transformation (in the memory) will occur. Load Store Jns sdwulf nohh And, the new encrypted string will be stored in the memory as shown below. W Load Store Jns Halt u 06B 020 06C k I patricklee 064 077 075 06C 066 06E 020 06F d I f /printing the string before encryption Load addrName ID PrintStringAddr Store Jns subPrintString /printing the string after addrName ID PrintStringAddr subPrintString n /calling the subroutine to perform encryption addrName ID EncryptStr subCaesarEnc 065 065 02E e 0 Please note that, during the encryption process, ASCII value for "SPACE" and remains unchanged. To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. You may use the following template to begin with. Here, we are (re)using the subPrintString subroutine from section 2.2. 068 h e 068 h / Load string start address / Pass as an argument / Call printing subroutine 02E / Load string start address / Pass as an argument / Call the cipher subroutine encryption / Load string start address /Pass as an argument / Call printing subroutine /Your subroutine "subCaesarEnc" EncryptStr, Dec 0 subCaesarEnc, HEX 0 / Your codes..... /Your subroutine ends here. 2.4 A subroutine to perform decryption on a string (20 marks). In this part, we want to decrypt a string. To do that, we need a second table (in addition to the encryption table "myEncKeyl" in section 2.3) that has the reverse mapping. Add a table "myDeckey1" to your code that is exactly the inverse of the "myEncKey1" table above. myDecKeylAddr, myDecKeyl, ADR HEX ??? HEX ??? . 070 begins here. / variable or label to store the start / address of a string label (subroutine name) to begin the / subroutine myDecKeyl / /b HEX ??? Output log RTL log OUTPUT MODE: UNICODE -> Modify your subroutine in section 2.3 to create a new subroutine performing decryption. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table, and then store that value back into memory (overwriting the original letter). Watch list / 2 -> W X Input list John Nguyen Jrkq Njxbhq John Nguyen The following illustrated example explains the decryption process further. Here, you will encrypt the string first, storing the encrypted string back in the memory, and then, decrypt this string back to the original form. In this example, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 061 074 072 069 063 06B 020 06C 065 065 02E 073 S a 070 t r During the encryption process, the following transformation (in the memory) will occur. And, the new encrypted string will be stored in the memory as shown below. W a u 061 074 072 t i 064 077 075 06C 066 06E 020 06F d I f r patricklee sdwulf nohh k /Encrypting the string Load addrName ID Store EncryptStr Jns subCaesarEnc Now, you will decrypt the above string "sdwulfn ohh." to its original form "patrick lee." /To print the original string Load addrName ID Store PrintStringAddr Jns subPrintString 069 063 i /Decrypting the string Load addrName ID Store DecryptStr /print the encrypted string Load addrNameID Store PrintStringAddr Jns subPrintString C n e 0 068 h / Load string start address / Pass as an argument e To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. Please note that, as you need to encrypt the string first, so that you can decrypt an already encrypted string, there is a series of activities involved here [Print the original string-> Encryption -> Print the encrypted string-> Decryption -> Print the original string]. You may use the following template to begin with. e 06B 020 06C 065 065 02E k / Load string start address /Pass as an argument / Call printing subroutine 068 h / Load string start address / Pass as an argument / Call printing subroutine / Load string start address / Pass as an argument 02E e / Call the Encryption cipher subroutine Jns subCaesarDec /print the decrypted string addrName ID Load Store Jns Halt PrintStringAddr subPrintString Your subroutine "subCaesarDec" DecryptStr, DEC 0 subCaesarDec, HEX 0 / Your codes..... /Your subroutine ends here. / Call the Decryption cipher subroutine / Load string start address /Pass as an argument / Call printing subroutine begins here. / variable or label to store the start / address of a string / label (subroutine name) to begin the / subroutine Write a MARIE program to encode your name and ID as a string The following example of a MARIE string "nameID" encodes a name and an ID using ASCII characters. The "name" is separated from the ID by an ASCII character "Hex 00A" (New Line). Different parts of a name are separated by another ASCII character "Hex 020" (Space). And, the string is terminated by a dot character. The label "addrNameID" holds the address of the first character of the string. You need to follow this MARIE string while solving the task given below. addrNameID, ADR namelD nameID, HEX 04A HEX 06F HEX 068 HEX 06E HEX 020 HEX 04E HEX 067 HEX 075 HEX 079 HEX 065 HEX 06E HEX 00A HEX 032 HEX 031 HEX 032 HEX 033 HEX 039 HEX 037 HEX 039 HEX 038 HEX 02E ['J' l'o' /'h' /'n' /Space /'N' I'g' l'u' l'y' l'e' /'n' /NL(New Line) /'2' /'1' /'2' /'3' 1'9' ('7' /'9' /'8' Encode a string that includes your full name (first name and last name) and your student ID using ASCII characters. Following the above example, you need to use two labels, one label (e.g. "nameID") to store the first character of the string, and another label (e.g. "addrNameID") to store the address of the first character of the same string. You need to use the ADR command and HEX keywords (like the above example), so that after assembling, your name, ID and the address (of the first character of the string) is stored in MARIE memory. 2.2 Write a MARIE program to print the name and ID using subroutines (15 marks) Prepare a MARIE subroutine called subPrintString that can print the ASCII terminated string of your name and your student ID that you have implemented above. You may use the "Output" instruction to print characters in the MARIE output space. To receive full marks, your program must have a subroutine to print the name and ID string. The subroutine needs to be called from a MARIE main program using a JnS instruction. Hint: In your main program, you need to use a label "StringAdd" that holds the start address of the string (like, addrNameID) that you want to print. Then, you should call the subroutine subPrintString. In the subroutine, the codes should then load a character from the address "StringAdd", print the character, then increment the address by one, and keep doing that upto the character loaded from the address is a' (which signals the end of the string). The output may look similar to the output below. John Nguyen 21239798 2.3 Implementation of Caesar Cipher Substitution to encrypt a string (20 marks) In this section, we are going to implement Caesar Cipher (a type of substitution cipher) encryption that we have learned in the Cryptography lab. It replaces each character in a string by a different character of the alphabet defined by a simple shift. An encryption "Key" using a shift of 3 positions, shown in the table below. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z defghijklmnopqrstuvwx|yz|ab|c This is a very simple form of encryption. Please note the use of lower case alphabets only, and we will encrypt or decrypt only "alphabets". One more example "Key" below is showing a Caesar Cipher with a shift of 5 positions. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z fghijklmnopqrstuvwxyz abcde To encrypt, each letter in the top row is replaced by the corresponding letter in the bottom row, and to decrypt, each letter in the bottom row is replaced by the corresponding letter in the top row. In this part, your task is to implement subroutines that perform Caesar cipher substitution on a string, either performing encryption or decryption (cipher or decipher). You will implement the mapping in MARIE by a lookup table, storing the result of the substitution for each letter. The lookup table below maps an encryption key using a shift of 3 positions. myEncKeylAddr, myEncKeyl, ADR HEX HEX 065 / b HEX 066 / c HEX 067 / d HEX 068 HEX 069 / f HEX 06A / g HEX 06B / h HEX 06C HEX 06D HEX 06E HEX 06F HEX 070 HEX 071 HEX 072 HEX 073/p HEX 074/ q HEX 075 HEX 076 / s HEX 077 / t HEX 078 HEX 079 HEX 07A HEX 061 HEX 062 HEX 063 myEnckey1 064/ a -> d -> e -> -> -> -> / V / W / x / y / z -> j ^ ^ ^ -> k /i -> thi (D / j / k -> / 1 -> / m -> /n -> / 0 HECO 1 m n HQ T S -> -> u < C -> V -> -> -> -> -> -> b -> C W 3 XNQ Z a A subroutine to perform encryption on a string In this task, you will implement a MARIE subroutine called subCaesarEnc that can perform encryption using Caesar cipher substitution on a string whose start address is passed as an argument in the EncryptStr label. You need to use the "name" part of the string referred to in section 2.1 (name/D containing your first name and last name) to encrypt. You need to display the string before and after the encryption process. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table "myEnckey1", and then store that value back into memory (overwriting the original letter). Think about how to get "a value" from a table. E.g., assume that the original letter is 'k', which is the 11th letter in the alphabet. So we need to load the 11th entry in the table- in other words, the entry at address myEncKey1Addr + 10 (which is HEX 06E or DEC 110, or the letter 'n'). The letter 'k' has an ASCII value of HEX 06B (DEC 107). So, how do we determine to add '10' to the address "myEncKey1Addr"? We simply subtract the ASCII value for the letter 'a', which is HEX 061 (DEC 97). So, in decimal notation, "117 - 97 = 10" or in HEX notation, "HEX 06B - HEX 061 = HEX A." The following illustrated example explains the encryption process further. Here, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 070 073 S 061 074 072 069 063 t i a r During the encryption process, the following transformation (in the memory) will occur. Load Store Jns sdwulf nohh And, the new encrypted string will be stored in the memory as shown below. W Load Store Jns Halt u 06B 020 06C k I patricklee 064 077 075 06C 066 06E 020 06F d I f /printing the string before encryption Load addrName ID PrintStringAddr Store Jns subPrintString /printing the string after addrName ID PrintStringAddr subPrintString n /calling the subroutine to perform encryption addrName ID EncryptStr subCaesarEnc 065 065 02E e 0 Please note that, during the encryption process, ASCII value for "SPACE" and remains unchanged. To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. You may use the following template to begin with. Here, we are (re)using the subPrintString subroutine from section 2.2. 068 h e 068 h / Load string start address / Pass as an argument / Call printing subroutine 02E / Load string start address / Pass as an argument / Call the cipher subroutine encryption / Load string start address /Pass as an argument / Call printing subroutine /Your subroutine "subCaesarEnc" EncryptStr, Dec 0 subCaesarEnc, HEX 0 / Your codes..... /Your subroutine ends here. 2.4 A subroutine to perform decryption on a string (20 marks). In this part, we want to decrypt a string. To do that, we need a second table (in addition to the encryption table "myEncKeyl" in section 2.3) that has the reverse mapping. Add a table "myDeckey1" to your code that is exactly the inverse of the "myEncKey1" table above. myDecKeylAddr, myDecKeyl, ADR HEX ??? HEX ??? . 070 begins here. / variable or label to store the start / address of a string label (subroutine name) to begin the / subroutine myDecKeyl / /b HEX ??? Output log RTL log OUTPUT MODE: UNICODE -> Modify your subroutine in section 2.3 to create a new subroutine performing decryption. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table, and then store that value back into memory (overwriting the original letter). Watch list / 2 -> W X Input list John Nguyen Jrkq Njxbhq John Nguyen The following illustrated example explains the decryption process further. Here, you will encrypt the string first, storing the encrypted string back in the memory, and then, decrypt this string back to the original form. In this example, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 061 074 072 069 063 06B 020 06C 065 065 02E 073 S a 070 t r During the encryption process, the following transformation (in the memory) will occur. And, the new encrypted string will be stored in the memory as shown below. W a u 061 074 072 t i 064 077 075 06C 066 06E 020 06F d I f r patricklee sdwulf nohh k /Encrypting the string Load addrName ID Store EncryptStr Jns subCaesarEnc Now, you will decrypt the above string "sdwulfn ohh." to its original form "patrick lee." /To print the original string Load addrName ID Store PrintStringAddr Jns subPrintString 069 063 i /Decrypting the string Load addrName ID Store DecryptStr /print the encrypted string Load addrNameID Store PrintStringAddr Jns subPrintString C n e 0 068 h / Load string start address / Pass as an argument e To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. Please note that, as you need to encrypt the string first, so that you can decrypt an already encrypted string, there is a series of activities involved here [Print the original string-> Encryption -> Print the encrypted string-> Decryption -> Print the original string]. You may use the following template to begin with. e 06B 020 06C 065 065 02E k / Load string start address /Pass as an argument / Call printing subroutine 068 h / Load string start address / Pass as an argument / Call printing subroutine / Load string start address / Pass as an argument 02E e / Call the Encryption cipher subroutine Jns subCaesarDec /print the decrypted string addrName ID Load Store Jns Halt PrintStringAddr subPrintString Your subroutine "subCaesarDec" DecryptStr, DEC 0 subCaesarDec, HEX 0 / Your codes..... /Your subroutine ends here. / Call the Decryption cipher subroutine / Load string start address /Pass as an argument / Call printing subroutine begins here. / variable or label to store the start / address of a string / label (subroutine name) to begin the / subroutine Write a MARIE program to encode your name and ID as a string The following example of a MARIE string "nameID" encodes a name and an ID using ASCII characters. The "name" is separated from the ID by an ASCII character "Hex 00A" (New Line). Different parts of a name are separated by another ASCII character "Hex 020" (Space). And, the string is terminated by a dot character. The label "addrNameID" holds the address of the first character of the string. You need to follow this MARIE string while solving the task given below. addrNameID, ADR namelD nameID, HEX 04A HEX 06F HEX 068 HEX 06E HEX 020 HEX 04E HEX 067 HEX 075 HEX 079 HEX 065 HEX 06E HEX 00A HEX 032 HEX 031 HEX 032 HEX 033 HEX 039 HEX 037 HEX 039 HEX 038 HEX 02E ['J' l'o' /'h' /'n' /Space /'N' I'g' l'u' l'y' l'e' /'n' /NL(New Line) /'2' /'1' /'2' /'3' 1'9' ('7' /'9' /'8' Encode a string that includes your full name (first name and last name) and your student ID using ASCII characters. Following the above example, you need to use two labels, one label (e.g. "nameID") to store the first character of the string, and another label (e.g. "addrNameID") to store the address of the first character of the same string. You need to use the ADR command and HEX keywords (like the above example), so that after assembling, your name, ID and the address (of the first character of the string) is stored in MARIE memory. 2.2 Write a MARIE program to print the name and ID using subroutines (15 marks) Prepare a MARIE subroutine called subPrintString that can print the ASCII terminated string of your name and your student ID that you have implemented above. You may use the "Output" instruction to print characters in the MARIE output space. To receive full marks, your program must have a subroutine to print the name and ID string. The subroutine needs to be called from a MARIE main program using a JnS instruction. Hint: In your main program, you need to use a label "StringAdd" that holds the start address of the string (like, addrNameID) that you want to print. Then, you should call the subroutine subPrintString. In the subroutine, the codes should then load a character from the address "StringAdd", print the character, then increment the address by one, and keep doing that upto the character loaded from the address is a' (which signals the end of the string). The output may look similar to the output below. John Nguyen 21239798 2.3 Implementation of Caesar Cipher Substitution to encrypt a string (20 marks) In this section, we are going to implement Caesar Cipher (a type of substitution cipher) encryption that we have learned in the Cryptography lab. It replaces each character in a string by a different character of the alphabet defined by a simple shift. An encryption "Key" using a shift of 3 positions, shown in the table below. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z defghijklmnopqrstuvwx|yz|ab|c This is a very simple form of encryption. Please note the use of lower case alphabets only, and we will encrypt or decrypt only "alphabets". One more example "Key" below is showing a Caesar Cipher with a shift of 5 positions. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z fghijklmnopqrstuvwxyz abcde To encrypt, each letter in the top row is replaced by the corresponding letter in the bottom row, and to decrypt, each letter in the bottom row is replaced by the corresponding letter in the top row. In this part, your task is to implement subroutines that perform Caesar cipher substitution on a string, either performing encryption or decryption (cipher or decipher). You will implement the mapping in MARIE by a lookup table, storing the result of the substitution for each letter. The lookup table below maps an encryption key using a shift of 3 positions. myEncKeylAddr, myEncKeyl, ADR HEX HEX 065 / b HEX 066 / c HEX 067 / d HEX 068 HEX 069 / f HEX 06A / g HEX 06B / h HEX 06C HEX 06D HEX 06E HEX 06F HEX 070 HEX 071 HEX 072 HEX 073/p HEX 074/ q HEX 075 HEX 076 / s HEX 077 / t HEX 078 HEX 079 HEX 07A HEX 061 HEX 062 HEX 063 myEnckey1 064/ a -> d -> e -> -> -> -> / V / W / x / y / z -> j ^ ^ ^ -> k /i -> thi (D / j / k -> / 1 -> / m -> /n -> / 0 HECO 1 m n HQ T S -> -> u < C -> V -> -> -> -> -> -> b -> C W 3 XNQ Z a A subroutine to perform encryption on a string In this task, you will implement a MARIE subroutine called subCaesarEnc that can perform encryption using Caesar cipher substitution on a string whose start address is passed as an argument in the EncryptStr label. You need to use the "name" part of the string referred to in section 2.1 (name/D containing your first name and last name) to encrypt. You need to display the string before and after the encryption process. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table "myEnckey1", and then store that value back into memory (overwriting the original letter). Think about how to get "a value" from a table. E.g., assume that the original letter is 'k', which is the 11th letter in the alphabet. So we need to load the 11th entry in the table- in other words, the entry at address myEncKey1Addr + 10 (which is HEX 06E or DEC 110, or the letter 'n'). The letter 'k' has an ASCII value of HEX 06B (DEC 107). So, how do we determine to add '10' to the address "myEncKey1Addr"? We simply subtract the ASCII value for the letter 'a', which is HEX 061 (DEC 97). So, in decimal notation, "117 - 97 = 10" or in HEX notation, "HEX 06B - HEX 061 = HEX A." The following illustrated example explains the encryption process further. Here, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 070 073 S 061 074 072 069 063 t i a r During the encryption process, the following transformation (in the memory) will occur. Load Store Jns sdwulf nohh And, the new encrypted string will be stored in the memory as shown below. W Load Store Jns Halt u 06B 020 06C k I patricklee 064 077 075 06C 066 06E 020 06F d I f /printing the string before encryption Load addrName ID PrintStringAddr Store Jns subPrintString /printing the string after addrName ID PrintStringAddr subPrintString n /calling the subroutine to perform encryption addrName ID EncryptStr subCaesarEnc 065 065 02E e 0 Please note that, during the encryption process, ASCII value for "SPACE" and remains unchanged. To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. You may use the following template to begin with. Here, we are (re)using the subPrintString subroutine from section 2.2. 068 h e 068 h / Load string start address / Pass as an argument / Call printing subroutine 02E / Load string start address / Pass as an argument / Call the cipher subroutine encryption / Load string start address /Pass as an argument / Call printing subroutine /Your subroutine "subCaesarEnc" EncryptStr, Dec 0 subCaesarEnc, HEX 0 / Your codes..... /Your subroutine ends here. 2.4 A subroutine to perform decryption on a string (20 marks). In this part, we want to decrypt a string. To do that, we need a second table (in addition to the encryption table "myEncKeyl" in section 2.3) that has the reverse mapping. Add a table "myDeckey1" to your code that is exactly the inverse of the "myEncKey1" table above. myDecKeylAddr, myDecKeyl, ADR HEX ??? HEX ??? . 070 begins here. / variable or label to store the start / address of a string label (subroutine name) to begin the / subroutine myDecKeyl / /b HEX ??? Output log RTL log OUTPUT MODE: UNICODE -> Modify your subroutine in section 2.3 to create a new subroutine performing decryption. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table, and then store that value back into memory (overwriting the original letter). Watch list / 2 -> W X Input list John Nguyen Jrkq Njxbhq John Nguyen The following illustrated example explains the decryption process further. Here, you will encrypt the string first, storing the encrypted string back in the memory, and then, decrypt this string back to the original form. In this example, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 061 074 072 069 063 06B 020 06C 065 065 02E 073 S a 070 t r During the encryption process, the following transformation (in the memory) will occur. And, the new encrypted string will be stored in the memory as shown below. W a u 061 074 072 t i 064 077 075 06C 066 06E 020 06F d I f r patricklee sdwulf nohh k /Encrypting the string Load addrName ID Store EncryptStr Jns subCaesarEnc Now, you will decrypt the above string "sdwulfn ohh." to its original form "patrick lee." /To print the original string Load addrName ID Store PrintStringAddr Jns subPrintString 069 063 i /Decrypting the string Load addrName ID Store DecryptStr /print the encrypted string Load addrNameID Store PrintStringAddr Jns subPrintString C n e 0 068 h / Load string start address / Pass as an argument e To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. Please note that, as you need to encrypt the string first, so that you can decrypt an already encrypted string, there is a series of activities involved here [Print the original string-> Encryption -> Print the encrypted string-> Decryption -> Print the original string]. You may use the following template to begin with. e 06B 020 06C 065 065 02E k / Load string start address /Pass as an argument / Call printing subroutine 068 h / Load string start address / Pass as an argument / Call printing subroutine / Load string start address / Pass as an argument 02E e / Call the Encryption cipher subroutine Jns subCaesarDec /print the decrypted string addrName ID Load Store Jns Halt PrintStringAddr subPrintString Your subroutine "subCaesarDec" DecryptStr, DEC 0 subCaesarDec, HEX 0 / Your codes..... /Your subroutine ends here. / Call the Decryption cipher subroutine / Load string start address /Pass as an argument / Call printing subroutine begins here. / variable or label to store the start / address of a string / label (subroutine name) to begin the / subroutine Write a MARIE program to encode your name and ID as a string The following example of a MARIE string "nameID" encodes a name and an ID using ASCII characters. The "name" is separated from the ID by an ASCII character "Hex 00A" (New Line). Different parts of a name are separated by another ASCII character "Hex 020" (Space). And, the string is terminated by a dot character. The label "addrNameID" holds the address of the first character of the string. You need to follow this MARIE string while solving the task given below. addrNameID, ADR namelD nameID, HEX 04A HEX 06F HEX 068 HEX 06E HEX 020 HEX 04E HEX 067 HEX 075 HEX 079 HEX 065 HEX 06E HEX 00A HEX 032 HEX 031 HEX 032 HEX 033 HEX 039 HEX 037 HEX 039 HEX 038 HEX 02E ['J' l'o' /'h' /'n' /Space /'N' I'g' l'u' l'y' l'e' /'n' /NL(New Line) /'2' /'1' /'2' /'3' 1'9' ('7' /'9' /'8' Encode a string that includes your full name (first name and last name) and your student ID using ASCII characters. Following the above example, you need to use two labels, one label (e.g. "nameID") to store the first character of the string, and another label (e.g. "addrNameID") to store the address of the first character of the same string. You need to use the ADR command and HEX keywords (like the above example), so that after assembling, your name, ID and the address (of the first character of the string) is stored in MARIE memory. 2.2 Write a MARIE program to print the name and ID using subroutines (15 marks) Prepare a MARIE subroutine called subPrintString that can print the ASCII terminated string of your name and your student ID that you have implemented above. You may use the "Output" instruction to print characters in the MARIE output space. To receive full marks, your program must have a subroutine to print the name and ID string. The subroutine needs to be called from a MARIE main program using a JnS instruction. Hint: In your main program, you need to use a label "StringAdd" that holds the start address of the string (like, addrNameID) that you want to print. Then, you should call the subroutine subPrintString. In the subroutine, the codes should then load a character from the address "StringAdd", print the character, then increment the address by one, and keep doing that upto the character loaded from the address is a' (which signals the end of the string). The output may look similar to the output below. John Nguyen 21239798 2.3 Implementation of Caesar Cipher Substitution to encrypt a string (20 marks) In this section, we are going to implement Caesar Cipher (a type of substitution cipher) encryption that we have learned in the Cryptography lab. It replaces each character in a string by a different character of the alphabet defined by a simple shift. An encryption "Key" using a shift of 3 positions, shown in the table below. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z defghijklmnopqrstuvwx|yz|ab|c This is a very simple form of encryption. Please note the use of lower case alphabets only, and we will encrypt or decrypt only "alphabets". One more example "Key" below is showing a Caesar Cipher with a shift of 5 positions. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z fghijklmnopqrstuvwxyz abcde To encrypt, each letter in the top row is replaced by the corresponding letter in the bottom row, and to decrypt, each letter in the bottom row is replaced by the corresponding letter in the top row. In this part, your task is to implement subroutines that perform Caesar cipher substitution on a string, either performing encryption or decryption (cipher or decipher). You will implement the mapping in MARIE by a lookup table, storing the result of the substitution for each letter. The lookup table below maps an encryption key using a shift of 3 positions. myEncKeylAddr, myEncKeyl, ADR HEX HEX 065 / b HEX 066 / c HEX 067 / d HEX 068 HEX 069 / f HEX 06A / g HEX 06B / h HEX 06C HEX 06D HEX 06E HEX 06F HEX 070 HEX 071 HEX 072 HEX 073/p HEX 074/ q HEX 075 HEX 076 / s HEX 077 / t HEX 078 HEX 079 HEX 07A HEX 061 HEX 062 HEX 063 myEnckey1 064/ a -> d -> e -> -> -> -> / V / W / x / y / z -> j ^ ^ ^ -> k /i -> thi (D / j / k -> / 1 -> / m -> /n -> / 0 HECO 1 m n HQ T S -> -> u < C -> V -> -> -> -> -> -> b -> C W 3 XNQ Z a A subroutine to perform encryption on a string In this task, you will implement a MARIE subroutine called subCaesarEnc that can perform encryption using Caesar cipher substitution on a string whose start address is passed as an argument in the EncryptStr label. You need to use the "name" part of the string referred to in section 2.1 (name/D containing your first name and last name) to encrypt. You need to display the string before and after the encryption process. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table "myEnckey1", and then store that value back into memory (overwriting the original letter). Think about how to get "a value" from a table. E.g., assume that the original letter is 'k', which is the 11th letter in the alphabet. So we need to load the 11th entry in the table- in other words, the entry at address myEncKey1Addr + 10 (which is HEX 06E or DEC 110, or the letter 'n'). The letter 'k' has an ASCII value of HEX 06B (DEC 107). So, how do we determine to add '10' to the address "myEncKey1Addr"? We simply subtract the ASCII value for the letter 'a', which is HEX 061 (DEC 97). So, in decimal notation, "117 - 97 = 10" or in HEX notation, "HEX 06B - HEX 061 = HEX A." The following illustrated example explains the encryption process further. Here, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 070 073 S 061 074 072 069 063 t i a r During the encryption process, the following transformation (in the memory) will occur. Load Store Jns sdwulf nohh And, the new encrypted string will be stored in the memory as shown below. W Load Store Jns Halt u 06B 020 06C k I patricklee 064 077 075 06C 066 06E 020 06F d I f /printing the string before encryption Load addrName ID PrintStringAddr Store Jns subPrintString /printing the string after addrName ID PrintStringAddr subPrintString n /calling the subroutine to perform encryption addrName ID EncryptStr subCaesarEnc 065 065 02E e 0 Please note that, during the encryption process, ASCII value for "SPACE" and remains unchanged. To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. You may use the following template to begin with. Here, we are (re)using the subPrintString subroutine from section 2.2. 068 h e 068 h / Load string start address / Pass as an argument / Call printing subroutine 02E / Load string start address / Pass as an argument / Call the cipher subroutine encryption / Load string start address /Pass as an argument / Call printing subroutine /Your subroutine "subCaesarEnc" EncryptStr, Dec 0 subCaesarEnc, HEX 0 / Your codes..... /Your subroutine ends here. 2.4 A subroutine to perform decryption on a string (20 marks). In this part, we want to decrypt a string. To do that, we need a second table (in addition to the encryption table "myEncKeyl" in section 2.3) that has the reverse mapping. Add a table "myDeckey1" to your code that is exactly the inverse of the "myEncKey1" table above. myDecKeylAddr, myDecKeyl, ADR HEX ??? HEX ??? . 070 begins here. / variable or label to store the start / address of a string label (subroutine name) to begin the / subroutine myDecKeyl / /b HEX ??? Output log RTL log OUTPUT MODE: UNICODE -> Modify your subroutine in section 2.3 to create a new subroutine performing decryption. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table, and then store that value back into memory (overwriting the original letter). Watch list / 2 -> W X Input list John Nguyen Jrkq Njxbhq John Nguyen The following illustrated example explains the decryption process further. Here, you will encrypt the string first, storing the encrypted string back in the memory, and then, decrypt this string back to the original form. In this example, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 061 074 072 069 063 06B 020 06C 065 065 02E 073 S a 070 t r During the encryption process, the following transformation (in the memory) will occur. And, the new encrypted string will be stored in the memory as shown below. W a u 061 074 072 t i 064 077 075 06C 066 06E 020 06F d I f r patricklee sdwulf nohh k /Encrypting the string Load addrName ID Store EncryptStr Jns subCaesarEnc Now, you will decrypt the above string "sdwulfn ohh." to its original form "patrick lee." /To print the original string Load addrName ID Store PrintStringAddr Jns subPrintString 069 063 i /Decrypting the string Load addrName ID Store DecryptStr /print the encrypted string Load addrNameID Store PrintStringAddr Jns subPrintString C n e 0 068 h / Load string start address / Pass as an argument e To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. Please note that, as you need to encrypt the string first, so that you can decrypt an already encrypted string, there is a series of activities involved here [Print the original string-> Encryption -> Print the encrypted string-> Decryption -> Print the original string]. You may use the following template to begin with. e 06B 020 06C 065 065 02E k / Load string start address /Pass as an argument / Call printing subroutine 068 h / Load string start address / Pass as an argument / Call printing subroutine / Load string start address / Pass as an argument 02E e / Call the Encryption cipher subroutine Jns subCaesarDec /print the decrypted string addrName ID Load Store Jns Halt PrintStringAddr subPrintString Your subroutine "subCaesarDec" DecryptStr, DEC 0 subCaesarDec, HEX 0 / Your codes..... /Your subroutine ends here. / Call the Decryption cipher subroutine / Load string start address /Pass as an argument / Call printing subroutine begins here. / variable or label to store the start / address of a string / label (subroutine name) to begin the / subroutine Write a MARIE program to encode your name and ID as a string The following example of a MARIE string "nameID" encodes a name and an ID using ASCII characters. The "name" is separated from the ID by an ASCII character "Hex 00A" (New Line). Different parts of a name are separated by another ASCII character "Hex 020" (Space). And, the string is terminated by a dot character. The label "addrNameID" holds the address of the first character of the string. You need to follow this MARIE string while solving the task given below. addrNameID, ADR namelD nameID, HEX 04A HEX 06F HEX 068 HEX 06E HEX 020 HEX 04E HEX 067 HEX 075 HEX 079 HEX 065 HEX 06E HEX 00A HEX 032 HEX 031 HEX 032 HEX 033 HEX 039 HEX 037 HEX 039 HEX 038 HEX 02E ['J' l'o' /'h' /'n' /Space /'N' I'g' l'u' l'y' l'e' /'n' /NL(New Line) /'2' /'1' /'2' /'3' 1'9' ('7' /'9' /'8' Encode a string that includes your full name (first name and last name) and your student ID using ASCII characters. Following the above example, you need to use two labels, one label (e.g. "nameID") to store the first character of the string, and another label (e.g. "addrNameID") to store the address of the first character of the same string. You need to use the ADR command and HEX keywords (like the above example), so that after assembling, your name, ID and the address (of the first character of the string) is stored in MARIE memory. 2.2 Write a MARIE program to print the name and ID using subroutines (15 marks) Prepare a MARIE subroutine called subPrintString that can print the ASCII terminated string of your name and your student ID that you have implemented above. You may use the "Output" instruction to print characters in the MARIE output space. To receive full marks, your program must have a subroutine to print the name and ID string. The subroutine needs to be called from a MARIE main program using a JnS instruction. Hint: In your main program, you need to use a label "StringAdd" that holds the start address of the string (like, addrNameID) that you want to print. Then, you should call the subroutine subPrintString. In the subroutine, the codes should then load a character from the address "StringAdd", print the character, then increment the address by one, and keep doing that upto the character loaded from the address is a' (which signals the end of the string). The output may look similar to the output below. John Nguyen 21239798 2.3 Implementation of Caesar Cipher Substitution to encrypt a string (20 marks) In this section, we are going to implement Caesar Cipher (a type of substitution cipher) encryption that we have learned in the Cryptography lab. It replaces each character in a string by a different character of the alphabet defined by a simple shift. An encryption "Key" using a shift of 3 positions, shown in the table below. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z defghijklmnopqrstuvwx|yz|ab|c This is a very simple form of encryption. Please note the use of lower case alphabets only, and we will encrypt or decrypt only "alphabets". One more example "Key" below is showing a Caesar Cipher with a shift of 5 positions. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z fghijklmnopqrstuvwxyz abcde To encrypt, each letter in the top row is replaced by the corresponding letter in the bottom row, and to decrypt, each letter in the bottom row is replaced by the corresponding letter in the top row. In this part, your task is to implement subroutines that perform Caesar cipher substitution on a string, either performing encryption or decryption (cipher or decipher). You will implement the mapping in MARIE by a lookup table, storing the result of the substitution for each letter. The lookup table below maps an encryption key using a shift of 3 positions. myEncKeylAddr, myEncKeyl, ADR HEX HEX 065 / b HEX 066 / c HEX 067 / d HEX 068 HEX 069 / f HEX 06A / g HEX 06B / h HEX 06C HEX 06D HEX 06E HEX 06F HEX 070 HEX 071 HEX 072 HEX 073/p HEX 074/ q HEX 075 HEX 076 / s HEX 077 / t HEX 078 HEX 079 HEX 07A HEX 061 HEX 062 HEX 063 myEnckey1 064/ a -> d -> e -> -> -> -> / V / W / x / y / z -> j ^ ^ ^ -> k /i -> thi (D / j / k -> / 1 -> / m -> /n -> / 0 HECO 1 m n HQ T S -> -> u < C -> V -> -> -> -> -> -> b -> C W 3 XNQ Z a A subroutine to perform encryption on a string In this task, you will implement a MARIE subroutine called subCaesarEnc that can perform encryption using Caesar cipher substitution on a string whose start address is passed as an argument in the EncryptStr label. You need to use the "name" part of the string referred to in section 2.1 (name/D containing your first name and last name) to encrypt. You need to display the string before and after the encryption process. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table "myEnckey1", and then store that value back into memory (overwriting the original letter). Think about how to get "a value" from a table. E.g., assume that the original letter is 'k', which is the 11th letter in the alphabet. So we need to load the 11th entry in the table- in other words, the entry at address myEncKey1Addr + 10 (which is HEX 06E or DEC 110, or the letter 'n'). The letter 'k' has an ASCII value of HEX 06B (DEC 107). So, how do we determine to add '10' to the address "myEncKey1Addr"? We simply subtract the ASCII value for the letter 'a', which is HEX 061 (DEC 97). So, in decimal notation, "117 - 97 = 10" or in HEX notation, "HEX 06B - HEX 061 = HEX A." The following illustrated example explains the encryption process further. Here, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 070 073 S 061 074 072 069 063 t i a r During the encryption process, the following transformation (in the memory) will occur. Load Store Jns sdwulf nohh And, the new encrypted string will be stored in the memory as shown below. W Load Store Jns Halt u 06B 020 06C k I patricklee 064 077 075 06C 066 06E 020 06F d I f /printing the string before encryption Load addrName ID PrintStringAddr Store Jns subPrintString /printing the string after addrName ID PrintStringAddr subPrintString n /calling the subroutine to perform encryption addrName ID EncryptStr subCaesarEnc 065 065 02E e 0 Please note that, during the encryption process, ASCII value for "SPACE" and remains unchanged. To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. You may use the following template to begin with. Here, we are (re)using the subPrintString subroutine from section 2.2. 068 h e 068 h / Load string start address / Pass as an argument / Call printing subroutine 02E / Load string start address / Pass as an argument / Call the cipher subroutine encryption / Load string start address /Pass as an argument / Call printing subroutine /Your subroutine "subCaesarEnc" EncryptStr, Dec 0 subCaesarEnc, HEX 0 / Your codes..... /Your subroutine ends here. 2.4 A subroutine to perform decryption on a string (20 marks). In this part, we want to decrypt a string. To do that, we need a second table (in addition to the encryption table "myEncKeyl" in section 2.3) that has the reverse mapping. Add a table "myDeckey1" to your code that is exactly the inverse of the "myEncKey1" table above. myDecKeylAddr, myDecKeyl, ADR HEX ??? HEX ??? . 070 begins here. / variable or label to store the start / address of a string label (subroutine name) to begin the / subroutine myDecKeyl / /b HEX ??? Output log RTL log OUTPUT MODE: UNICODE -> Modify your subroutine in section 2.3 to create a new subroutine performing decryption. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table, and then store that value back into memory (overwriting the original letter). Watch list / 2 -> W X Input list John Nguyen Jrkq Njxbhq John Nguyen The following illustrated example explains the decryption process further. Here, you will encrypt the string first, storing the encrypted string back in the memory, and then, decrypt this string back to the original form. In this example, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 061 074 072 069 063 06B 020 06C 065 065 02E 073 S a 070 t r During the encryption process, the following transformation (in the memory) will occur. And, the new encrypted string will be stored in the memory as shown below. W a u 061 074 072 t i 064 077 075 06C 066 06E 020 06F d I f r patricklee sdwulf nohh k /Encrypting the string Load addrName ID Store EncryptStr Jns subCaesarEnc Now, you will decrypt the above string "sdwulfn ohh." to its original form "patrick lee." /To print the original string Load addrName ID Store PrintStringAddr Jns subPrintString 069 063 i /Decrypting the string Load addrName ID Store DecryptStr /print the encrypted string Load addrNameID Store PrintStringAddr Jns subPrintString C n e 0 068 h / Load string start address / Pass as an argument e To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. Please note that, as you need to encrypt the string first, so that you can decrypt an already encrypted string, there is a series of activities involved here [Print the original string-> Encryption -> Print the encrypted string-> Decryption -> Print the original string]. You may use the following template to begin with. e 06B 020 06C 065 065 02E k / Load string start address /Pass as an argument / Call printing subroutine 068 h / Load string start address / Pass as an argument / Call printing subroutine / Load string start address / Pass as an argument 02E e / Call the Encryption cipher subroutine Jns subCaesarDec /print the decrypted string addrName ID Load Store Jns Halt PrintStringAddr subPrintString Your subroutine "subCaesarDec" DecryptStr, DEC 0 subCaesarDec, HEX 0 / Your codes..... /Your subroutine ends here. / Call the Decryption cipher subroutine / Load string start address /Pass as an argument / Call printing subroutine begins here. / variable or label to store the start / address of a string / label (subroutine name) to begin the / subroutine Write a MARIE program to encode your name and ID as a string The following example of a MARIE string "nameID" encodes a name and an ID using ASCII characters. The "name" is separated from the ID by an ASCII character "Hex 00A" (New Line). Different parts of a name are separated by another ASCII character "Hex 020" (Space). And, the string is terminated by a dot character. The label "addrNameID" holds the address of the first character of the string. You need to follow this MARIE string while solving the task given below. addrNameID, ADR namelD nameID, HEX 04A HEX 06F HEX 068 HEX 06E HEX 020 HEX 04E HEX 067 HEX 075 HEX 079 HEX 065 HEX 06E HEX 00A HEX 032 HEX 031 HEX 032 HEX 033 HEX 039 HEX 037 HEX 039 HEX 038 HEX 02E ['J' l'o' /'h' /'n' /Space /'N' I'g' l'u' l'y' l'e' /'n' /NL(New Line) /'2' /'1' /'2' /'3' 1'9' ('7' /'9' /'8' Encode a string that includes your full name (first name and last name) and your student ID using ASCII characters. Following the above example, you need to use two labels, one label (e.g. "nameID") to store the first character of the string, and another label (e.g. "addrNameID") to store the address of the first character of the same string. You need to use the ADR command and HEX keywords (like the above example), so that after assembling, your name, ID and the address (of the first character of the string) is stored in MARIE memory. 2.2 Write a MARIE program to print the name and ID using subroutines (15 marks) Prepare a MARIE subroutine called subPrintString that can print the ASCII terminated string of your name and your student ID that you have implemented above. You may use the "Output" instruction to print characters in the MARIE output space. To receive full marks, your program must have a subroutine to print the name and ID string. The subroutine needs to be called from a MARIE main program using a JnS instruction. Hint: In your main program, you need to use a label "StringAdd" that holds the start address of the string (like, addrNameID) that you want to print. Then, you should call the subroutine subPrintString. In the subroutine, the codes should then load a character from the address "StringAdd", print the character, then increment the address by one, and keep doing that upto the character loaded from the address is a' (which signals the end of the string). The output may look similar to the output below. John Nguyen 21239798 2.3 Implementation of Caesar Cipher Substitution to encrypt a string (20 marks) In this section, we are going to implement Caesar Cipher (a type of substitution cipher) encryption that we have learned in the Cryptography lab. It replaces each character in a string by a different character of the alphabet defined by a simple shift. An encryption "Key" using a shift of 3 positions, shown in the table below. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z defghijklmnopqrstuvwx|yz|ab|c This is a very simple form of encryption. Please note the use of lower case alphabets only, and we will encrypt or decrypt only "alphabets". One more example "Key" below is showing a Caesar Cipher with a shift of 5 positions. |a|b|c|d|e|f|g|h|i|i|k|i|m|n|o|p|q|r|s|t|u|v|w|x|y|z fghijklmnopqrstuvwxyz abcde To encrypt, each letter in the top row is replaced by the corresponding letter in the bottom row, and to decrypt, each letter in the bottom row is replaced by the corresponding letter in the top row. In this part, your task is to implement subroutines that perform Caesar cipher substitution on a string, either performing encryption or decryption (cipher or decipher). You will implement the mapping in MARIE by a lookup table, storing the result of the substitution for each letter. The lookup table below maps an encryption key using a shift of 3 positions. myEncKeylAddr, myEncKeyl, ADR HEX HEX 065 / b HEX 066 / c HEX 067 / d HEX 068 HEX 069 / f HEX 06A / g HEX 06B / h HEX 06C HEX 06D HEX 06E HEX 06F HEX 070 HEX 071 HEX 072 HEX 073/p HEX 074/ q HEX 075 HEX 076 / s HEX 077 / t HEX 078 HEX 079 HEX 07A HEX 061 HEX 062 HEX 063 myEnckey1 064/ a -> d -> e -> -> -> -> / V / W / x / y / z -> j ^ ^ ^ -> k /i -> thi (D / j / k -> / 1 -> / m -> /n -> / 0 HECO 1 m n HQ T S -> -> u < C -> V -> -> -> -> -> -> b -> C W 3 XNQ Z a A subroutine to perform encryption on a string In this task, you will implement a MARIE subroutine called subCaesarEnc that can perform encryption using Caesar cipher substitution on a string whose start address is passed as an argument in the EncryptStr label. You need to use the "name" part of the string referred to in section 2.1 (name/D containing your first name and last name) to encrypt. You need to display the string before and after the encryption process. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table "myEnckey1", and then store that value back into memory (overwriting the original letter). Think about how to get "a value" from a table. E.g., assume that the original letter is 'k', which is the 11th letter in the alphabet. So we need to load the 11th entry in the table- in other words, the entry at address myEncKey1Addr + 10 (which is HEX 06E or DEC 110, or the letter 'n'). The letter 'k' has an ASCII value of HEX 06B (DEC 107). So, how do we determine to add '10' to the address "myEncKey1Addr"? We simply subtract the ASCII value for the letter 'a', which is HEX 061 (DEC 97). So, in decimal notation, "117 - 97 = 10" or in HEX notation, "HEX 06B - HEX 061 = HEX A." The following illustrated example explains the encryption process further. Here, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 070 073 S 061 074 072 069 063 t i a r During the encryption process, the following transformation (in the memory) will occur. Load Store Jns sdwulf nohh And, the new encrypted string will be stored in the memory as shown below. W Load Store Jns Halt u 06B 020 06C k I patricklee 064 077 075 06C 066 06E 020 06F d I f /printing the string before encryption Load addrName ID PrintStringAddr Store Jns subPrintString /printing the string after addrName ID PrintStringAddr subPrintString n /calling the subroutine to perform encryption addrName ID EncryptStr subCaesarEnc 065 065 02E e 0 Please note that, during the encryption process, ASCII value for "SPACE" and remains unchanged. To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. You may use the following template to begin with. Here, we are (re)using the subPrintString subroutine from section 2.2. 068 h e 068 h / Load string start address / Pass as an argument / Call printing subroutine 02E / Load string start address / Pass as an argument / Call the cipher subroutine encryption / Load string start address /Pass as an argument / Call printing subroutine /Your subroutine "subCaesarEnc" EncryptStr, Dec 0 subCaesarEnc, HEX 0 / Your codes..... /Your subroutine ends here. 2.4 A subroutine to perform decryption on a string (20 marks). In this part, we want to decrypt a string. To do that, we need a second table (in addition to the encryption table "myEncKeyl" in section 2.3) that has the reverse mapping. Add a table "myDeckey1" to your code that is exactly the inverse of the "myEncKey1" table above. myDecKeylAddr, myDecKeyl, ADR HEX ??? HEX ??? . 070 begins here. / variable or label to store the start / address of a string label (subroutine name) to begin the / subroutine myDecKeyl / /b HEX ??? Output log RTL log OUTPUT MODE: UNICODE -> Modify your subroutine in section 2.3 to create a new subroutine performing decryption. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table, and then store that value back into memory (overwriting the original letter). Watch list / 2 -> W X Input list John Nguyen Jrkq Njxbhq John Nguyen The following illustrated example explains the decryption process further. Here, you will encrypt the string first, storing the encrypted string back in the memory, and then, decrypt this string back to the original form. In this example, the first name is "patrick", and the last name is "lee." And, it will be stored in the memory as shown below. 061 074 072 069 063 06B 020 06C 065 065 02E 073 S a 070 t r During the encryption process, the following transformation (in the memory) will occur. And, the new encrypted string will be stored in the memory as shown below. W a u 061 074 072 t i 064 077 075 06C 066 06E 020 06F d I f r patricklee sdwulf nohh k /Encrypting the string Load addrName ID Store EncryptStr Jns subCaesarEnc Now, you will decrypt the above string "sdwulfn ohh." to its original form "patrick lee." /To print the original string Load addrName ID Store PrintStringAddr Jns subPrintString 069 063 i /Decrypting the string Load addrName ID Store DecryptStr /print the encrypted string Load addrNameID Store PrintStringAddr Jns subPrintString C n e 0 068 h / Load string start address / Pass as an argument e To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. Please note that, as you need to encrypt the string first, so that you can decrypt an already encrypted string, there is a series of activities involved here [Print the original string-> Encryption -> Print the encrypted string-> Decryption -> Print the original string]. You may use the following template to begin with. e 06B 020 06C 065 065 02E k / Load string start address /Pass as an argument / Call printing subroutine 068 h / Load string start address / Pass as an argument / Call printing subroutine / Load string start address / Pass as an argument 02E e / Call the Encryption cipher subroutine Jns subCaesarDec /print the decrypted string addrName ID Load Store Jns Halt PrintStringAddr subPrintString Your subroutine "subCaesarDec" DecryptStr, DEC 0 subCaesarDec, HEX 0 / Your codes..... /Your subroutine ends here. / Call the Decryption cipher subroutine / Load string start address /Pass as an argument / Call printing subroutine begins here. / variable or label to store the start / address of a string / label (subroutine name) to begin the / subroutine

Step by Step Solution

3.34 Rating (148 Votes )

There are 3 Steps involved in it

Step: 1

Heres a MARIE program that encodes a string with your full name and student ID using ASCII characters ORG 200 addrNameID HEX 0 Placeholder for the address of the string nameID HEX 0 Placeholder for th... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions