コード例 #1
0
ファイル: alphabetic_ut.py プロジェクト: cyrylk/MCMC
 def test_stripped_text_properties(self):
     stripped_text1 = alphabetic.StrippedText("LET US GO! IT IS TIME. ",
                                              alphabetic.Alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
     self.assertEqual(stripped_text1.ends_of_words, {2: 0, 4: 1, 6: 2, 8: 3, 10: 4, 14: 5})
     self.assertEqual(stripped_text1.stripped_part, [" ", " ", "! ", " ", " ", ". ", ""])
     self.assertEqual(stripped_text1.get_non_stripped_text(), "LET US GO! IT IS TIME. ")
     self.assertEqual(stripped_text1.positions["L"], set([0]))
     self.assertEqual(stripped_text1.positions["E"], set([1, 14]))
     stripped_text2 = alphabetic.StrippedText("  LET US GO! IT IS TIME",
                                              alphabetic.Alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
     self.assertEqual(stripped_text2.ends_of_words, {-1: 0, 2: 1, 4: 2, 6: 3, 8: 4, 10: 5, 14: 6})
     self.assertEqual(stripped_text2.stripped_part, ["  ", " ", " ", "! ", " ", " ", ""])
     self.assertEqual(stripped_text2.get_non_stripped_text(), "  LET US GO! IT IS TIME")
     stripped_text2[3] = "F"
     self.assertEqual(stripped_text2[3], "F")
     self.assertEqual(stripped_text2.positions["F"], set([3]))
コード例 #2
0
 def test_encrypt_decrypt_text(self):
     self.assertEqual(
         vigenere.encrypt_decrypt_text("MONTE CARLO", [1, 2],
                                       self.alphabet), list("NQOVF DCSNP"))
     stripped_text = alphabetic.StrippedText("MONTE CARLO", self.alphabet)
     self.assertEqual(
         vigenere.encrypt_decrypt_text(stripped_text, [1, 2],
                                       self.alphabet).non_stripped_part,
         list("NQOVFEBTMQ"))
コード例 #3
0
def create_stripped_encryption_decryption(text, encryption_decryption,
                                          alphabet):
    result = alphabetic.StrippedText(encryption_decryption, alphabet)
    result.set_ends_of_words(text.ends_of_words)
    result.set_stripped_part(text.stripped_part)
    return result
コード例 #4
0
ファイル: substitution.py プロジェクト: cyrylk/MCMC
                common.update_frequency(current_frequencies, frequency_change)
                current_dist += dist_change
                aux = current_order[swapp[0]]
                current_order[swapp[0]] = current_order[swapp[1]]
                current_order[swapp[1]] = aux

                if current_dist > max_dist:
                    max_dist = current_dist
                    max_state = copy.deepcopy(current_guessed_decoding_key)
                    print(current_decryption.get_non_stripped_text())
    return get_reverse_permutation(alphabet, max_state)


alphabett = alphabetic.Alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
plain = alphabetic.StrippedText(
    data_generator.get_string_cleared(
        data_generator.generate_random_excerpt("../data/1984.txt",
                                               2000)).upper(), alphabett)

standard2 = data_generator.get_log_distribution_from_json(
    "../data/bigram_log_distributions_uppercase.json")
standard1 = data_generator.get_log_distribution_from_json(
    "../data/monogram_log_distributions_uppercase.json")

all_printable = data_generator.get_string_cleared(string.printable + " ")
upper_printable = all_printable[:10] + all_printable[36:]
complete_alphabet = alphabetic.Alphabet(
    data_generator.get_string_cleared(string.printable + " "))
upper_alphabet = alphabetic.Alphabet(upper_printable)

freqs = common.calculate_n_gram_frequencies(plain, 1)
コード例 #5
0
ファイル: autokey_ut.py プロジェクト: cyrylk/MCMC
 def test_encrypt_text(self):
     text = alphabetic.StrippedText("A B C D E", self.alphabet)
     self.assertEqual(
         autokey.encrypt_text(text, [1, 2],
                              self.alphabet).get_non_stripped_text(),
         "B D C E G")