def incidenceOfCoincidence(sequence): if (len(sequence) > 1): F = Frequency() F.count(sequence) IncOfCoinc = 0 FreqNum = 0 length = len(sequence) for i in range(0,26): FreqNum = F.getNthNum(i) IncOfCoinc = IncOfCoinc + (FreqNum*(FreqNum - 1)) IncOfCoinc = (IncOfCoinc / (length*(length - 1))) return IncOfCoinc else: return 0
def incidence_of_coincidence(sequence): ''' Processes and return the incidence of coincidence of a given substring of the ciphertext ''' if (len(sequence) > 1): F = Frequency() F.count(sequence) IncOfCoinc = 0 FreqNum = 0 length = len(sequence) for i in range(0,26): FreqNum = F.getNthNum(i) IncOfCoinc = IncOfCoinc + (FreqNum*(FreqNum - 1)) IncOfCoinc = (IncOfCoinc / (length*(length - 1))) return IncOfCoinc else: return 0