sha1prng


Namesha1prng JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummarySHA1PRNG在Python中的实现,与JAVA SecureRandom的生成结果保持一致。
upload_time2024-11-23 03:31:01
maintainerrRR0VrFP
docs_urlNone
authorrRR0VrFP
requires_pythonNone
licenseApache License, Version 2.0
keywords sha1prng hashprng
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sha1prng

SHA1PRNG在Python中的实现,与JAVA SecureRandom的生成结果保持一致。

## 安装

```shell
pip install sha1prng
```

## 使用

### Python测试代码

```python

import binascii
from sha1prng import SHA1PRNG

gen = SHA1PRNG(b"pwd")
for i in range(50):
    value = gen.randbytes(7)
    print(binascii.hexlify(value).decode())

```

### 测试代码输出结果

```txt
975b2cd4ff9ae554fe8a
d33168fbfc326d2021dd
25ad76226e84fecd44ec
8410ccdf0fc320aebe0a
9bdb251d6a1eaf62cba0
7bd707b603c87ed78d4b
7b41230345bea763d765
6eb65c474080455599a6
c6a0429b6ed9b927b50f
c39d476505ebe8e7ce16
fbe50b6a550322e4bca1
4dcb5109c0de5ca9e704
cbe78b1046c7352b169e
0185612ee00213a5333f
2b2ee782aa509f79fe9b
3f92911bdcf250d0129d
3960fbfc52281f5af14b
2b0b1c824db557898125
80c5e8d9a380a7369dd0
a85227a13e5aa84afb0c
ac0ea6a2aa933770b673
51d3f6bb454ef7806f46
60f98768834d1205696e
75f491485a56913bf415
20540ae17f66468d9f2e
38566dfc7e00e5a0be8d
51842708ba24c2092d66
4e8d71a7fa9ab473a854
88baf9a1b71f4726c7e2
e9082e6b5930d35744fb
0bba14eafa4aa2589a07
f2909e7b76d528409032
c6d6c4aa0d5e30ac0d33
d8950862edfa5b3347f7
79529e2098be91e7b9b2
04b0bbbfc7b092639144
d678d6af3188aecef436
654f9b2c1ab9896c340d
cc19e1564a68e484c2f5
34af1ed78b1c14010826
a174149923dfdfde8022
383d6dfd8ae931debc53
7883c16442772744885a
1252262cd4a61f87eb3d
c627078df3e7def3d809
24e1688e47e50c7a687d
c1af8efcaf3b6bfeb953
14d1bfadafd92786922b
582d90f5703f73cfabc3
d952c02e90c0729ae495
```

## 保持输出序列一致时的JAVA代码

```java
import java.security.*; 
import java.util.*; 

class Main {
    public static void main(String[] args) {
        try {
            byte[] output = new byte[10];
            // 初始种子0x70 0x77 0x64即为b"pwd"
            byte[] pwd = new byte[] { (byte)0x70, (byte)0x77, (byte)0x64 };
            SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
            random.setSeed(pwd);
            for(int i=0; i<50; i++){
                random.nextBytes(output);
                System.out.println(HexFormat.of().formatHex(output));
            }
        } catch (NoSuchAlgorithmException e){
        }
    }
}
```

## 版本记录

### 0.1.0

