'Crypto'에 해당되는 글 2건

  1. 2016.02.15 Python RC2 (Rivest's Cipher version 2) Cipher
  2. 2014.05.27 Python PKCS#12 v1.0 PBKDF Module



The MIX transformation of RC2; four of these comprise a MIXING round


General

Designers      : Ron Rivest

First published : leaked in 1996, designed in 1987


Cipher detail

Key sizes      : 8–1024 bits, in steps of 8 bits; default 64 bits

Block sizes     : 64 bits

Structure        : Source-heavy unbalanced Feistel network

Rounds          : 16 of type MIXING, 2 of type MASHING



This module implements the RC2 (Rivest's Cipher version 2) encryption algorithm in pure python, specified in RFC 2268.


ECB and CBC modes are supported.


Original source code : https://github.com/0xEBFE/RC2-python/blob/master/rc2.py


Backporting Python 3 Code to Python 2.7.x by koha <kkoha@msn.com>


Quick start


Install from PyPIhttps://pip.pypa.io/en/latest/installing.html


pip install rc2


Example RC2 usage


from rc2 import *

#RC2 ECB encryption.
plaintext = "hello_word_ECB"
key = "test key"

rc2 = RC2(key)
encrypted = rc2.encrypt(plaintext,MODE_ECB)
print encrypted.encode('hex')

#RC2 ECB decryption.
rc2 = RC2(key)
decrypted = rc2.decrypt(encrypted,MODE_ECB)
print decrypted

#RC2 CBC encryption.
plaintext = "hello_word_CBC"
key = "test key"
iv = "\x01\x02\x03\x04\x05\x06\x07\x08"

rc2 = RC2(key)
encrypted = rc2.encrypt(plaintext,MODE_CBC,iv,PADDING_PKCS5)
print encrypted.encode('hex')

#RC2 CBC decryption.
rc2 = RC2(key)
decrypted = rc2.decrypt(encrypted,MODE_CBC,iv,PADDING_PKCS5)
print decrypted


https://pypi.python.org/pypi/rc2

저작자 표시
신고
Posted by kkoha 트랙백 0 : 댓글 0

This module implements the password-based key derivation function, PBKDF, specified in RSA PKCS#12 v1.0.


Quick start


Install from PyPIhttps://pip.pypa.io/en/latest/installing.html


pip install PBKDF_PKCS12


Example PBKDF PKCS#12 v1.0 usage

PBKDF_PKCS12v1(iteration, password, salt, keylen)


import PBKDF_PKCS12
from Crypto.Cipher import AES
import os

salt = os.urandom(8)    # 64-bit salt
key = PBKDF_PKCS12.PBKDF_PKCS12v1(2, "This passphrase is a secret" , salt, 32) # 256-bit key
iv = os.urandom(16)     # 128-bit IV
cipher = AES.new(key, AES.MODE_CBC, iv)


https://pypi.python.org/pypi/PBKDF_PKCS12/1.0

저작자 표시
신고
Posted by kkoha 트랙백 0 : 댓글 0

티스토리 툴바