
In this program, you are required to learn basic concepts of Python 3.
Type hints is a feature to specify the type of a variable, which is useful for write correct codes. In all lab assignments, you are required to write Python 3 code with type hints feature. Recall that you are required to use at least Python 3.10, otherwise you might suffer from issues brings by type hints as PEP 563 has not become the default option until Python 3.10.
Your programs does the following:
In your readme.pdf file, apart from the general information, it should include:
bytes and str. Example here:
The figure above is corresponding to the following code.
first_hex:str = input()
first_bytes:bytes = bytes.fromhex(first_hex)import base64
def output_bytes(in_bytes: bytes):
for ch in in_bytes:
print(ch, end=' ')
print()
def output_hex(in_bytes: bytes):
for ch in in_bytes:
print(hex(ch), end=' ')
print()
def decode_utf8(in_bytes: bytes) -> str:
return in_bytes.decode('utf-8')
print("Enter a string str1:")
str1: str = input()
byte_array: bytes = bytearray.fromhex(str1)
output_bytes(byte_array)
output_hex(byte_array)
encoded: bytes = base64.b64encode(byte_array)
print(encoded)
print("Enter a string str2:")
str2: str = input()
byte_array2: bytes = bytearray.fromhex(str2)
str3: str = decode_utf8(byte_array2)
print(str3)Enter a string str1:
deadbeef
222 173 190 239
0xde 0xad 0xbe 0xef
b'3q2+7w=='
Enter a string str2:
4445414442454546
DEADBEEF
进程已结束,退出代码为 0
A figure representing the relationship between all the variables in your program with type bytes and str:

初学密码学,如果发现错误,还请各位指正。
受于文本原因,本文相关算法实现工程无法展示出来,现已将资源上传,可自行点击下方链接下载。