init-commit

This commit is contained in:
lilinyang 2025-05-23 15:27:15 +08:00
commit 18a552597a
3461 changed files with 1150579 additions and 0 deletions

View file

@ -0,0 +1,54 @@
from .BaseCipherEnvironment import BaseCipherEnvironment
class Asc2Environment(BaseCipherEnvironment):
def __init__(self, *args, **kwargs):
problem_description = ''
super().__init__(problem_description, *args, **kwargs)
@property
def cipher_name(self):
return "ASCII"
def encode(self, text):
# 初始化一个空列表用于存储ASCII编码
ascii_list = []
# 遍历输入字符串中的每个字符
for char in text:
# 获取字符的ASCII编码
ascii_code = ord(char)
# 将ASCII编码添加到列表中
ascii_list.append(ascii_code)
# 打印字符及其对应的ASCII编码
print(f"Character: {char}, ASCII Code: {ascii_code}")
# print(f"Current ASCII List: {ascii_list}\n")
print("ASCII List:", ascii_list)
# 返回ASCII编码列表
return ascii_list
def get_encode_rule(self, ):
return """加密方案概述将字符串转换为ASCII编码。"""
def decode(self, text):
"""
将ASCII编码列表转换为字符串并打印每个ASCII码及其对应的字符
:param ascii_list: 包含ASCII编码的列表
:return: 转换后的字符串
"""
result = ""
for ascii_code in text:
# 检查ASCII码是否在可打印字符的范围内
if 32 <= ascii_code <= 126:
# 将ASCII码转换为字符并添加到结果字符串中
result += chr(ascii_code)
# 打印ASCII码及其对应的字符
print(f"ASCII Code: {ascii_code}, Character: {chr(ascii_code)}")
else:
# 如果ASCII码不在可打印字符的范围内打印警告信息
print(f"Warning: ASCII Code {ascii_code} is not a printable character.")
print("Result:", result)
return result
def get_decode_rule(self, ):
return """解密方案概述遍历ASCII编码字符串,返回转换后的字符串"""