Помогите перевести с Python на C#

Помогите, пожалуйста, написать данный код на С#:

MAX_KEY_LENGTH_GUESS = 20
alphabet = 'abcdefghijklmnopqrstuvwxyz'
english_frequences = [0.08167, 0.01492, 0.02782, 0.04253, 0.12702, 0.02228, 0.02015,
                  0.06094, 0.06966, 0.00153, 0.00772, 0.04025, 0.02406, 0.06749,
                  0.07507, 0.01929, 0.00095, 0.05987, 0.06327, 0.09056, 0.02758,
                  0.00978, 0.02360, 0.00150, 0.01974, 0.00074]
def get_index_c(ciphertext):
N = float(len(ciphertext))
frequency_sum = 0.0
for letter in alphabet:
    frequency_sum += ciphertext.count(letter) * (ciphertext.count(letter) - 1)

ic = frequency_sum / (N * (N - 1))
return ic


def get_key_length(ciphertext):
ic_table = []
for guess_len in range(MAX_KEY_LENGTH_GUESS):
    ic_sum = 0.0
    avg_ic = 0.0
    for i in range(guess_len):
        sequence = ""
        for j in range(0, len(ciphertext[i:]), guess_len):
            sequence += ciphertext[i + j]
        ic_sum += get_index_c(sequence)
    if not guess_len == 0:
        avg_ic = ic_sum / guess_len
    ic_table.append(avg_ic)

best_guess = ic_table.index(sorted(ic_table, reverse=True)[0])
second_best_guess = ic_table.index(sorted(ic_table, reverse=True)[1])
if best_guess % second_best_guess == 0:
    return second_best_guess
else:
    return best_guess
def freq_analysis(sequence):
all_chi_squareds = [0] * 26

for i in range(26):

    chi_squared_sum = 0.0
    sequence_offset = [chr(((ord(sequence[j]) - 97 - i) % 26) + 97) for j in range(len(sequence))]
    v = [0] * 26
    for l in sequence_offset:
        v[ord(l) - ord('a')] += 1
    for j in range(26):
        v[j] *= (1.0 / float(len(sequence)))
    for j in range(26):
        chi_squared_sum += ((v[j] - float(english_frequences[j])) ** 2) / float(english_frequences[j])
    all_chi_squareds[i] = chi_squared_sum
shift = all_chi_squareds.index(min(all_chi_squareds))
return chr(shift + 97)


def get_key(ciphertext, key_length):
key = ''
for i in range(key_length):
    sequence = ""
    for j in range(0, len(ciphertext[i:]), key_length):
        sequence += ciphertext[i + j]
    key += freq_analysis(sequence)

return key


def decrypt(ciphertext, key):
cipher_ascii = [ord(letter) for letter in ciphertext]
key_ascii = [ord(letter) for letter in key]
plain_ascii = []
for i in range(len(cipher_ascii)):
    plain_ascii.append(((cipher_ascii[i] - key_ascii[i % len(key)]) % 26) + 97)
plaintext = ''.join(chr(i) for i in plain_ascii)
return plaintext


def Plain_text(message):
ciphertext_unfiltered = message
ciphertext = ''.join(x.lower() for x in ciphertext_unfiltered if x.isalpha())
key_length = get_key_length(ciphertext)
key = get_key(ciphertext, key_length)
plaintext = decrypt(ciphertext, key)
return plaintext


def Key_length(message):
ciphertext_unfiltered = message
ciphertext = ''.join(x.lower() for x in ciphertext_unfiltered if x.isalpha())
key_length = get_key_length(ciphertext)
return key_length


def Key(message):
ciphertext_unfiltered = message
ciphertext = ''.join(x.lower() for x in ciphertext_unfiltered if x.isalpha())
key_length = get_key_length(ciphertext)
key = get_key(ciphertext, key_length)
return key

Ответы (0 шт):