Stegano/tools.py
2010-10-02 02:35:17 +02:00

17 lines
No EOL
394 B
Python

#! /usr/local/bin/python
# -*- coding: utf-8 -*-
def a2bits(chars):
"""
Convert a string to its bits representation as a string of 0's and 1's.
"""
return bin(reduce(lambda x, y : (x<<8)+y, (ord(c) for c in chars), 1))[3:]
def bs(s):
"""
Convert a int to its bits representation as a string of 0's and 1's.
"""
return str(s) if s<=1 else bs(s>>1) + str(s&1)