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)
程序运行结果如下: