Python3 decode bytes [closed] - python-3.x

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Trying to decode bytes
2k2P3PKIfViQ1L6TTc7kYks6bpeat6pPH9qRrNcj1S2195TYz\x88}\x88\x88JKgqzeXz96zKrTX05D9bkJf1yCf
Is there a way to convert \x88 to letter or hide it.
trying this
s = b'2k2P3PKIfViQ1L6TTc7kYks6bpeat6pPH9qRrNcj1S2195TYz\x88}\x88\x88JKgqzeXz96zKrTX05D9bkJf1yCf'
d = s.decode('utf-8')
but got error
*** UnicodeDecodeError: 'utf-8' codec can't decode byte 0x88 in position 64: invalid start byte
Any Help?? Thanks in advance...

Why do you think it's UTF-8? UTF-8 is a specific, self-checking encoding, you can't just decode random bytes with it. If you just want to convert every byte to the equivalent Unicode ordinal, decode with latin-1. Decoding with cp1252 will even make a useful printable character. Or choose any other one byte per character ASCII encoding and see what it looks like. With no idea what it's supposed to mean, any 1-1 bytes to text encoding works, it's the logic of your program that determines if it's correct.

Related

Does the initalization vector need to be kept, to decrypt data? [duplicate]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm working on text encryption using AES. I'm saving the key and encrypted text in files, but what should i do with IV?
The IV is usually stored with the ciphertext. Prefixing the IV is commonplace as you need the IV at the start when performing decryption. As the IV is usually one block in size, you do not have to store the size of the IV if you know the block cipher used. Beware that AES-GCM, a popular authenticated mode of encryption, is most effective with a 12 byte IV.
Note that the IV is binary and often consist of randomized bytes. Neither the IV nor the ciphertext are likely to consist of valid characters. You need a encoding format such as base 64 or - less commonly - hexadecimals if you need to store the IV and ciphertext as text.
Yes, you must provide the same IV for encryption and decryption.

How To Crash UTF-8 Encode [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am looking for a string that will crash python3 when encoding it to UTF8.
s=?
s.encode("UTF-8") -> results in error
Thank you for your help
The UTF-8 encoder does not allow Unicode strings to use the the UTF-16 "surrogate" code points from U+D800 to U+DFFF:
>>> s = '\ud800'
>>> s.encode('UTF-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'utf-8' codec can't encode character '\ud800' in position 0: surrogates not allowed

python code to generate a Nigerian plate number [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I need a code designed with python to generate vehicle plate numbers
for platecode in range(100):
print('KJA'+'platecode'+'AA')
expected result is = KJA001AA till 100
The problem with your code is that you're not using the platecode variable, you're just putting it in as a string. 'platecode' (string) =/= platecode (variable). And as a comment stated, you want to zero-pad it. To do so use the format method:
for platecode in range(100):
print("KJA{0:03d}AA".format(platecode))
(Note that we use the platecode variable, not a string 'platecode'.)
To explain what the format method is doing: When format is called, it replaces braced sections ("{0:03d}") with the arguments to format (in this case, platecode). The first 0 says to access the argument at index 0; the colon indicates the beginning of the format specifier. The second zero says to zero-pad the number; the 3 says to use a minimum of 3 digits; and the d indicates to print in base 10, decimal.

How can search for no numerical/alphabetic characters in my file [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a text file that contains lots of data arranges as String separated by lines. I am facing an error in another program that uses this file. It seems there is a non alphabetical/numerical character. How can I search for it? How can I remove it if found ?
EDIT: including spaces (i.e, the line is white space).
Try this command:
cat bigfile.txt| od -cx | less
Unprintable characters will show up as "\xxx". Printable characters will be displayed as ASCII text. All characters - printable or not - will be displayed as hex, and you can see the offsets in the file.
Once you know 1) what the offending characters are, or 2) where they're located, you can develop a strategy for eliminating them. Perhaps all you need is a simple "sed" script.
PS:
"vi -b" would probably also work, even for what might seem gargantuan files. IMHO...

Converting ASCII text to Unicode with formatting [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Is there a free tool under linux system, for converting ascii text to unicode by keeping original text formatting ?
iconv can convert between different encodings, if that's what you mean.
Sure, it's called cat:
cat myasciifile > myunicodefile
Now myunicodefile consists of unicode codepoints, encoded in the popular UTF8 encoding. Note that this assumes that myasciifile consists only of legal ASCII characters (i.e. in the range 0-127).
An alternative to this is cp.

Resources