python将txt文件(ASCII码格式),转化为16进制文件

不多BB直接上代码

import time
print("begin")

#读取的txt文件
infile = open("god.txt","r");
#输出的cer文件,当然你想输出什么格式都可以
outfile = open("god.cer","wb");

#开始读文件
a = infile.read(1);
_combine = "";
i=0;
while a != '\n':
    if ' ' == a:
        a = infile.read(1);
        continue;
    else:
        _combine = _combine + a;
        i = i+1;
        if 2 == i :
            i = 0;
            #此处转化为16进制
            outfile.write(bytes.fromhex(_combine));
            _combine = "";
    a = infile.read(1);

infile.close();
outfile.close();


print("end")

python将txt转16进制,内附有将16进制文本以ASCII码格式存储的txt文件,如果你已经安装了python,可以直接在cmd中运行程序。
这个是py文件和txt文件的压缩包,需要可以下载

python 163.py

在这里插入图片描述
这样就成功了

到此,问题结束

如果没有安装python,点这里去python官网下载
这里我只说一下Windows安装
在这里插入图片描述

1.建议选择稳定版下载
在这里插入图片描述
2.下载完后安装

2.1最好勾选 add python 3.x to path在这里插入图片描述
2.2自己选择安装位置
在这里插入图片描述

3.打开cmd ,输入python
在这里插入图片描述

到此成功安装python

猜你喜欢

转载自blog.csdn.net/pz641/article/details/107088177
今日推荐