This simple Python program encodes and decodes strings into binary representation and back. It takes a string as input, converts each character into its binary equivalent, and allows you to decode a list of binary values back into a string.
- Encoding: Converts each character of a string into its binary representation (Unicode code point).
- Decoding: Converts a list of binary strings back into the original string.
-
Encoding:
- The program takes a string input from the user.
- It converts each character into its Unicode code point (integer) and then into a binary string.
- The binary representation is printed as a list of binary values.
-
Decoding:
- The program prompts the user to enter a space-separated list of binary values.
- It then converts each binary value back into the corresponding character and prints the decoded string.
Enter Name: Alice Encoded (binary representation): ['1000001', '1101100', '1100101', '1100010', '1100100']
Enter the space-separated list of binary values: 1000001 1101100 1100101 1100010 1100100 Decoded (characters): ['A', 'l', 'i', 'c', 'e']
- Input: A string (e.g.,
"Alice"
). - Process: Each character is converted to its Unicode code point using
ord()
and then to a binary string usingbin()
. - Output: A list of binary strings representing the encoded characters.
- Input: A list of binary values (space-separated).
- Process: Each binary string is converted back into its integer value using
int(binary_value, 2)
and then back to a character usingchr()
. - Output: A list of characters decoded from the binary strings.
This program only requires Python 3.x. No external libraries are needed.
- Clone this repository or copy the code into a Python file (e.g.,
encoder_decoder.py
). - Run the program using Python:
python encoder_decoder.py