- 版本首发。

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sha1prng",
    "maintainer": "rRR0VrFP",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "sha1prng, hashprng",
    "author": "rRR0VrFP",
    "author_email": null,
    "download_url": null,
    "platform": null,
    "description": "# sha1prng\n\nSHA1PRNG\u5728Python\u4e2d\u7684\u5b9e\u73b0\uff0c\u4e0eJAVA SecureRandom\u7684\u751f\u6210\u7ed3\u679c\u4fdd\u6301\u4e00\u81f4\u3002\n\n## \u5b89\u88c5\n\n```shell\npip install sha1prng\n```\n\n## \u4f7f\u7528\n\n### Python\u6d4b\u8bd5\u4ee3\u7801\n\n```python\n\nimport binascii\nfrom sha1prng import SHA1PRNG\n\ngen = SHA1PRNG(b\"pwd\")\nfor i in range(50):\n    value = gen.randbytes(7)\n    print(binascii.hexlify(value).decode())\n\n```\n\n### \u6d4b\u8bd5\u4ee3\u7801\u8f93\u51fa\u7ed3\u679c\n\n```txt\n975b2cd4ff9ae554fe8a\nd33168fbfc326d2021dd\n25ad76226e84fecd44ec\n8410ccdf0fc320aebe0a\n9bdb251d6a1eaf62cba0\n7bd707b603c87ed78d4b\n7b41230345bea763d765\n6eb65c474080455599a6\nc6a0429b6ed9b927b50f\nc39d476505ebe8e7ce16\nfbe50b6a550322e4bca1\n4dcb5109c0de5ca9e704\ncbe78b1046c7352b169e\n0185612ee00213a5333f\n2b2ee782aa509f79fe9b\n3f92911bdcf250d0129d\n3960fbfc52281f5af14b\n2b0b1c824db557898125\n80c5e8d9a380a7369dd0\na85227a13e5aa84afb0c\nac0ea6a2aa933770b673\n51d3f6bb454ef7806f46\n60f98768834d1205696e\n75f491485a56913bf415\n20540ae17f66468d9f2e\n38566dfc7e00e5a0be8d\n51842708ba24c2092d66\n4e8d71a7fa9ab473a854\n88baf9a1b71f4726c7e2\ne9082e6b5930d35744fb\n0bba14eafa4aa2589a07\nf2909e7b76d528409032\nc6d6c4aa0d5e30ac0d33\nd8950862edfa5b3347f7\n79529e2098be91e7b9b2\n04b0bbbfc7b092639144\nd678d6af3188aecef436\n654f9b2c1ab9896c340d\ncc19e1564a68e484c2f5\n34af1ed78b1c14010826\na174149923dfdfde8022\n383d6dfd8ae931debc53\n7883c16442772744885a\n1252262cd4a61f87eb3d\nc627078df3e7def3d809\n24e1688e47e50c7a687d\nc1af8efcaf3b6bfeb953\n14d1bfadafd92786922b\n582d90f5703f73cfabc3\nd952c02e90c0729ae495\n```\n\n## \u4fdd\u6301\u8f93\u51fa\u5e8f\u5217\u4e00\u81f4\u65f6\u7684JAVA\u4ee3\u7801\n\n```java\nimport java.security.*; \nimport java.util.*; \n\nclass Main {\n    public static void main(String[] args) {\n        try {\n            byte[] output = new byte[10];\n            // \u521d\u59cb\u79cd\u5b500x70 0x77 0x64\u5373\u4e3ab\"pwd\"\n            byte[] pwd = new byte[] { (byte)0x70, (byte)0x77, (byte)0x64 };\n            SecureRandom random = SecureRandom.getInstance(\"SHA1PRNG\");\n            random.setSeed(pwd);\n            for(int i=0; i<50; i++){\n                random.nextBytes(output);\n                System.out.println(HexFormat.of().formatHex(output));\n            }\n        } catch (NoSuchAlgorithmException e){\n        }\n    }\n}\n```\n\n## \u7248\u672c\u8bb0\u5f55\n\n### 0.1.0\n\n- \u7248\u672c\u9996\u53d1\u3002\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "SHA1PRNG\u5728Python\u4e2d\u7684\u5b9e\u73b0\uff0c\u4e0eJAVA SecureRandom\u7684\u751f\u6210\u7ed3\u679c\u4fdd\u6301\u4e00\u81f4\u3002",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [
        "sha1prng",
        " hashprng"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1bd030184d622e140a37d9319c9f7d17a8dc73a1d0164543b802858c4b8cdb0b",
                "md5": "6bd1b062db61b78735e9207e4c117207",
                "sha256": "de2e5f352a4c863d8b3035455e343108b19f90aba27d2ab130b2d7916b1beb80"
            },
            "downloads": -1,
            "filename": "sha1prng-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6bd1b062db61b78735e9207e4c117207",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8926,
            "upload_time": "2024-11-23T03:31:01",
            "upload_time_iso_8601": "2024-11-23T03:31:01.349098Z",
            "url": "https://files.pythonhosted.org/packages/1b/d0/30184d622e140a37d9319c9f7d17a8dc73a1d0164543b802858c4b8cdb0b/sha1prng-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-23 03:31:01",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "sha1prng"
}
        
Elapsed time: 0.74265s