01转二维码(不是二进制)

news/2024/11/15 0:46:24/文章来源:https://www.cnblogs.com/yanxiao777/p/18547209

例题ctfhub/隐写v2.0

image-20241115002433749

打开是一张图片

image-20241115002519329

文件分离得到zip,爆破密码得到7878

打开得到0和1,

!!!不是二进制转图片,直接是二维码

缩小能看到

image-20241115002644330

000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0011111111111110110000111110000001001111110000000110000011111111111100
0011111111111110110000111110000001001111110000000110000011111111111100
0011000000000110110000001111100110111111001111111001110011000000000100
0011000000000110110000001111100110111111001111111001110011000000000100
0011001111100110111111110001100111000011110111100111110011011111100100
0011001111100110001111001000011111001111111000011111110011011111100100
0011001111100110001111001000011111001111111000011111110011011111100100
0011001111100110000011000000011001110011000111111000000011011111100100
0011001111100110000011000000011001110011000111111000000011011111100100
0011000000000110110000000110011111000011110001111111110011000000000100
0011000000000110110000000110011111000011110001111111110011000000000100
0011111111111110110011001001100110110011001001100110110011111111111100
0011111111111110110011001001100110110011001001100110110011111111111100
0000000000000000111100000110000110111100000111111000000000000000000000
0000001111100110110000001110000111110011111000000111111111100001111100
0000001111100110110000001110000111110011111000000111111111100001111100
0000110111100001110011110000000000000011000110000001001100111110011000
0000110111100001110011110000000000000011000110000001001100111110011000
0011000000000110000011111110011000110000001000011111111111100111100100
0011000000000110000011111110011000110000001000011111111111100111100100
0000000001111001000011110110011111000000001001100001001100100000000000
0000000001111001000011110110011111000000001001100001001100100000000000
0000001110011110000011110111100000110000000110011001111111111001100100
0000000001111001000011110000011000001111000000011110001100000000011000
0000000001111001000011110000011000001111000000011110001100000000011000
0011111110011110111111001001100111111111001111100001110011011111100100
0011111110011110111111001001100111111111001111100001110011011111100100
0011001000011000001100000001111111111111110001100001111111100000000100
0011001000011000001100000001111111111111110001100001111111100000000100
0011001001100111111100111110011111001100000111111111110011011111100100
0011001001100111111100111110011111001100000111111111110011011111100100
0000110110011001111111000111100001110011001001100000001100100110000000
0011001110000111110011001111100000000011110000000111111111011111111100
0011001110000111110011001111100000000011110000000111111111011111111100
0011000001100000111100000001111000111100110110000000000000100110011000
0011000001100000111100000001111000111100110110000000000000100110011000
0000001000011110111100000111111000110000000000011111110011011001111000
0000001000011110111100000111111000110000000000011111110011011001111000
0000111111111001000000111110011111001111110001100000001100100111111100
0000111111111001000000111110011111001111110001100000001100100111111100
0000111001111110110000111110000001000011000111100001111111100000011100
0011001111111001000011000001111000111111000111100111000011000000011000
0011001111111001000011000001111000111111000111100111000011000000011000
0000110000000110001100110000011110001111111000000001000011000111100000
0000110000000110001100110000011110001111111000000001000011000111100000
0011000001100001110011001110011000001100111001100111110011000110000000
0011000001100001110011001110011000001100111001100111110011000110000000
0011001000000111000011001110011110110011110000000110000000000001111100
0011001000000111000011001110011110110011110000000110000000000001111100
0011001111111001111100111111100111001111001001100110111100000110011100
0011001000011111110011110111111001001111001000011110111111111000000100
0011001000011111110011110111111001001111001000011110111111111000000100
0000000000000000111111110000000111110011110001100001110000011001111000
0000000000000000111111110000000111110011110001100001110000011001111000
0011111111111110000011001000011000001111000001111000110011011110000100
0011111111111110000011001000011000001111000001111000110011011110000100
0011000000000110000011110000000110111111111001100000110000011000000000
0011001111100110111111110001100001111111001001111111111111111111100100
0011001111100110111111110001100001111111001001111111111111111111100100
0011001111100110110011001001111110110011001000000001001111011000011100
0011001111100110110011001001111110110011001000000001001111011000011100
0011001111100110110000000110011001000011001111100001110000100000000100
0011001111100110110000000110011001000011001111100001110000100000000100
0011000000000110001111001111100110110011111110000111110011100000000100
0011000000000110001111001111100110110011111110000111110011100000000100
0011111111111110001111110110000000000011001110000000001100000111111100
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000

