[关闭]
@Lin-- 2019-10-21T14:18:42.000000Z 字数 819 阅读 287

Comsec作业五:GF(2^8)乘法证明

ComSec

  1. '''
  2. # File : Prove_GF.py
  3. # Author : Hongpei Lin
  4. # Date : 20191016
  5. # Purpose : prove GF(2^8)
  6. '''
  7. import copy
  8. mod_number=[285,299,301,333,351,355,357,361,369,391,397,425,451,463,487,501]
  9. #multilpy in GF(2^8)
  10. def mul(a,b,n):
  11. r=0
  12. while b:
  13. if b%2:
  14. r=r^a#add operation : XOR
  15. b=b>>1
  16. if a&int('10000000',2)==0:#hightest bit's value = 0
  17. a=a<<1
  18. else:#hightest bit's value = 1
  19. a=a<<1
  20. a=a^n
  21. return r
  22. #jugde whether a list exists same element
  23. def Judge_Same(a):
  24. b=copy.deepcopy(a)
  25. b.sort()
  26. for i in range(len(a)-1):
  27. if b[i]==b[i+1]:
  28. return False
  29. return True
  30. #judge whether a list all values are "True"
  31. def Judge_True(a):
  32. for i in a:
  33. if i==False:
  34. return False
  35. return True
  36. final=[]
  37. k=len(mod_number)-1
  38. while k:
  39. result = []
  40. for i in range(1,256):
  41. subresult=[]
  42. for j in range(1,256):
  43. subresult.append(mul(i,j,mod_number[k]))
  44. result.append(Judge_Same(subresult))
  45. final.append(Judge_True(result))
  46. k-=1
  47. print(Judge_True(final))
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注