當前位置: 首頁>>代碼示例>>Python>>正文


Python cipher.Cipher類代碼示例

本文整理匯總了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")
開發者ID:Insaida,項目名稱:NSFcryptTool,代碼行數:9,代碼來源:aristocrat.py

示例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
開發者ID:ZhuZhengyi,項目名稱:ipmsg-1,代碼行數:32,代碼來源:__init__.py

示例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
開發者ID:ZhuZhengyi,項目名稱:ipmsg-1,代碼行數:21,代碼來源:__init__.py

示例4: test_cipher_compositiion2

 def test_cipher_compositiion2(self):
     plaintext = 'adaywithoutlaughterisadaywasted'
     c = Cipher()
     self.assertEqual(plaintext, c.decode(c.encode(plaintext)))
開發者ID:leovieira20,項目名稱:exercismpython,代碼行數:4,代碼來源:simple_cipher_test.py

示例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)))
開發者ID:leovieira20,項目名稱:exercismpython,代碼行數:6,代碼來源:simple_cipher_test.py

示例6: test_cipher_encode_short_key

 def test_cipher_encode_short_key(self):
     c = Cipher('abcd')
     self.assertEqual('abcdabcd', c.encode('aaaaaaaa'))
開發者ID:leovieira20,項目名稱:exercismpython,代碼行數:3,代碼來源:simple_cipher_test.py

示例7: test_cipher_encode4

 def test_cipher_encode4(self):
     key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
            'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
     c = Cipher(key)
     self.assertEqual('gccwkixcltycv', c.encode('diffiehellman'))
開發者ID:leovieira20,項目名稱:exercismpython,代碼行數:5,代碼來源:simple_cipher_test.py

示例8: test_cipher_encode3

 def test_cipher_encode3(self):
     c = Cipher('dddddddddddddddddddddd')
     self.assertEqual('yhqlylglylfl', c.encode('venividivici'))
開發者ID:leovieira20,項目名稱:exercismpython,代碼行數:3,代碼來源:simple_cipher_test.py

示例9: test_cipher_encode2

 def test_cipher_encode2(self):
     c = Cipher('aaaaaaaaaaaaaaaaaaaaaa')
     self.assertEqual('itisawesomeprogramminginpython',
                      c.encode('itisawesomeprogramminginpython'))
開發者ID:leovieira20,項目名稱:exercismpython,代碼行數:4,代碼來源:simple_cipher_test.py

示例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)

開發者ID:Trindad,項目名稱:trabalhos-seguranca,代碼行數:17,代碼來源:main.py

示例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)))
開發者ID:Insaida,項目名稱:NSFcryptTool,代碼行數:3,代碼來源:patristocrat.py

示例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)))
開發者ID:Insaida,項目名稱:NSFcryptTool,代碼行數:4,代碼來源:aristocrat.py

示例13: encrypt

 def encrypt(self, text = ""):
   text = Cipher.encrypt(self, text)
   return self.process(self.ptkey, self.ctkey, text.lower())
開發者ID:Insaida,項目名稱:NSFcryptTool,代碼行數:3,代碼來源:aristocrat.py

示例14: decrypt

 def decrypt(self, text = ""):
   text = Cipher.decrypt(self, text)
   return self.process(self.ctkey, self.ptkey, text.upper())
開發者ID:Insaida,項目名稱:NSFcryptTool,代碼行數:3,代碼來源:aristocrat.py

示例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
開發者ID:Insaida,項目名稱:NSFcryptTool,代碼行數:6,代碼來源:aristocrat.py


注:本文中的cipher.Cipher類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。