# Python实用宝典
# 2021/07/19
from ciphey.__main__ import main, main_decrypt, make_default_config
main_decrypt(make_default_config("SGVsbG8gbXkgbmFtZSBpcyBiZWUgYW5kIEkgbGlrZSBkb2cgYW5kIGFwcGxlIGFuZCB0cmVl"))
# >> Hello my name is bee and I like dog and apple and tree
运行后会输出如下的结果:
效果还是相当不错的,如果你不想输出概率表,只想要解密内容,代码需要这么写:
# Python实用宝典
# 2021/07/19
from ciphey.__main__ import main, main_decrypt, make_default_config
config = make_default_config("SGVsbG8gbXkgbmFtZSBpcyBiZWUgYW5kIEkgbGlrZSBkb2cgYW5kIGFwcGxlIGFuZCB0cmVl")
config["grep"] = True
main_decrypt(config)
# >> Hello my name is bee and I like dog and apple and tree
非常Nice,你根本无需知道这是什么编码。
Ciphey 支持解密的密文和编码多达51种,下面列出一些基本的选项
基本密码:
Caesar Cipher
ROT47 (up to ROT94 with the ROT47 alphabet)
ASCII shift (up to ROT127 with the full ASCII alphabet)
Vigenère Cipher
Affine Cipher
Binary Substitution Cipher (XY-Cipher)
Baconian Cipher (both variants)
Soundex
Transposition Cipher
Pig Latin
现代密码学:
Repeating-key XOR
Single XOR
编码:
Base32
Base64
Z85 (release candidate stage)
Base65536 (release candidate stage)
ASCII
Reversed text
Morse Code
DNA codons (release candidate stage)
Atbash
Standard Galactic Alphabet (aka Minecraft Enchanting Language)
from flashtext import KeywordProcessor
# 1. 初始化关键字处理器
keyword_processor = KeywordProcessor()
# 2. 添加关键词
keyword_processor.add_keyword('New Delhi', 'NCR region')
# 3. 替换关键词
new_sentence = keyword_processor.replace_keywords('I love Big Apple and new delhi.')
# 4. 结果
print(new_sentence)
# 'I love New York and NCR region.'
关键词大小写敏感
如果你需要精确提取,识别大小写字母,那么你可以在处理器初始化的时候设定 sensitive 参数:
from flashtext import KeywordProcessor
# 1. 初始化关键字处理器, 注意设置大小写敏感(case_sensitive)为TRUE
keyword_processor = KeywordProcessor(case_sensitive=True)
# 2. 添加关键词
keyword_processor.add_keyword('Big Apple', 'New York')
keyword_processor.add_keyword('Bay Area')
# 3. 处理目标句子并提取相应关键词
keywords_found = keyword_processor.extract_keywords('I love big Apple and Bay Area.')
# 4. 结果
print(keywords_found)
# ['Bay Area']
# example1:
>>> a = "wtf"
>>> b = "wtf"
>>> a is b
True
# example2:
>>> a = "wtf!"
>>> b = "wtf!"
>>> a is b
False
# example3:
>>> a, b = "wtf!", "wtf!"
>>> a is b
True # 3.7 版本返回结果为 False.
# example4:
>>> 'a' * 20 is 'aaaaaaaaaaaaaaaaaaaa'
True
>>> 'a' * 21 is 'aaaaaaaaaaaaaaaaaaaaa'
False # 3.7 版本返回结果为 True
from functools import singledispatch
@singledispatch
def fun(arg, verbose=False):
if verbose:
print("Let me just say,", end=" ")
print(arg)
然后用register属性注册重载后的函数:
@fun.register(int)
def _(arg: int, verbose=False):
if verbose:
print("Strength in numbers, eh?", end=" ")
print(arg)
@fun.register(list)
def _(arg: list, verbose=False):
if verbose:
print("Enumerate this:")
for i, elem in enumerate(arg):
print(i, elem)