本文整理汇总了Python中mapper.Mapper.generate_candidates方法的典型用法代码示例。如果您正苦于以下问题:Python Mapper.generate_candidates方法的具体用法?Python Mapper.generate_candidates怎么用?Python Mapper.generate_candidates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapper.Mapper
的用法示例。
在下文中一共展示了Mapper.generate_candidates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Cryptsession
# 需要导入模块: from mapper import Mapper [as 别名]
# 或者: from mapper.Mapper import generate_candidates [as 别名]
#.........这里部分代码省略.........
else:
#if we do not have a mapping use ?
plainword+=u"?"
#if not at least half of the letters have a mapping don't show word-mapping
if plainword.count(u"?") <= len(word)/2:
out+= u" --> {}".format(plainword.lower())
print out
def show_plaintext(self):
decrypted = ''
for symbol in self.ciphertext.text:
#check if there is a substitution-rule
if self.mapper.has_mapping_from(symbol):
#use it
decrypted += self.mapper.get_mapping_from(symbol).lower()
else:
#use letter from ciphertext instead
decrypted += symbol
print decrypted
def show_menu(self):
choice =u''
while True:
print "======== Available Actions ========"
print "[0] Read ciphertext from file"
print "[1] Show ciphertext"
#print "[2] Analyse ciphertext"
print "[3] Show reference frequencies (symbols)"
#TODO Show absolute frequencies
print "[4] Show ciphertext frequencies (symbols)"
print "[5] Shwo n most frequent symbols"
print "[6] Show n most frequent bigrams"
print "[7] Show n most frequent trigrams"
print "[8] Show n most frequent words"
print "[9] Create n substitution rules using symbol-frequencies "
print "[10] Define substitution rule for ciphertext -> plaintext"
print "[11] Remove substitution rule"
print "[12] Show substitution rules"
print "[13] Show decrypted text (uses substitution rules)"
print "==================================="
choice = input("Please choose: ")
try:
if choice == 0:
fn = raw_input("Path to ciphertext: ")
lan = raw_input("Language of ciphertext (german/english): ")
self.reference = ReferenceModel.for_language(lan)
self.ciphertext = AnalysisModel.from_file(fn,self.reference)
self.show_most_frequent_symbols()
self.show_most_frequent_bigrams()
self.show_most_frequent_trigrams()
elif choice == 1:
self.ciphertext.show_text()
elif choice == 2:
self.analyze()
elif choice == 3:
self.reference.show_letter_freqs()
elif choice == 4:
self.ciphertext.show_letter_freqs()
elif choice == 5:
n = raw_input("n: ").decode(sys.stdout.encoding)
self.show_most_frequent_symbols(int(n))
elif choice == 6:
n = raw_input("n: ").decode(sys.stdout.encoding)
self.show_most_frequent_bigrams(int(n))
elif choice == 8:
n = raw_input("n: ").decode(sys.stdout.encoding)
self.show_most_frequent_words(int(n))
elif choice == 7:
n = raw_input("n: ").decode(sys.stdout.encoding)
self.show_most_frequent_trigrams(int(n))
elif choice == 9:
n = raw_input("n: ").decode(sys.stdout.encoding)
self.mapper.generate_mappings(self.reference,self.ciphertext,int(n))
elif choice == 10:
ciph = raw_input("From: ").decode(sys.stdout.encoding)
plain = raw_input("To: ").decode(sys.stdout.encoding)
self.mapper.add_mapping(ciph, plain)
elif choice == 11:
ciph = raw_input("Remove substitution for which letter?").decode(sys.stdout.encoding)
self.mapper.remove_mapping(ciph)
elif choice == 12:
self.mapper.show_mappings()
elif choice == 13:
self.show_plaintext()
elif choice == 14:
fn = raw_input("filename: ").decode(sys.stdout.encoding)
self.mapper.load_mappings(fn)
elif choice == 15:
fn = raw_input("filename: ").decode(sys.stdout.encoding)
self.mapper.store_mappings(fn)
elif choice == 16:
self.mapper.generate_candidates(self.reference, self.ciphertext)
elif choice == 'q':
system.exit(0)
else:
print "Unknown option"
except:
raise