exp1:0为黑色像素,1为白色像素,70行,70列

image-20241115002954179

image-20241115003008761

from PIL import Image# 二进制字符串
binary_nums = """0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0011111111111110110000111110000001001111110000000110000011111111111100
0011111111111110110000111110000001001111110000000110000011111111111100
0011000000000110110000001111100110111111001111111001110011000000000100
0011000000000110110000001111100110111111001111111001110011000000000100
0011001111100110111111110001100111000011110111100111110011011111100100
0011001111100110001111001000011111001111111000011111110011011111100100
0011001111100110001111001000011111001111111000011111110011011111100100
0011001111100110000011000000011001110011000111111000000011011111100100
0011001111100110000011000000011001110011000111111000000011011111100100
0011000000000110110000000110011111000011110001111111110011000000000100
0011000000000110110000000110011111000011110001111111110011000000000100
0011111111111110110011001001100110110011001001100110110011111111111100
0011111111111110110011001001100110110011001001100110110011111111111100
0000000000000000111100000110000110111100000111111000000000000000000000
0000001111100110110000001110000111110011111000000111111111100001111100
0000001111100110110000001110000111110011111000000111111111100001111100
0000110111100001110011110000000000000011000110000001001100111110011000
0000110111100001110011110000000000000011000110000001001100111110011000
0011000000000110000011111110011000110000001000011111111111100111100100
0011000000000110000011111110011000110000001000011111111111100111100100
0000000001111001000011110110011111000000001001100001001100100000000000
0000000001111001000011110110011111000000001001100001001100100000000000
0000001110011110000011110111100000110000000110011001111111111001100100
0000000001111001000011110000011000001111000000011110001100000000011000
0000000001111001000011110000011000001111000000011110001100000000011000
0011111110011110111111001001100111111111001111100001110011011111100100
0011111110011110111111001001100111111111001111100001110011011111100100
0011001000011000001100000001111111111111110001100001111111100000000100
0011001000011000001100000001111111111111110001100001111111100000000100
0011001001100111111100111110011111001100000111111111110011011111100100
0011001001100111111100111110011111001100000111111111110011011111100100
0000110110011001111111000111100001110011001001100000001100100110000000
0011001110000111110011001111100000000011110000000111111111011111111100
0011001110000111110011001111100000000011110000000111111111011111111100
0011000001100000111100000001111000111100110110000000000000100110011000
0011000001100000111100000001111000111100110110000000000000100110011000
0000001000011110111100000111111000110000000000011111110011011001111000
0000001000011110111100000111111000110000000000011111110011011001111000
0000111111111001000000111110011111001111110001100000001100100111111100
0000111111111001000000111110011111001111110001100000001100100111111100
0000111001111110110000111110000001000011000111100001111111100000011100
0011001111111001000011000001111000111111000111100111000011000000011000
0011001111111001000011000001111000111111000111100111000011000000011000
0000110000000110001100110000011110001111111000000001000011000111100000
0000110000000110001100110000011110001111111000000001000011000111100000
0011000001100001110011001110011000001100111001100111110011000110000000
0011000001100001110011001110011000001100111001100111110011000110000000
0011001000000111000011001110011110110011110000000110000000000001111100
0011001000000111000011001110011110110011110000000110000000000001111100
0011001111111001111100111111100111001111001001100110111100000110011100
0011001000011111110011110111111001001111001000011110111111111000000100
0011001000011111110011110111111001001111001000011110111111111000000100
0000000000000000111111110000000111110011110001100001110000011001111000
0000000000000000111111110000000111110011110001100001110000011001111000
0011111111111110000011001000011000001111000001111000110011011110000100
0011111111111110000011001000011000001111000001111000110011011110000100
0011000000000110000011110000000110111111111001100000110000011000000000
0011001111100110111111110001100001111111001001111111111111111111100100
0011001111100110111111110001100001111111001001111111111111111111100100
0011001111100110110011001001111110110011001000000001001111011000011100
0011001111100110110011001001111110110011001000000001001111011000011100
0011001111100110110000000110011001000011001111100001110000100000000100
0011001111100110110000000110011001000011001111100001110000100000000100
0011000000000110001111001111100110110011111110000111110011100000000100
0011000000000110001111001111100110110011111110000111110011100000000100
0011111111111110001111110110000000000011001110000000001100000111111100
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000""".replace('\n', '')# 图像尺寸
MAX = 70
pic = Image.new("RGB", (MAX, MAX))# 填充像素
i = 0
for y in range(MAX):for x in range(MAX):if binary_nums[i] == '0':pic.putpixel((x, y), (0, 0, 0))  # 黑色else:pic.putpixel((x, y), (255, 255, 255))  # 白色i += 1# 保存图像
pic.save("flag.png")

