rawbytestring

Split a string and keep the delimiters as part of the split string chunks, not as separate list elements

夙愿已清 提交于 2020-06-28 09:21:22
问题 This is a spin-off from In Python, how do I split a string and keep the separators? rawByteString = b'\\!\x00\x00\x00\x00\x00\x00\\!\x00\x00\x00\x00\x00\x00' How can I split this rawByteString into parts using "\\!" as the delimiter without dropping the delimiters, so that I get: [b'\\!\x00\x00\x00\x00\x00\x00', b'\\!\x00\x00\x00\x00\x00\x00'] I do not want to use [b'\\!' + x for x in rawByteString.split(b'\\!')][1:] as that would use string.split() and is just a workaround, that is why this

Convert raw byte string to Unicode without knowing the codepage beforehand

て烟熏妆下的殇ゞ 提交于 2019-12-20 04:18:16
问题 When using the right-click menu context, windows passes file path as raw (byte) string type. For example: path = 'C:\\MyDir\\\x99\x8c\x85\x8d.mp3' Many external packages in my application are expecting unicode type strings, so I have to convert it into unicode . That would be easy if we'd known the raw string's encoding beforehand (In the example, it is cp1255 ). However I can't know which encoding will be used locally on each computer around the world. How can I convert the string into

C/C++ Why to use unsigned char for binary data?

会有一股神秘感。 提交于 2019-12-17 17:29:36
问题 Is it really necessary to use unsigned char to hold binary data as in some libraries which work on character encoding or binary buffers? To make sense of my question, have a look at the code below - char c[5], d[5]; c[0] = 0xF0; c[1] = 0xA4; c[2] = 0xAD; c[3] = 0xA2; c[4] = '\0'; printf("%s\n", c); memcpy(d, c, 5); printf("%s\n", d); both the printf's output 𤭢 correctly, where f0 a4 ad a2 is the encoding for the Unicode code-point U+24B62 (𤭢) in hex. Even memcpy also correctly copied the bits

Delphi (FMX): DCPCrypt2 in Windows produces different result in Android/IOS

雨燕双飞 提交于 2019-12-08 02:34:14
问题 I am trying to write a function that returns the same result in Delphi (RAD Studio 10.2) as the following piece of code in PHP: <?php $method = 'AES-256-CTR'; $data = 'Hello, world!'; $key = 'bRuD5WYw5wd0rdHR9yLlM6wt2vteuini'; $vector = 'bf49ea9d61104d8c'; $crypt = openssl_encrypt($data, $method, $key, 0, $vector); echo $crypt; ?> I have come up with this function in Pascal (using the DCPcrypt v2.1 library written by David Barton): procedure TMainForm.Encrypt1ButtonClick(Sender: TObject); var

Delphi (FMX): DCPCrypt2 in Windows produces different result in Android/IOS

本小妞迷上赌 提交于 2019-12-06 12:06:59
I am trying to write a function that returns the same result in Delphi (RAD Studio 10.2) as the following piece of code in PHP: <?php $method = 'AES-256-CTR'; $data = 'Hello, world!'; $key = 'bRuD5WYw5wd0rdHR9yLlM6wt2vteuini'; $vector = 'bf49ea9d61104d8c'; $crypt = openssl_encrypt($data, $method, $key, 0, $vector); echo $crypt; ?> I have come up with this function in Pascal (using the DCPcrypt v2.1 library written by David Barton): procedure TMainForm.Encrypt1ButtonClick(Sender: TObject); var Cipher: TDCP_rijndael; Key, Vector: RawByteString; Data, Crypt: RawByteString; begin Data := 'Hello,

C/C++ Why to use unsigned char for binary data?

人走茶凉 提交于 2019-11-28 15:39:23
Is it really necessary to use unsigned char to hold binary data as in some libraries which work on character encoding or binary buffers? To make sense of my question, have a look at the code below - char c[5], d[5]; c[0] = 0xF0; c[1] = 0xA4; c[2] = 0xAD; c[3] = 0xA2; c[4] = '\0'; printf("%s\n", c); memcpy(d, c, 5); printf("%s\n", d); both the printf's output 𤭢 correctly, where f0 a4 ad a2 is the encoding for the Unicode code-point U+24B62 (𤭢) in hex. Even memcpy also correctly copied the bits held by a char. What reasoning could possibly advocate the use of unsigned char instead of a plain