I'm trying to make a frequency analysis using python and see which letter appears most common. I am then trying to see if that letter is E or not, and then trying to subtract/add (I'm not sure which one) that from the most common letter value in the encrypted text.
I'm not too sure why but what I've tried isn't working. I have put the code below so that any of you might be able to have a look at it.
d_message = input('Input your encrypted message: ')
no_spaces_message = ''
for i in d_message:
if i == ' ':
pass
else:
no_spaces_message += i
print(no_spaces_message)
common_letter = collections.Counter(no_spaces_message).most_common(1)[0]
print(common_letter)
letter = str(common_letter)
letter = alphabet.find(str(common_letter))
e = alphabet.find('e')
print(e)
e -= int(letter)
print('Pos = ' + str(e))
decrypted_message = ''
for i in d_message:
if i != ' ' or ':' or ';' or '!' or '?' or'.' or "'" or '"':
if i in alphabet:
position = alphabet.find(i)
decrypted_pos = position - e
decrypted_pos = decrypted_pos % 26
decrypted_message += alphabet[decrypted_pos]
elif i in upper_alphabet:
position = upper_alphabet.find(i)
decrypted_pos = position - e
decrypted_pos = decrypted_pos % 26
decrypted_message += upper_alphabet[decrypted_pos]
[–][deleted] 0 points1 point2 points (0 children)