in order to print the ASCII I need to reverse the string so that what I've done and then to take for example 41 11 etc. and convert it to char. The outcome should be a word(in this case, Hacker)
The conversion need to be according to this: 1.the value range from A to Z is from 65 to 90 2.the value range from a to z is from 97 to 122 3.the value of the space character is 32
Do you have any idea how to do that?
Thank you in advance!
that's what I get currently: I get Unicode characters
['41', '11', '01', '10', '17', '99', '99', '27'] 41 11 01 10 17 99 99 27 ) cc
s="729799107101114"
rs=s[::-1]
import re
new=re.findall('..',rs)
print(new)
n=""
for num in new:
n =num " "
print(n)
j=''.join(chr(int(i)) for i in n.split())
print(j)
CodePudding user response:
The input presented numbers on ASCII
codes. i.e 72
is the H
char.
Then the outcome is look like this:
s="72 97 99 107 101 114"
j=''.join(chr(int(i)) for i in s.split())
print(j)
[Output]
Hacker
[EDIT]:
In this part, we'll tokenize the numbers as it, without space.
s="721111193211611132114101116117114110321161041013265836773733211511611410511010332971021161011143297321031051181011103211511611410511010332111102321101171099810111411563"
j=''
start=0
step=2
while start < len(s)-1:
n=s[start:start 2]
if 32<=int(n)<=99:
start =2
if int(n)<32:
n=s[start:start 3]
start =3
j=j (chr(int(n)))
print(j)
[Output2:] In this sequence numbers sample we'll get this sentence:
How to return the ASCII string after a given string of numbers?
CodePudding user response:
A slightly less verbose version:
res = ''
start = end = 0
while end < len(s):
end = start 2 (s[start] == '1')
res = chr(int(s[start:end]))
start = end