RC6Encryption (version 1.0.0)
index
rc6encryption.py

This package implements RC6 encryption.
 
>>> rc6 = RC6Encryption(b'abcdefghijklmnop', 12, 32, 5)
>>> c = rc6.blocks_to_data(rc6.encrypt(b'abcdefghijklmnop'))
>>> rc6.blocks_to_data(rc6.decrypt(c))
b'abcdefghijklmnop'
>>>
 
>>> from urllib.request import urlopen, Request
>>> from json import dumps, load
>>> rc6 = RC6Encryption(b'abcdefghijklmnop')
>>> encrypt = rc6.blocks_to_data(rc6.encrypt(b'abcdefghijklmnop')).hex()
>>> encrypt
'bb05a4b6c46a24a8bf70e1e2c0a33e51'
>>> encrypt == load(urlopen(Request("https://www.lddgo.net/api/RC6?lang=en", headers={"Content-Type": "application/json;charset=UTF-8"}, data=dumps({"inputContent":"abcdefghijklmnop","model":"ECB","padding":"nopadding","inputPassword":"abcdefghijklmnop","inputIv":"","inputFormat":"string","outputFormat":"hex","charset":"UTF-8","encrypt":True}).encode())))["data"]
True
>>> encrypt = rc6.blocks_to_data(rc6.encrypt(b'abcdefghijklmnop') + rc6.encrypt(b'abcdefghijklmnop')).hex()
>>> encrypt
'bb05a4b6c46a24a8bf70e1e2c0a33e51bb05a4b6c46a24a8bf70e1e2c0a33e51'
>>> encrypt == load(urlopen(Request("https://www.lddgo.net/api/RC6?lang=en", headers={"Content-Type": "application/json;charset=UTF-8"}, data=dumps({"inputContent":"abcdefghijklmnopabcdefghijklmnop","model":"ECB","padding":"nopadding","inputPassword":"abcdefghijklmnop","inputIv":"","inputFormat":"string","outputFormat":"hex","charset":"UTF-8","encrypt":True}).encode())))["data"]
True
>>> pkcs5_7padding(b'abcdefghijklmno')
b'abcdefghijklmno\x01'
>>> remove_pkcs_padding(pkcs5_7padding(b'abcdefghijklmno')) == b'abcdefghijklmno'
True
>>> pkcs5_7padding(b'abcdefghijklm')
b'abcdefghijklm\x03\x03\x03'
>>> remove_pkcs_padding(pkcs5_7padding(b'abcdefghijklm')) == b'abcdefghijklm'
True
>>> rc6 = RC6Encryption(b'abcdefghijklm')
>>> encrypt = rc6.blocks_to_data(rc6.encrypt(pkcs5_7padding(b'abcdefghijklm'))).hex()
>>> encrypt
'c5ee3509788662a5711822d5e01eb4c0'
>>> encrypt == load(urlopen(Request("https://www.lddgo.net/api/RC6?lang=en", headers={"Content-Type": "application/json;charset=UTF-8"}, data=dumps({"inputContent":"abcdefghijklm","model":"ECB","padding":"pkcs5padding","inputPassword":"abcdefghijklm","inputIv":"","inputFormat":"string","outputFormat":"hex","charset":"UTF-8","encrypt":True}).encode())))["data"]
True
>>> rc6 = RC6Encryption(b'abcd')
>>> encrypt = rc6.data_encryption_ECB(b'abcdefghijklmnop').hex()
>>> encrypt
'78a64e37f7455f30aaf40750be1a065701bf2f308216c43c42c794285ffbf99e'
>>> encrypt == load(urlopen(Request("https://www.lddgo.net/api/RC6?lang=en", headers={"Content-Type": "application/json;charset=UTF-8"}, data=dumps({"inputContent":"abcdefghijklmnop","model":"ECB","padding":"pkcs5padding","inputPassword":"abcd","inputIv":"","inputFormat":"string","outputFormat":"hex","charset":"UTF-8","encrypt":True}).encode())))["data"]
True
>>> rc6.data_decryption_ECB(bytes.fromhex('78a64e37f7455f30aaf40750be1a065701bf2f308216c43c42c794285ffbf99e'))
b'abcdefghijklmnop'
>>> rc6 = RC6Encryption(b'abcd')
>>> iv, encrypt = rc6.data_encryption_CBC(b'abcdefghijklmnopabcdefghijklmnopabcdefghijklm', b'IVTEST')
>>> encrypt = encrypt.hex()
>>> iv
b'IVTESTIVTESTIVTE'
>>> encrypt
'8de91e69865825bbb6e1785e3b498f3a89708aaa2aff01a688cf9836bd7eea56c04fa0a14706d79bd94846e905bf070b'
>>> encrypt == load(urlopen(Request("https://www.lddgo.net/api/RC6?lang=en", headers={"Content-Type": "application/json;charset=UTF-8"}, data=dumps({"inputContent":"abcdefghijklmnopabcdefghijklmnopabcdefghijklm","model":"CBC","padding":"pkcs5padding","inputPassword":"abcd","inputIv":iv.decode('latin-1'),"inputFormat":"string","outputFormat":"hex","charset":"UTF-8","encrypt":True}).encode())))["data"]
True
>>> rc6.data_decryption_CBC(bytes.fromhex('8de91e69865825bbb6e1785e3b498f3a89708aaa2aff01a688cf9836bd7eea56c04fa0a14706d79bd94846e905bf070b'), iv)
b'abcdefghijklmnopabcdefghijklmnopabcdefghijklm'
>>> 
 
