python仿射密码加解密实现

Keys1=9
Keys2=2
first = 97
temp=0
dir={}
for i in range(26):
    dir[chr(first)]=i
    first=first+1
PlainText ='In several distributed systems a user should only be able to access data if a user posses a certain set of credentials or attributes Currently the only method for enforcing such policies is to employ a trusted server to store the data and mediate access control However if any server storing the data is compromised then the confidentiality of the data will be compromised In this paper we present a system for realizing complex access control on encrypted data that we call ciphertext-policy attribute-based encryption By using our techniques encrypted data can be kept confidential even if the storage server is untrusted moreover our methods are secure against collusion attacks is'
PlainText=PlainText.replace(' ','').replace('-','').lower()
CipherText=''
for i in PlainText:
    temp=dir[i]
    temp=(temp*Keys1+Keys2)%26
    for Keys,values in dir.items():
        if(temp==values):
            CipherText=CipherText+Keys
print('密文如下')
print(CipherText)
Statistics={}
for i in  CipherText:
    if(i  not in Statistics):
        Statistics[i]=1
    else:
        Statistics[i]=Statistics[i]+1
print("各字符出现次数的统计如下:")
print(Statistics)

# 解密如下
PlainText=''
for i in CipherText:
    temp=dir[i]
    temp=((temp-2)*3)%26
    for Keys,values in dir.items():
        if(temp==values):
            PlainText=PlainText+Keys
print('明文如下')
print(PlainText)
Statistics={}
for i in  PlainText:
    if(i  not in Statistics):
        Statistics[i]=1
    else:
        Statistics[i]=Statistics[i]+1
print("各字符出现次数的统计如下:")
print(Statistics)

程序运行结果如下:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值