当前位置: 首页>>代码示例>>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;未经允许,请勿转载。