~# rc6 mykey -s mydata -6
0wS4TwM292nGa378oBuz/w==
~# rc6 mykey -s 0wS4TwM292nGa378oBuz/w== -n base64 -d
mydata
~# rc6 mykey --no-sha256 -r 12 -s mydata -6
vzliI0irqi3tZ8fULxJ14g==
~# rc6 mykey --no-sha256 -r 12 -s vzliI0irqi3tZ8fULxJ14g== -n base64 -d
mydata
~# rc6 mykey -m CBC -I myiv -s mydata -1
6D7969766D7969766D7969766D796976BF2F024053F74FE27920DE5C274935A6
~# rc6 mykey -m CBC -d -s 6D7969766D7969766D7969766D796976BF2F024053F74FE27920DE5C274935A6 -n base16
mydata
~# 
 
1 items passed all tests:
  32 tests in RC6Encryption
32 tests in 25 items.
32 passed and 0 failed.
Test passed.

 
Classes
       
builtins.object
RC6Encryption

 
class RC6Encryption(builtins.object)
    RC6Encryption(key: bytes, rounds: int = 20, w_bit: int = 32, lgw: int = 5)
 
This class implements the RC6 encryption.
 
Rounds possible values: {12, 16, 20}
 
  Methods defined here:
__init__(self, key: bytes, rounds: int = 20, w_bit: int = 32, lgw: int = 5)
Initialize self.  See help(type(self)) for accurate signature.
data_decryption_CBC(self, data: bytes, iv: bytes) -> bytes
This function performs full decryption using CBC mode:
    - get blocks
    - decrypt all blocks using CBC mode
    - convert blocks in bytes
    - remove PKCS (5/7) padding
    - returns bytes
data_decryption_ECB(self, data: bytes) -> bytes
This function performs full decryption using ECB mode:
    - get blocks
    - decrypt all blocks using ECB mode
    - convert blocks in bytes
    - remove PKCS (5/7) padding
    - returns bytes
data_encryption_CBC(self, data: bytes, iv: bytes = None) -> Tuple[bytes, bytes]
This function performs full encryption using CBC mode:
    - get/generate the IV
    - add PKCS (5/7) padding
    - get blocks
    - encrypt all blocks using CBC mode
    - convert blocks in bytes
    - returns bytes
data_encryption_ECB(self, data: bytes) -> bytes
This function performs full encryption using ECB mode:
    - add PKCS (5/7) padding
    - get blocks
    - encrypt all blocks using ECB mode
    - convert blocks in bytes
    - returns bytes
decrypt(self, data: bytes) -> List[int]
This function performs a RC6 decryption.
encrypt(self, data: Union[bytes, Tuple[int, int, int, int]]) -> List[int]
This functions performs RC6 encryption on only one block.
 
This function returns a list of 4 integers.
key_generation(self) -> List[int]
This function generate the key.
left_rotation(self, x: int, n: int) -> int
This function perform a left rotation (based on right rotation).
right_rotation(self, x: int, n: int) -> int
This function perform a right rotation.

Static methods defined here:
blocks_to_data(blocks: List[int]) -> bytes
This function returns data from blocks (binary strings).
enumerate_blocks(data: bytes) -> collections.abc.Iterator[typing.Tuple[int, int, int, int]]
This function returns a tuple of 4 integers for each blocks.
get_blocks(data: bytes) -> Tuple[List[str], List[int]]
This function returns blocks (binary strings and integers) from data.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
P32 = 3084996963
Q32 = 2654435769

 
Functions
       
pkcs5_7padding(data: bytes, size: int = 16) -> bytes
This function implements PKCS 5/7 padding.

 
Data
        __all__ = ['RC6Encryption', 'pkcs5_7padding']
__author_email__ = 'mauricelambert434@gmail.com'
__copyright__ = '\nRC6Encryption Copyright (C) 2021, 2023, 2024 ...ome to redistribute it\nunder certain conditions.\n'
__description__ = 'This package implements RC6 encryption.'
__license__ = 'GPL-3.0 License'
__maintainer__ = 'Maurice Lambert'
__maintainer_email__ = 'mauricelambert434@gmail.com'
__url__ = 'https://github.com/mauricelambert/RC6Encryption'

 
Author
        Maurice Lambert