输入一个身份证号码和一个电话号码,对这两项信息进行脱敏处理, 即将身份证的第7-14位,手机号码的第4-7位用“*”代替。编写python程序进行处理并输出结果。
时间: 2024-10-14 17:16:17 浏览: 57
在Python中,我们可以使用字符串切片和星号(*)来实现这个脱敏处理。以下是一个简单的示例程序:
```python
def desensitize_info(id_number, phone_number):
# 脱敏身份证号码(第7-14位)
id_desensitized = id_number[:6] + '*' * (14 - 6) + id_number[14:]
# 脱敏手机号码(第4-7位)
phone_desensitized = phone_number[:3] + '*' * 3 + phone_number[7:]
return id_desensitized, phone_desensitized
# 示例输入
id_number = "1234567890123456"
phone_number = "13812345678"
# 脱敏处理并输出结果
id_sansensitized, phone_sansensitized = desensitize_info(id_number, phone_number)
print(f"身份证号码脱敏后: {id_sansensitized}")
print(f"手机号码脱敏后: {phone_sansensitized}")
阅读全文