Sandra


NameSandra JSON
Version 0.0.18 PyPI version JSON
download
home_pagehttps://github.com/lopgogo/Sandra
SummaryAES Stream Cipher with CFB and OpenPGP Modes
upload_time2023-05-08 18:46:56
maintainer
docs_urlNone
authorGeorge Assaad
requires_python
licenseMIT
keywords python encryption decryption cipher cryptography
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Sandra

![logo](https://user-images.githubusercontent.com/26662104/234409378-4602ff85-8fb1-425d-9213-979876c78dcc.png)



**Sandra implements CFB and  [OpenPGP-CFB](https://datatracker.ietf.org/doc/html/rfc4880) built on top of pycryptodome.**



## Usage

### Loading Data

```python

Sandra.load_data(

    path # str -> path to data to be loaded

)

```

### Writing Data

 ```python

Sandra.write_data(

    file_names, # name of files to be written

    file_data, # data to be written, must be the same length as file_names

    path='.' # path to write data to

)

```



## Examples

### RSA File Encryption 

```python

import Sandra

file_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt') 

enc_dec_rsa = Sandra.RSA(2048, Sandra.RSA_ENGINE_DOME)

ciphertext = enc_dec_rsa.encrypt(file_data[0])

print(len(ciphertext))

plaintext = enc_dec_rsa.decrypt(ciphertext)

print(plaintext == file_data[0])

Sandra.write_data(

    file_names, # name of the file to be written

    [plaintext], # data to be written, must be the same length as file_names

    path='./taylor_txt_ed' # path to write data to

)

```



### AES CFB Mode Sample(NIST) Encryption

```python

import Sandra

#Test Case from http://csrc.nist.gov/groups/STM/cavp/block-ciphers.html#aes

data = bytes.fromhex('fffffe00000000000000000000000000')

iv   = bytes.fromhex('fffffe00000000000000000000000000')

key  = bytes.fromhex('00000000000000000000000000000000')



enc_dec_sandra = Sandra.AES(key, Sandra.MODE_CFB, iv, segment_size=16)

ciphertext = enc_dec_sandra.encrypt(data)

plaintext = enc_dec_sandra.decrypt(ciphertext)

```



### AES CFB Mode File Encryption

```python

import Sandra

iv   = bytes.fromhex('fffffe00000000000000000000000000')

key  = bytes.fromhex('00000000000000000000000000000000')

file_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt') 

enc_dec_cfb = Sandra.AES(key, Sandra.MODE_CFB, iv, segment_size=16)

ciphertext = enc_dec_cfb.encrypt(file_data[0])

print(len(ciphertext))

plaintext = enc_dec_cfb.decrypt(ciphertext)

print(plaintext == file_data[0])

Sandra.write_data(

    file_names, # name of the file to be written

    [plaintext], # data to be written, must be same length as file_names

    path='./taylor_txt_ed' # path to write data to

)

```



### AES OpenPGP-CFB Mode File Encryption

> In This mode, the first 18 bytes of cipher text contain the encrypted IV

> Padding here is unnecessary as this mode is a stream cipher

```python

import Sandra

iv   = bytes.fromhex('fffffe00000000000000000000000000')

key  = bytes.fromhex('00000000000000000000000000000000')

file_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt')

print(len(file_data[0]))

file_data_padded = Sandra.pad(file_data, Sandra.AES_BLOCK_SIZE) 

print(len(file_data_padded[0]))

enc_dec_pgp = Sandra.AES(key, Sandra.MODE_OPENPGP, iv)

ciphertext = enc_dec_pgp.encrypt(file_data_padded[0])

eiv, ciphertext = ciphertext[:18], ciphertext[18:]

print(len(ciphertext))

plaintext = enc_dec_pgp.decrypt(ciphertext)

print(len(plaintext))

plaintext = Sandra.unpad(plaintext,Sandra.AES_BLOCK_SIZE)

print(len(plaintext))

print(plaintext == file_data[0])

Sandra.write_data(

    file_names, # name of the file to be written

    [plaintext], # data to be written, must be the same length as file_names

    path='./taylor_txt_ed' # path to write data to

)

```



## Performance

To obtain a table like this one, run 

```python

import Sandra

file_names, file_data = Sandra.load_data('path/to/data')

stats = Sandra.performance_test(

    file_names, 

    file_data, 

    rsa_key_size=256,

    rsa_engine=Sandra.RSA_ENGINE_RAW,

    segment_size=64,  

    verbose=True)



stats = Sandra.performance_test(

    file_names, 

    file_data, 

    rsa_key_size=256,

    rsa_engine=Sandra.RSA_ENGINE_RAW,

    segment_size=16,  

    verbose=True)

```

![image](https://user-images.githubusercontent.com/26662104/236880905-4862877c-1fec-4662-831a-a8cdd5781a2d.png)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lopgogo/Sandra",
    "name": "Sandra",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,encryption,decryption,cipher,cryptography",
    "author": "George Assaad",
    "author_email": "<lopgogo@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/c8/cb/6bd4fbebeefe44c15a1455b75182ae8dd88fe57ad06f1336a3b298fabb9c/Sandra-0.0.18.tar.gz",
    "platform": null,
    "description": "\n# Sandra\n\n![logo](https://user-images.githubusercontent.com/26662104/234409378-4602ff85-8fb1-425d-9213-979876c78dcc.png)\n\n\n\n**Sandra implements CFB and  [OpenPGP-CFB](https://datatracker.ietf.org/doc/html/rfc4880) built on top of pycryptodome.**\n\n\n\n## Usage\n\n### Loading Data\n\n```python\n\nSandra.load_data(\n\n    path # str -> path to data to be loaded\n\n)\n\n```\n\n### Writing Data\n\n ```python\n\nSandra.write_data(\n\n    file_names, # name of files to be written\n\n    file_data, # data to be written, must be the same length as file_names\n\n    path='.' # path to write data to\n\n)\n\n```\n\n\n\n## Examples\n\n### RSA File Encryption \n\n```python\n\nimport Sandra\n\nfile_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt') \n\nenc_dec_rsa = Sandra.RSA(2048, Sandra.RSA_ENGINE_DOME)\n\nciphertext = enc_dec_rsa.encrypt(file_data[0])\n\nprint(len(ciphertext))\n\nplaintext = enc_dec_rsa.decrypt(ciphertext)\n\nprint(plaintext == file_data[0])\n\nSandra.write_data(\n\n    file_names, # name of the file to be written\n\n    [plaintext], # data to be written, must be the same length as file_names\n\n    path='./taylor_txt_ed' # path to write data to\n\n)\n\n```\n\n\n\n### AES CFB Mode Sample(NIST) Encryption\n\n```python\n\nimport Sandra\n\n#Test Case from http://csrc.nist.gov/groups/STM/cavp/block-ciphers.html#aes\n\ndata = bytes.fromhex('fffffe00000000000000000000000000')\n\niv   = bytes.fromhex('fffffe00000000000000000000000000')\n\nkey  = bytes.fromhex('00000000000000000000000000000000')\n\n\n\nenc_dec_sandra = Sandra.AES(key, Sandra.MODE_CFB, iv, segment_size=16)\n\nciphertext = enc_dec_sandra.encrypt(data)\n\nplaintext = enc_dec_sandra.decrypt(ciphertext)\n\n```\n\n\n\n### AES CFB Mode File Encryption\n\n```python\n\nimport Sandra\n\niv   = bytes.fromhex('fffffe00000000000000000000000000')\n\nkey  = bytes.fromhex('00000000000000000000000000000000')\n\nfile_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt') \n\nenc_dec_cfb = Sandra.AES(key, Sandra.MODE_CFB, iv, segment_size=16)\n\nciphertext = enc_dec_cfb.encrypt(file_data[0])\n\nprint(len(ciphertext))\n\nplaintext = enc_dec_cfb.decrypt(ciphertext)\n\nprint(plaintext == file_data[0])\n\nSandra.write_data(\n\n    file_names, # name of the file to be written\n\n    [plaintext], # data to be written, must be same length as file_names\n\n    path='./taylor_txt_ed' # path to write data to\n\n)\n\n```\n\n\n\n### AES OpenPGP-CFB Mode File Encryption\n\n> In This mode, the first 18 bytes of cipher text contain the encrypted IV\n\n> Padding here is unnecessary as this mode is a stream cipher\n\n```python\n\nimport Sandra\n\niv   = bytes.fromhex('fffffe00000000000000000000000000')\n\nkey  = bytes.fromhex('00000000000000000000000000000000')\n\nfile_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt')\n\nprint(len(file_data[0]))\n\nfile_data_padded = Sandra.pad(file_data, Sandra.AES_BLOCK_SIZE) \n\nprint(len(file_data_padded[0]))\n\nenc_dec_pgp = Sandra.AES(key, Sandra.MODE_OPENPGP, iv)\n\nciphertext = enc_dec_pgp.encrypt(file_data_padded[0])\n\neiv, ciphertext = ciphertext[:18], ciphertext[18:]\n\nprint(len(ciphertext))\n\nplaintext = enc_dec_pgp.decrypt(ciphertext)\n\nprint(len(plaintext))\n\nplaintext = Sandra.unpad(plaintext,Sandra.AES_BLOCK_SIZE)\n\nprint(len(plaintext))\n\nprint(plaintext == file_data[0])\n\nSandra.write_data(\n\n    file_names, # name of the file to be written\n\n    [plaintext], # data to be written, must be the same length as file_names\n\n    path='./taylor_txt_ed' # path to write data to\n\n)\n\n```\n\n\n\n## Performance\n\nTo obtain a table like this one, run \n\n```python\n\nimport Sandra\n\nfile_names, file_data = Sandra.load_data('path/to/data')\n\nstats = Sandra.performance_test(\n\n    file_names, \n\n    file_data, \n\n    rsa_key_size=256,\n\n    rsa_engine=Sandra.RSA_ENGINE_RAW,\n\n    segment_size=64,  \n\n    verbose=True)\n\n\n\nstats = Sandra.performance_test(\n\n    file_names, \n\n    file_data, \n\n    rsa_key_size=256,\n\n    rsa_engine=Sandra.RSA_ENGINE_RAW,\n\n    segment_size=16,  \n\n    verbose=True)\n\n```\n\n![image](https://user-images.githubusercontent.com/26662104/236880905-4862877c-1fec-4662-831a-a8cdd5781a2d.png)\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "AES Stream Cipher with CFB and OpenPGP Modes",
    "version": "0.0.18",
    "project_urls": {
        "Homepage": "https://github.com/lopgogo/Sandra"
    },
    "split_keywords": [
        "python",
        "encryption",
        "decryption",
        "cipher",
        "cryptography"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "531abe3eb4e4de3b84abb88394123dfef05df8ddb54f3a33d09ac62cfa47f292",
                "md5": "e34918ec774d6f74ae8a51b7643cc520",
                "sha256": "6d7eeb8f9d5abf1a8fe6b50de236f6eca0376850ffdd0e980dc73219b6860576"
            },
            "downloads": -1,
            "filename": "Sandra-0.0.18-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e34918ec774d6f74ae8a51b7643cc520",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8088,
            "upload_time": "2023-05-08T18:46:51",
            "upload_time_iso_8601": "2023-05-08T18:46:51.036148Z",
            "url": "https://files.pythonhosted.org/packages/53/1a/be3eb4e4de3b84abb88394123dfef05df8ddb54f3a33d09ac62cfa47f292/Sandra-0.0.18-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8cb6bd4fbebeefe44c15a1455b75182ae8dd88fe57ad06f1336a3b298fabb9c",
                "md5": "8d938c7ef06e67145e20774c643ebe4c",
                "sha256": "17ef99ad9c0b3fb23e90ae5a1d2dbf901b48967418d11ca7db0202b1b41e6921"
            },
            "downloads": -1,
            "filename": "Sandra-0.0.18.tar.gz",
            "has_sig": false,
            "md5_digest": "8d938c7ef06e67145e20774c643ebe4c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8396,
            "upload_time": "2023-05-08T18:46:56",
            "upload_time_iso_8601": "2023-05-08T18:46:56.788706Z",
            "url": "https://files.pythonhosted.org/packages/c8/cb/6bd4fbebeefe44c15a1455b75182ae8dd88fe57ad06f1336a3b298fabb9c/Sandra-0.0.18.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-08 18:46:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lopgogo",
    "github_project": "Sandra",
    "github_not_found": true,
    "lcname": "sandra"
}
        
Elapsed time: 0.13559s