本文整理汇总了Python中cipher.Cipher类的典型用法代码示例。如果您正苦于以下问题:Python Cipher类的具体用法?Python Cipher怎么用?Python Cipher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cipher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: display
def display(self):
data = ""
ct = shared.breaklines(Cipher.encrypt(self.cipher), self.maxlinelen).split("n")
pt = shared.breaklines(self.cipher.decrypt(), self.maxlinelen).split("n")
for index in range(len(ct)):
data += ct[index] + "n"
data += pt[index] + "nn"
print data.strip("n")
示例2: encrypt
def encrypt(self, msg, addr):
logger.debug('before encryption')
if not self.knows(addr):
logger.debug('dont know who')
return False, None
logger.debug('checking methods')
methods = self.get_methods(shex(self.contact_capa[addr]))
if None in methods:
logger.debug('dont have methods')
return False, None
rsa_tag, cipher_tag = methods
logger.debug('methods checked: rsa_tag=%s, cipher_tag=%s' % (rsa_tag, cipher_tag))
try:
rsa_key = self.contact_keys[addr][RSALEN[rsa_tag]]
except KeyError:
logger.debug('does not have public key for %s, %s' % (repr(addr), RSALEN[rsa_tag]))
return False, None
logger.debug('got rsa key %s' % (RSALEN[rsa_tag]))
cipher = Cipher(*CIPHERS[cipher_tag])
logger.debug('ready to encypt cipher')
enc_msg = cipher.encrypt(msg)
enc_ses_key = rsa_key.encrypt(cipher.session_key)
capa = shex(rsa_tag | cipher_tag)
enc_raw = capa + ':' + binascii.b2a_hex(enc_ses_key) + ':' + binascii.b2a_hex(enc_msg)
logger.debug('encryption ok')
return True, enc_raw
示例3: decrypt
def decrypt(self, raw):
enc_capa, enc_session_key, enc_msg = re.split(':', raw, 2)
rsa_tag, cipher_tag = self.get_methods(enc_capa)
if not rsa_tag or not cipher_tag:
logger.debug('no method specified: %s, %s' % (rsa_tag, cipher_tag))
return False, None
try:
key = self.key[RSALEN[rsa_tag]]
enc_session_key = binascii.a2b_hex(enc_session_key)
session_key = key.decrypt(enc_session_key)
except:
logger.debug(traceback.format_exc())
return False, None
cipher = Cipher(*CIPHERS[cipher_tag], session_key=session_key)
enc_msg = binascii.a2b_hex(enc_msg)
dec_msg = cipher.decrypt(enc_msg)
return True, dec_msg
示例4: test_cipher_compositiion2
def test_cipher_compositiion2(self):
plaintext = 'adaywithoutlaughterisadaywasted'
c = Cipher()
self.assertEqual(plaintext, c.decode(c.encode(plaintext)))
示例5: test_cipher_compositiion1
def test_cipher_compositiion1(self):
key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
plaintext = 'adaywithoutlaughterisadaywasted'
c = Cipher(key)
self.assertEqual(plaintext, c.decode(c.encode(plaintext)))
示例6: test_cipher_encode_short_key
def test_cipher_encode_short_key(self):
c = Cipher('abcd')
self.assertEqual('abcdabcd', c.encode('aaaaaaaa'))
示例7: test_cipher_encode4
def test_cipher_encode4(self):
key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
c = Cipher(key)
self.assertEqual('gccwkixcltycv', c.encode('diffiehellman'))
示例8: test_cipher_encode3
def test_cipher_encode3(self):
c = Cipher('dddddddddddddddddddddd')
self.assertEqual('yhqlylglylfl', c.encode('venividivici'))
示例9: test_cipher_encode2
def test_cipher_encode2(self):
c = Cipher('aaaaaaaaaaaaaaaaaaaaaa')
self.assertEqual('itisawesomeprogramminginpython',
c.encode('itisawesomeprogramminginpython'))
示例10: Cipher
from sys import argv
import re
import random
from cipher import Cipher
from ngram import NGram
from break_cipher import BreakCipher
script,enc,text = argv
c = Cipher()
textEnc = c.cipher(enc)
dictionary = c.processText(text)
b = BreakCipher()
b.breakCipher(textEnc,dictionary)
示例11: frequency_list
def frequency_list(self, length = 1, text = ""):
text = Cipher.encrypt(self.cipher, text)
self.print_counts(shared.calc_graphs(text, int(length)))
示例12: frequency_list
def frequency_list(self, length = 1, text = ""):
"""Displays counts for frequencies of characters"""
text = Cipher.encrypt(self.cipher, text)
self.print_counts(shared.calc_graphs(text.split(" "), int(length)))
示例13: encrypt
def encrypt(self, text = ""):
text = Cipher.encrypt(self, text)
return self.process(self.ptkey, self.ctkey, text.lower())
示例14: decrypt
def decrypt(self, text = ""):
text = Cipher.decrypt(self, text)
return self.process(self.ctkey, self.ptkey, text.upper())
示例15: __init__
def __init__(self):
Cipher.__init__(self)
self.ctkey = string.ascii_uppercase
self.ptkey = "-" * 26
self.decrypt_filter = lambda char: char in (string.ascii_letters + string.punctuation + " ")
self.encrypt_filter = self.decrypt_filter