吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1225|回复: 6
收起左侧

[求助] Python怎么把字符串转字节集

[复制链接]
雪辉 发表于 2021-5-20 16:23
本帖最后由 雪辉 于 2021-5-20 16:26 编辑

C#
byte[] temp = Encoding.UTF8.GetBytes(“我是中文”);
输出  230,136,145,230,152,175,228,184,173,230,150,135

Python
sj = "我是中文"
sj = sj.encode('utf8')

输出 b'\xe6\x88\x91\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87'




python怎么才能做到其他编程语言的转字节集呢

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 雪辉 发表于 2021-5-20 16:24
python怎么才能做到其他编程语言的转字节集呢?
qeq66 发表于 2021-5-20 16:29
 楼主| 雪辉 发表于 2021-5-20 16:49
qeq66 发表于 2021-5-20 16:55
雪辉 发表于 2021-5-20 16:49
我进去怎么提示404

[Python] 纯文本查看 复制代码
import base64

"""
Some useful functions for interacting with Java web services from Python.
"""

def make_file_java_byte_array_compatible(file_obj):
    """ 
    Reads in a file and converts it to a format accepted as Java byte array 
    :param file object
    :return string
    """
    encoded_data = base64.b64encode(file_obj.read())
    strg = ''
    for i in xrange((len(encoded_data)/40)+1):
        strg += encoded_data[i*40:(i+1)*40]
        
    return strg

def java_byte_array_to_binary(file_obj):
    """ 
    Converts a java byte array to a binary stream
    :param java byte array as string (pass in as a file like object, can use StringIO)
    :return binary string
    """
    decoded_data = base64.b64decode(file_obj.read())
    strg = ''
    for i in xrange((len(decoded_data)/40)+1):
        strg += decoded_data[i*40:(i+1)*40]
        
    return strg
咸鱼灭 发表于 2021-5-20 17:14
[Asm] 纯文本查看 复制代码
sj = "我是中文".encode()
print(list(sj))

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
ARtcgb + 1 + 1 谢谢@Thanks!

查看全部评分

cc78947 发表于 2021-5-21 15:47
Python
sj = "我是中文"
sj = sj.encode('utf8')
mum_lit = [ int(i) for i in sj]
print(mum_lit)
>>> [230, 136, 145, 230, 152, 175, 228, 184, 173, 230, 150, 135]
是这个意思吗,编码就是16进制的
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-17 02:34

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表