本文整理汇总了Python中helper.Helper.format方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.format方法的具体用法?Python Helper.format怎么用?Python Helper.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helper.Helper
的用法示例。
在下文中一共展示了Helper.format方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import format [as 别名]
class Vegenere:
def __init__(self):
self.helper = Helper()
def encrypt(self, plaintext, key):
plaintext = self.helper.format(plaintext)
key = self.helper.format(key)
kryptotext = ''
for index, char in enumerate(plaintext):
plain_char = ord(char) - 65
key_char = ord(key[index % len(key)]) - 65
krypto_char = ((plain_char + key_char) % 26) + 65
kryptotext += unichr(krypto_char)
return kryptotext
def decrypt(self, kryptotext, key):
kryptotext = self.helper.format(kryptotext)
key = self.helper.format(key)
plaintext = ''
for index, char in enumerate(kryptotext):
krypto_char = ord(char) - 65
key_char = ord(key[index % len(key)]) - 65
plain_char = ((krypto_char - key_char) % 26)
if plain_char < 0:
plain_char += 26
plain_char += 65
plaintext += unichr(plain_char)
return plaintext
示例2: _char_frequency
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import format [as 别名]
def _char_frequency(text):
frequencies = [0 for i in range(26)]
text = Helper.format(text)
for index, char in enumerate(text):
frequencies[ord(char) - 65] += 1
return frequencies
示例3: _find_positions
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import format [as 别名]
def _find_positions(self, krypto_text):
krypto_text = Helper.format(krypto_text)
positions = {}
for i in range(len(krypto_text)-2):
sub = krypto_text[i:i+3]
if sub in positions:
positions[sub].append(i+1)
else:
positions[sub] = [i+1]
return self._remove_zero_or_one_occurancies(positions)