How do you go about converting something to ASCII using python? I have an example below of some randomly generated text that would need converted:
96,114,101,106, 60,
Shift: 27
I don't know where to begin with this....
9 21595
How do you go about converting something to ASCII using python? I have an example below of some randomly generated text that would need converted:
96,114,101,106, 60,
Shift: 27
I don't know where to begin with this....
Try the built in functions ord() and chr().
bvdet 2,851
Recognized Expert Moderator Specialist
How do you go about converting something to ASCII using python? I have an example below of some randomly generated text that would need converted:
96,114,101,106, 60,
Shift: 27
I don't know where to begin with this....
Use chr() to convert an integer in the range 0 to 255 to the equivalent ascii character. - >>> for item in [96,114,101,106,60,27]:
-
... print chr(item)
-
...
-
`
-
r
-
e
-
j
-
<
-
-
>>>
Use chr() to convert an integer in the range 0 to 255 to the equivalent ascii character. - >>> for item in [96,114,101,106,60,27]:
-
... print chr(item)
-
...
-
`
-
r
-
e
-
j
-
<
-
-
>>>
Is there a way to get the number value of a character?
Is there a way to get the number value of a character?
Yes, using the ord() function.
another way -
''.join([ "%c" % i for i in [96,114,41,42] ])
-
bartonc 6,596
Recognized Expert Expert
another way -
''.join([ "%c" % i for i in [96,114,41,42] ])
-
Or, slightly more efficient (no temporary lists) using a generator and a tuple: - ''.join("%c" % i for i in (96,114,41,42))
Thank you all for your replies, but what about something like this:
Generated String: 65$65$85$86$80$ 67$87$94$90$68$ 88$70$57$80$107 $
Shift: 20
I want to take that string and print out the decoded ascii, also using shifts. I
believe the shifts are from 0-30?? chr() and ord() don't seem to work with symbols in the string and the strings are randomly generated so they vary each time.
bvdet 2,851
Recognized Expert Moderator Specialist
Thank you all for your replies, but what about something like this:
Generated String: 65$65$85$86$80$ 67$87$94$90$68$ 88$70$57$80$107 $
Shift: 20
I want to take that string and print out the decoded ascii, also using shifts. I
believe the shifts are from 0-30?? chr() and ord() don't seem to work with symbols in the string and the strings are randomly generated so they vary each time.
- s = '65$65$85$86$80$67$87$94$90$68$88$70$57$80$107$'
-
-
print ''.join([chr(int(i)) for i in s.split('$') if i != ''])
>>> AAUVPCW^ZDXF9Pk
>>>
I do not understand what you want to do with the 'shift' number.
"This string was randomly generated. It will not be recognizable text. You have 3 seconds to take the information from the website, and apply that to your algorithm.
Generated String: 73"51"92"51"92" 81"66"87"71"48" 61"62"76"87"9 5"
Shift: 15" -
-
url = 'http://www.websitehere.php'
-
strSession = 'PHPSESSID=<cookiehere>'
-
dicHeaders = {'COOKIE': strSession}
-
req = urllib2.Request(url, None, dicHeaders)
-
f = urllib2.urlopen(req)
-
strContext = f.read()
-
I think the shift is either to subtract or add to the ordinals of the characters, if that makes any sense........ -
.join(chr(ord(c)15) for c in original_string)
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Peter Wilkinson |
last post by:
Hello tlistmembers,
I am using the encoding function to convert unicode to ascii. At one point
this code was working just fine, however, now it has broken.
I am reading a text file that has is in unicode (I am unsure of which
flavour or bit depth). as I read in the file one line at a time
(readlines()) it converts to ascii. Simple enough....
|
by: David Williams |
last post by:
Hi all, i have been able to convert an ASCII character to an INT however im
lost as to how to change them back. Cant find anything on the net (though im
probably looking in the wrong places!). Could anyone help me out?
Thanks
Dave
|
by: Prabhu |
last post by:
Hi,
We are having problem in converting a byte array to string, The byte array
has char(174), char(175), char(240), char(242) and char(247) as delimiters
for the message.
when we use "System.Text.Encoding.ASCII.GetString(bytearray)" of .Net
library, we found that the char (delimiters) specified above are replaced
with different char.
|
by: jj |
last post by:
It seems simple but I had a hard time converting this small function from
vb.net to C#. I even tried the
software that automatically converts from vb to c# , but to no avail.
Please can someone take some precious minutes to help me out.
Thanks
John
Public Function SimpleCrypt( ByVal Text As String) As String
Dim strTempChar As String, i...
|
by: scott |
last post by:
hi all, hope some one can help me, this prob is driving me mad.
im using sockets to communicate between a client and a server. I don't'
have control over the client and how it sends the data so i have had to try
and work out how it is doing it. From what i can see it is sending the data
in ASCII because if i try to use Unicode it just...
| |
by: Gidi |
last post by:
Hi,
I'm writing a C# win application program, and i need to transfer my hebrew
letters from unicode to ascii, now if i use the ascii encoding it writes me
??? instead of the hebrew letter i've entered. I know what the Ascii value of
each letter, so i understood that i can transfer my string to BYTE and enter
the ascii value by myself. if...
|
by: Mark Rae |
last post by:
Hi,
Can anyone please tell me how to convert an unserializeable object say, a
System.Web.Mail.MailMessage object, to a byte array and then convert the
byte array to a Base64 string?
Any assistance gratefully received.
Best regards,
|
by: David |
last post by:
I note that you can null teminate a string by adding controlchar.null.
Is there a way of adding a null to a Buffer of Bytes and converting it to a
string.
I have packets coming in from a serial ports as bytes and some of these
represent strings. (Like the Packed BCD date/time stamp etc).
At present I read through each Byte and convert...
|
by: davetelling |
last post by:
I am a total newbie, trying to slog through the Visual C# Express
application. I need to be able to convert a single ASCII character (can be
anything from 0 to 255) to an int for use in other places. So far, I cannot
find anything that works. My application gets a string of characters from an
external device via the serial port. I can use the...
|
by: Alci |
last post by:
I am getting some Korean characters data from MS SQL server. These
data were submitted as UTF-8 into the database, but stored as normal
varchars. So, when I getting them out of database by using Gridview
+SqlDataSource, they are actually ASCII format, but I couldn't just
convert the encoding of the page to get the proper UTF-8 format Korean...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |