Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. def get_cipherType(ciphertext):
  2.     if len(ciphertext) == 0:
  3.         return 'Empty Ciphertext'
  4.     polybius = True
  5.     polybius_count =0
  6.     for i in ciphertext:
  7.         if i =='\n':
  8.             continue
  9.         else:
  10.             try:
  11.                 int(i)
  12.                 polybius_count+=1
  13.             except:
  14.                 polybius = False
  15.                 break
  16.     if (polybius and (polybius_count%2==0)):
  17.         return 'Polybius Square Cipher'
  18.    
  19.     ic = get_indexOfCoin(remove_nonalpha(ciphertext))
  20.     chi_squared = utilities_A2.get_chiSquared(remove_nonalpha(ciphertext))
  21.     if (chi_squared < 400):
  22.         return 'Spartan Scytale Cipher'
  23.     else:
  24.         modified_ciphertext = ''
  25.         for i in ciphertext:
  26.             if i.isalpha():
  27.                 modified_ciphertext+=chr(ord('Z') - ord(i.upper())+65)
  28.             else:
  29.                 modified_ciphertext+=i
  30.         chi_squared_possible_atbash =  utilities_A2.get_chiSquared(remove_nonalpha(modified_ciphertext))    
  31.         if (ic>=0.062 and ic<=0.068 and chi_squared_possible_atbash<150):
  32.             return 'Atbash Cipher'
  33.         elif(ic>=0.062 and ic<=0.068):
  34.             return 'Shift Cipher'
  35.         elif(ic>=0.0415 and ic<=0.062):
  36.             return 'Vigenere Cipher'
  37.     return 'Unknown'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement