1
A
回答
3
我讀了ISAAC home page上的一些代碼示例,代碼看起來很簡單。如果您需要使用純Python,則可以使用其他語言中的幾個示例來指導您的移植工作。
從Python使用isaac()
的另一種方法是將C代碼構建爲共享庫並通過ctypes module, which is standard in 2.5+訪問它,但可以使用found on PyPI for earlier versions。這也應該比純Python中的直接端口更好。
下面是將C版本isaac()
作爲共享庫構建並通過ctypes使用它的示例。首先,你需要從作者的網站下載rand.c
,rand.h
,並且standard.h
,再建:
% gcc -shared -fPIC -o libisaac.so rand.c
這裏是Python代碼。請注意,RandCtx
中字段的大小取決於代碼是爲32位還是64位平臺構建的。我在64位Ubuntu上測試過。對於32位你需要改變所有的字段使用c_uint32
:
from ctypes import *
class RandCtx(Structure):
RANDSIZL = 8
RANDSIZ = 1 << RANDSIZL
_fields_ = [
('randcnt', c_uint64),
('randrsl', c_uint64 * RANDSIZ),
('randmem', c_uint64 * RANDSIZ),
('randa', c_uint64),
('randb', c_uint64),
('randc', c_uint64)
]
ctx = RandCtx()
lib = cdll.LoadLibrary('./libisaac.so')
lib.randinit(byref(ctx), 0)
lib.isaac(byref(ctx))
for i in xrange(4):
print ctx.randrsl[i]
輸出:
% python isaac.py
14
8193820543905647488
4194352129441799609
12121047914186473054
相關問題
- 1. ISAAC密碼在PHP中
- 2. python密碼加密?
- 3. Python Atbash密碼
- 4. Python醃密碼
- 5. Python:凱撒密碼加密
- 6. Python藍牙密碼/密碼Linux
- 7. Python 3密碼scrypt
- 8. python - 密碼過期
- 9. 密碼保護Python
- 10. 替代密碼Python
- 11. 凱撒密碼,Python
- 12. Python凱撒密碼
- 13. Python翻轉密碼
- 14. Python md5密碼值
- 15. Vigenere密碼Python bug
- 16. Python,替換密碼
- 17. 使用Python解密Windows無線密碼
- 18. 如何在Python pysftp中加密密碼?
- 19. Python + GPG(編輯密鑰更改密碼)
- 20. 使用python解密pdf密碼
- 21. Python 3密碼檢查
- 22. 阿諾德/書密碼python
- 23. python ssh密碼提示
- 24. Python的密碼破解
- 25. 用Python存儲密碼
- 26. 重置密碼python程序
- 27. 隨機替代密碼(Python)
- 28. 凱撒密碼在python
- 29. 單字節XOR密碼(python)
- 30. 的Python httplib.HTTPSConnection和密碼
它可以幫助你的問題鏈接或提供密碼的說明。 – Daenyth 2011-05-25 17:52:05