I have been working on a Python project where I am trying to use the original ASCII code, and incorporate it into a Cipher. But before that, I was wondering if there was a way to recursively convert an ascii to binary. Python 2.7.5 btw. Here's my code:
inputMessage= raw_input("Enter message for conversion: ")
print "Decoded string: "
#text to ascii
for ch in inputMessage:
print ord(ch)
print "\n\n"
#ascii to binary
print "ASCII to Binary:"
print bin(ord(ch))
print
print "The Binary without the '0b':"
for ch in inputMessage:
print bin(ord(ch))[2::]
my output in the shell:
Enter message for conversion: Hi, my name is Johnny
Decoded string:
72
105
44
32
109
121
32
110
97
109
101
32
105
115
32
74
111
104
110
110
121
ASCII to Binary:
0b1001000
0b1101001
0b101100
0b100000
0b1101101
0b1111001
0b100000
0b1101110
0b1100001
0b1101101
0b1100101
0b100000
0b1101001
0b1110011
0b100000
0b1001010
0b1101111
0b1101000
0b1101110
0b1101110
0b1111001
what I need to find out is how can I recursively run through each number of the ascii output of number when converting to binary. Anyone have a solution?