diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2011-02-01 17:33:50 +0000 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2011-02-01 17:33:50 +0000 |
| commit | aa1b4e5f72fd6c73c4a1bce3de01d23e98f0e257 (patch) | |
| tree | cdcda60503898319710e5140f55990afaab64fbb /passlib/utils | |
| parent | 36d54e254dd5f296be78e0958a4dbd3a04ee1e0b (diff) | |
| download | passlib-aa1b4e5f72fd6c73c4a1bce3de01d23e98f0e257.tar.gz | |
added phpass portable hash
Diffstat (limited to 'passlib/utils')
| -rw-r--r-- | passlib/utils/h64.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/passlib/utils/h64.py b/passlib/utils/h64.py index 4d472c2..78ac13c 100644 --- a/passlib/utils/h64.py +++ b/passlib/utils/h64.py @@ -70,6 +70,24 @@ def encode_1_offset(buffer, o1): v1 = ord(buffer[o1]) return encode_6bit(v1&0x3F) + encode_6bit(v1>>6) +def encode_bytes(source): + "encode byte string to h64 format" + #FIXME: do something much more efficient here. + out = '' + end = len(source) + idx = 0 + while idx <= end-3: + out += encode_3_offsets(source, idx, idx+1, idx+2) + idx += 3 + if end % 3 == 1: + out += encode_1_offset(source, idx) + idx += 1 + elif end % 3 == 2: + out += encode_2_offset(source, idx, idx+1) + idx += 2 + assert idx == end + return out + #================================================================================= # int <-> b64 string, used by des_crypt, ext_des_crypt #================================================================================= |
