File size: 343 Bytes
fb28dd9
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
def binary_to_text(binary_data):
    # Converts binary (e.g., 0s and 1s) into ASCII text
    try:
        n = int(binary_data, 2)
        return n.to_bytes((n.bit_length() + 7) // 8, 'big').decode()
    except Exception:
        return "Invalid binary input"

def text_to_binary(text):
    return ' '.join(format(ord(c), '08b') for c in text)