Python Forum
Simple text to binary python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple text to binary python script
#1
Hi all,

super new to python and working on a text to binary convertor using a dictionary, and wanting to understand how I get back to text after I have the binary output.

I currently have this;
def to_text_code(text):
    code = {'a':'01100001','b':'01100010','c':'01100011}

    text_code = ""

    for x in text:
        text_code += code[x.lower()]
    return text_code

text = input("Text to Binary Converter: ")
print(to_text_code(text))
It seems to work for the letters that I have placed in my dictionary and I can have multiple entries. However, when reversing the dictionary to go from binary back to text I'm having lots of issues.

Any help would be great,

thanks,

G
Reply


Messages In This Thread
Simple text to binary python script - by gmills13 - Feb-04-2020, 02:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Script that alternates between 2 text messages DiscoMatic 1 1,392 Dec-12-2023, 03:02 PM
Last Post: buran
  Python Code for Preorder Traversal of a Binary Tree Bolt 1 2,152 Sep-22-2023, 09:32 AM
Last Post: Gribouillis
  Python script that deletes symbols in plain text nzcan 3 1,856 Sep-05-2023, 04:03 PM
Last Post: deanhystad
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 8,531 Jun-29-2023, 11:57 AM
Last Post: gologica
  How do I read and write a binary file in Python? blackears 6 27,144 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Simple Python script, path not defined dubinaone 3 4,016 Nov-06-2021, 07:36 PM
Last Post: snippsat
  How to convert binary data into text? ZYSIA 3 3,807 Jul-16-2021, 04:18 PM
Last Post: deanhystad
  How to assigned value to each different binary in python... ZYSIA 2 3,044 Jul-12-2021, 11:01 AM
Last Post: Gribouillis
  Web Form to Python Script to Text File to zip file to web wfsteadman 1 3,039 Aug-09-2020, 02:12 PM
Last Post: snippsat
  How to convert a python code to binary? rsurathu 0 2,422 Aug-02-2020, 08:09 AM
Last Post: rsurathu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020