exp2:简化1

from PIL import Image# 从 flag.txt 文件中读取二进制字符串
with open('flag.txt', 'r') as file:binary_nums = file.read().strip().replace('\n', '')# 图像尺寸
MAX = 70
pic = Image.new("RGB", (MAX, MAX))# 填充像素
i = 0
for y in range(MAX):for x in range(MAX):if binary_nums[i] == '0':pic.putpixel((x, y), (0, 0, 0))  # 黑色else:pic.putpixel((x, y), (255, 255, 255))  # 白色i += 1# 保存图像
pic.save("flag.png")
print("图像已保存为 flag.png")

代码解释

1. PIL (Python Imaging Library)

PIL 是 Python Imaging Library 的缩写,是一个用于处理图像的库。它提供了许多图像处理功能,如读取、修改和保存各种图像格式。PIL 已经不再维护,但它的 fork 版本 Pillow 仍在积极开发和维护中。因此,通常我们会使用 Pillow 而不是原始的 PIL

2. Image

Image 类是 PIL 库中的一个核心类,用于表示和操作图像。你可以通过 Image 类创建新的图像、打开现有的图像文件、修改图像内容以及保存图像。

3. pic 变量

在你的代码中,pic 是一个 Image 对象,表示一个新创建的空白图像。具体来说:

pic = Image.new("RGB", (MAX, MAX))
  • "RGB":指定了图像的颜色模式。RGB 表示图像由红、绿、蓝三种颜色通道组成。
  • (MAX, MAX):指定了图像的尺寸,宽度和高度都是 MAX 像素。

@4. putpixel 方法

putpixelImage 类的一个方法,用于设置图像中某个特定像素的颜色。其语法如下:

image.putpixel((x, y), color)
  • (x, y):表示图像中的一个像素位置,xy 分别是水平和垂直坐标。
  • color:表示要设置的颜色。对于 RGB 图像,color 是一个包含三个整数的元组,分别表示红、绿、蓝三个颜色通道的值。例如,(0, 0, 0) 表示黑色,(255, 255, 255) 表示白色。
  • 越接近0解释越接近黑色,越接近255解释越接近白色。

代码示例中的 putpixel 使用

在你的代码中,putpixel 方法用于根据 binary_nums 字符串中的值设置图像的像素颜色:

i = 0
for y in range(MAX):for x in range(MAX):if binary_nums[i] == '0':pic.putpixel((x, y), (0, 0, 0))  # 黑色else:pic.putpixel((x, y), (255, 255, 255))  # 白色i += 1
  • i 是一个索引,用于遍历 binary_nums 字符串。
  • for y in range(MAX)for x in range(MAX) 是嵌套的循环,用于遍历图像的每一个像素位置 (x, y)
  • if binary_nums[i] == '0':如果当前字符是 0,则将该位置的像素设置为黑色 (0, 0, 0)
  • else:如果当前字符是 1,则将该位置的像素设置为白色 (255, 255, 255)
  • i += 1:每次处理完一个像素后,i 自增 1,以便处理下一个字符。

总结

  • PIL:Python Imaging Library,用于处理图像的库。
  • ImagePIL 中的核心类,用于表示和操作图像。
  • pic 变量:一个 Image 对象,表示一个新创建的空白图像。
  • putpixel 方法:用于设置图像中某个特定像素的颜色。

通过这些工具,你可以创建和操作图像,生成二维码图像并保存为文件。希望这些解释对你有帮助!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/833724.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

LIS系统与仪器进行通信-软件

上一篇文章介绍了LIS系统与仪器进行通信的方式和协议。这篇文章主要介绍一下按照通信方式和协议开发的一个通信软件。 这个软件在LIS信息传输中充当一个中间者的角色,只负责在仪器和三方系统中传递消息。仪器、通信软件、三方系统三者之间的通信流程如下图:登录界面首页首页可…

