ThihaNyein

Binary Match Encryption

Sep 12th, 2020 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. import math
  2.  
  3. def isPrime(x):
  4.     if(x==2):return True
  5.     elif(x<2):return False
  6.     for i in range(2,math.ceil(math.sqrt(x)+1)):
  7.         if (x%i==0): return False
  8.     return True
  9.  
  10. def isPerfect(x):
  11.     return math.ceil(math.sqrt(x))==math.sqrt(x)
  12.  
  13. prime =[]
  14. perfect=[]
  15. other=[]
  16. for i in range(2,1000):
  17.     if(isPrime(i)):
  18.         prime.append(i)
  19.     elif(isPerfect(i)):
  20.         perfect.append(i)
  21.     else:
  22.         other.append(i)
  23.  
  24. toBinary = lambda x: format(ord(x),'b').zfill(8)
  25.  
  26. T = int(input())
  27.  
  28. for c in range(T):
  29.     x = input()
  30.     a = "".join(toBinary(i) for i in x)
  31.     i,j,k = 0,0,0
  32.     ans = []
  33.     for n in range(0,len(a),2):
  34.         ind = a[n:n+2]
  35.         if(ind == '11'):
  36.             ans.append(prime[i])
  37.             i+=1
  38.         elif(ind == '00'):
  39.             ans.append(perfect[j])
  40.             j+=1
  41.         else:
  42.             ans.append(other[k])
  43.             k+=1
  44.      print("Case " , c+1 , " : ", ",".join(str(i) for i in ans))
Add Comment
Please, Sign In to add comment