测试仿射加密函数
在这一步中,你将使用提供的示例输入来测试 affine_encryption() 函数。
- 在
affine.py 文件中,在文件末尾添加以下代码:
if __name__ == "__main__":
## 示例 1
text = "welcome"
encryption_text = affine_encryption(text)
print(f"示例 1: {text} -> {encryption_text}")
## 示例 2
text = " welcome"
encryption_text = affine_encryption(text)
print(f"示例 2: {text} -> {encryption_text}")
## 示例 3
text = " Qrwe"
encryption_text = affine_encryption(text)
print(f"示例 3: {text} -> {encryption_text}")
## 示例 4
text = None
encryption_text = affine_encryption(text)
print(f"示例 4: {text} -> {encryption_text}")
- 保存
affine.py 文件。
- 打开终端或命令提示符,导航到包含
affine.py 文件的目录,并运行以下命令:
python3 affine.py
这将使用提供的示例输入执行 affine_encryption() 函数并打印结果。
验证输出是否与预期结果匹配:
示例1: welcome -> oclsaqc
示例2: welcome -> oclsaqc
示例3: Qrwe -> Qroc
示例4: None -> None
如果输出与预期结果匹配,则说明你的 affine_encryption() 函数工作正常。