iman——冲刺日志(第三天)

阉割版 团队成员分工与进度 📝👥组别 成员 完成的任务 完成任务所用时间 (小时) 剩余时间 (小时)前端 阿依娜孜 完成总览页面行程概览与高德地图接入,实现动态地图显示效果。 2 2前端 郭剑敏 优化并完善路线编辑功能的前端代码。 2 1前端 王梓铭 优化主页和导航栏布局,提…

雷电9安卓模拟器安装Xposed环境

参考:抹机王-雷电9-EdXposed框架安装 资源包:点击下载 备用链接 部署雷电9 开启雷电9的root权限修改模拟器磁盘共享方式为System.vmdk可写入安装Magisk 从资源包安装Magisk Delta.apk打开Magisk Delta,在 Magisk 那一栏点击安装下一步安装至系统分区注意:如果在该步骤没有出…

基于gossip流言算法实现alertmanager高可用

目录一.alertmanager高可用架构设计1 Gossip流言算法协议原理分析2 Gossip的优劣势3 Gossip中通信模式二.搭建alertmanager高可用架构实战1.搭建alertmanager高可用架构2..测试高可用 一.alertmanager高可用架构设计 1 Gossip流言算法协议原理分析如上图所示,我们可以发现aler…

iman——冲刺日志(第二天)

半成品 团队成员分工与进度 📝👥组别 成员 完成的任务 完成任务所用时间 (小时) 剩余时间 (小时)前端 阿依娜孜 完成每日行程展示页面,初步实现按钮切换功能。 3 2前端 郭剑敏 优化“账单管理”页面设计,编写路线编辑功能的前端代码。 3 1前端 王梓铭 完成主页和导航栏布…

先天软工圣体队——冲刺日记(第二天)

1. 每位团队成员的分工与进度成员 完成的任务 完成的任务时长 剩余时间何愉心、邱雨涵 对冲刺计划以及日常开发进行记录与剪辑 10小时 5小时陈思雨,郑奇键 “资料库”模块进一步完善 6小时 4小时陈尚冰 美化上传历年卷的前端页面 12小时 3小时柯鸿毅 API接口功能初步完成 15小…

攻防世界pwn-level0栈对齐

ret地址学习 NewStarCTFweek2-ez_game中出现了栈对齐相关知识点,所以特地前来学习,本篇主要为调试记录,由于远程非常轻易就可打通,故重点关注于本地打通 使用 ret_addr = hex(next(elf.search(asm(ret))))寻找汇编指令ret(n)的地址 ┌──(root㉿kali)-[~/Desktop/Adworl…

深度学习面试的时候,如何回答1x1卷积的作用

11月了,秋招已经开始了。不知最近有没有同学在投简历面试呢? 回想起几年前我面试某大厂的时候,被问到了很多深度学习相关的知识,那时的我懂的不多,可以说是被面试官360度无死角蹂躏。 那次面试,印象最深的是问了很多与卷积相关的问题,导致我后来工作一段时间看到卷积就时…

day4-Scrum

这个作业属于哪个课程 https://edu.cnblogs.com/campus/gdgy/CSGrade22-34/作业要求 需求&原型改进、系统设计、Alpha任务分配计划、测试计划团队项目仓库 https://github.com/bitpurleclude/GDUT-Goofish/issues团队成员 李嘉锐 车峤锐 于海洋 林进光 黄健 钟启…

GPU编程

来源:https://worktile.com/kb/p/2155928gpu编程有什么用? 图形处理单元(GPU)编程具有多种用途,主要包括:1、加速大规模计算任务、2、图形和视频渲染、3、深度学习和机器学习。GPU编程在深度学习和机器学习领域尤为重要。它允许数据科学家和研究人员利用GPU的并行处理能力…

Objects

概述 Objects 是一个工具类, 提供了一些方法去完成一些功能. Objects 类中的常见的成员方法:图1 Objects 类中的常见的成员方法equals 方法 程序示例: Javabean 类: public class Student {private String name;private int age;public Student() {}public Student(String name…

项目冲刺-3

一、昨日已完成的任务 学习有关springboot,vue等前后端知识,明确要开发的功能,初步搭好底层框架,做完了登录注册功能。 今日计划完成的任务 完善数据库和底层框架,学习有关知识,继续尝试做功能接口。 工作中遇到的困难 成员的前后端基础较差,需要花大量时间入门,目前做…