酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

用while循环实现简单密码加密:大写小写互变、数字变换规则揭秘!

以下是一个使用Python编写的while循环来实现密码加密的示例: ```python def encrypt_password(input_password): encrypted_password = "" i = 0 while i < len(input_password): char = input_password[i] if char.isalpha(): # 字母转换 if char.islower(): encrypted_password += char.upper() else: encrypted_password += char.lower() elif char.isdigit(): # 数字转换 num = int(char) encrypted_password += str((num - 1) % 10 + 1) else: # 其他字符不变 encrypted_password += char i += 1 return encrypted_password # 测试 input_password = input("请输入需要加密的密码:") encrypted_password = encrypt_password(input_password) print("加密后的密码是:", encrypted_password) ``` 这个程序首先定义了一个函数`encrypt_password`,它接受一个字符串作为输入密码。然后,我们使用while循环遍历输入的每个字符。根据字符的类型(字母、数字或其他),执行相应的加密操作,最后将加密后的字符添加到结果字符串中。循环结束后,返回加密后的密码。 ######[AI写代码神器 | 253点数解答 | 2024-05-07 16:50:24]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]