python希尔(Hill)密码加解密实现

python希尔(Hill)密码加解密实现,第1张

概述学校的实验之一。找个地方保存一下。。。。encryptionKeys=[[10,5,12,0,0],[3,14,21,0,0],[8,9,11,0,0],[0,0,0,11,8],[0,0,0,3,7]]decryptionKeys=[[21,15,17,0,0],[23,2,16,0,0],[25,4,3,0,0],[0,0,0,7,18],[0,0,0,23,11]]first=97temp=0num=0dir={}foriinra

学校的实验之一。找个地方保存一下。。。。

encryptionKeys=[[10,5,12,0,0],[3,14,21,0,0],[8,9,11,0,0],[0,0,0,11,8],[0,0,0,3,7]]decryptionKeys=[[21,15,17,0,0],[23,2,16,0,0],[25,4,3,0,0],[0,0,0,7,18],[0,0,0,23,11]]first = 97temp=0num=0dir = {}for i in range(26):    dir[chr(first)]=i    first=first+1PlainTextALL = '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' #明文PlainTextALL=PlainTextALL.lower().replace(' ','').replace('-','')  #去掉字符之间的空格和-,全部变成小写PlainListALL=List(PlainTextALL)PlainList=[]CipherList=[]CipherText=''# print(PlainListALL)for i in range(len(PlainListALL)):    PlainListALL[i]=dir[PlainListALL[i]]# print("PlainListALL如下:")# print(PlainListALL)print('\n')for i in PlainListALL:    PlainList.append(i)    # print(PlainList)    num=num+1    if(num%int(len(encryptionKeys))==0):            for i in range(len(encryptionKeys)):                for j in range(len(encryptionKeys)):                    temp+=PlainList[j]*encryptionKeys[j][i]                CipherList.append(temp)                temp=0            PlainList=[]num=0# print('CipherList如下')# print(CipherList)for i in range(len(CipherList)):    CipherList[i]=CipherList[i]%26    # print(CipherList[i],end=' ')    for keys,values in dir.items():        if(CipherList[i]==values):            CipherList[i]=keysfor i in CipherList:    CipherText+=iprint('\n密文为')print(CipherText)Statistics={}for i in  CipherText:    if(i  not in Statistics):        Statistics[i]=1    else:        Statistics[i]=Statistics[i]+1print("各字符出现次数的统计如下:")print(Statistics)# 解密算法如下:# print("解密方法如下:\n")print('是否解密?(Y/N)')judge =''judge=input()if(judge=='Y' or judge=='y'):    CipherTextALL=CipherText    CipherListALL=List(CipherTextALL)    CipherList=[]    PlainList=[]    PlainText=''    for i in range(len(CipherTextALL)):        CipherListALL[i]=dir[CipherListALL[i]]    # print("密文列表如下:")    # print(CipherListALL)    print('\n')    for i in CipherListALL:        CipherList.append(i)        # print(PlainList)        num=num+1        if(num%int(len(decryptionKeys))==0):                for i in range(len(decryptionKeys)):                    for j in range(len(decryptionKeys)):                        temp+=CipherList[j]*decryptionKeys[j][i]                    PlainList.append(temp)                    temp=0                CipherList=[]    # print('明文列表如下')    # print(PlainList)    for i in range(len(PlainList)):        PlainList[i]=PlainList[i]%26        # print(PlainList[i],end=' ')        for keys,values in dir.items():            if(PlainList[i]==values):                PlainList[i]=keys    for i in PlainList:        PlainText+=i    print('\n明文为')    print(PlainText)elif(judge=='N' or 'n'):    print('拜拜~~')else:    print('这也能输错?')# 统计字符出现的次数

程序实现如下:

总结

以上是内存溢出为你收集整理的python希尔(Hill)密码加解密实现全部内容,希望文章能够帮你解决python希尔(Hill)密码加解密实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1188722.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存