(C#加密)幻术-大踲无形
--这也是看Msdn就是把在一个图片上隐藏数据
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
namespace Steganography
{
/**//// <summary>
/// Summary description for SteganographyForm.
/// </summary>
public class SteganographyForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button buttonHideMessage;
private System.Windows.Forms.Panel panelOriginalImage;
private System.Windows.Forms.TextBox textBoxOriginalMessage;
private System.Windows.Forms.Panel panelModifiedImage;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button buttonExtractMessage;
private System.Windows.Forms.TextBox textBoxExtractedlMessage;
private System.Windows.Forms.GroupBox groupBox2;
/**//// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public SteganographyForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
try
{
//load original bitmap from a file
bitmapOriginal = (Bitmap)Bitmap.FromFile(
@"..\..\katie_plaintext.jpg");
//center to screen
this.CenterToScreen( );
}
catch (Exception ex)
{
MessageBox.Show(
"Error loading image. " +
ex.Message );
}
}
/**//// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows Form Designer generated code#region Windows Form Designer generated code
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonHideMessage = new System.Windows.Forms.Button();
this.panelOriginalImage = new System.Windows.Forms.Panel();
this.textBoxOriginalMessage = new System.Windows.Forms.TextBox();
this.panelModifiedImage = new System.Windows.Forms.Panel();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.buttonExtractMessage = new System.Windows.Forms.Button();
this.textBoxExtractedlMessage = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.SuspendLayout();
//
// buttonHideMessage
//
this.buttonHideMessage.Location = new System.Drawing.Point(10, 594);
this.buttonHideMessage.Name = "buttonHideMessage";
this.buttonHideMessage.Size = new System.Drawing.Size(144, 25);
this.buttonHideMessage.TabIndex = 0;
this.buttonHideMessage.Text = "Hide Message";
this.buttonHideMessage.Click += new System.EventHandler(this.buttonHideMessage_Click);
//
// panelOriginalImage
//
this.panelOriginalImage.Location = new System.Drawing.Point(19, 26);
this.panelOriginalImage.Name = "panelOriginalImage";
this.panelOriginalImage.Size = new System.Drawing.Size(412, 521);
this.panelOriginalImage.TabIndex = 0;
//
// textBoxOriginalMessage
//
this.textBoxOriginalMessage.Location = new System.Drawing.Point(182, 594);
this.textBoxOriginalMessage.Name = "textBoxOriginalMessage";
this.textBoxOriginalMessage.Size = new System.Drawing.Size(240, 21);
this.textBoxOriginalMessage.TabIndex = 1;
//
// panelModifiedImage
//
this.panelModifiedImage.Location = new System.Drawing.Point(461, 26);
this.panelModifiedImage.Name = "panelModifiedImage";
this.panelModifiedImage.Size = new System.Drawing.Size(411, 521);
this.panelModifiedImage.TabIndex = 0;
//
// groupBox1
//
this.groupBox1.Location = new System.Drawing.Point(163, 569);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(279, 60);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Original Message";
//
// groupBox3
//
this.groupBox3.Location = new System.Drawing.Point(10, 9);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(432, 551);
this.groupBox3.TabIndex = 3;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Original Image";
//
// groupBox4
//
this.groupBox4.Location = new System.Drawing.Point(451, 9);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(432, 551);
this.groupBox4.TabIndex = 3;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Modified Image";
//
// buttonExtractMessage
//
this.buttonExtractMessage.Location = new System.Drawing.Point(451, 594);
this.buttonExtractMessage.Name = "buttonExtractMessage";
this.buttonExtractMessage.Size = new System.Drawing.Size(144, 25);
this.buttonExtractMessage.TabIndex = 2;
this.buttonExtractMessage.Text = "Extract Message";
this.buttonExtractMessage.Click += new System.EventHandler(this.buttonExtractMessage_Click);
//
// textBoxExtractedlMessage
//
this.textBoxExtractedlMessage.Location = new System.Drawing.Point(624, 594);
this.textBoxExtractedlMessage.Name = "textBoxExtractedlMessage";
this.textBoxExtractedlMessage.ReadOnly = true;
this.textBoxExtractedlMessage.Size = new System.Drawing.Size(240, 21);
this.textBoxExtractedlMessage.TabIndex = 3;
//
// groupBox2
//
this.groupBox2.Location = new System.Drawing.Point(605, 569);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(278, 60);
this.groupBox2.TabIndex = 3;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Extractedl Message";
//
// SteganographyForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(930, 672);
this.Controls.Add(this.textBoxOriginalMessage);
this.Controls.Add(this.buttonHideMessage);
this.Controls.Add(this.panelModifiedImage);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.panelOriginalImage);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.buttonExtractMessage);
this.Controls.Add(this.textBoxExtractedlMessage);
this.Controls.Add(this.groupBox2);
this.Name = "SteganographyForm";
this.Text = "Steganography";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.SteganographyForm_Paint);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
/**//// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new SteganographyForm());
}
private void SteganographyForm_Paint(
object sender,
System.Windows.Forms.PaintEventArgs e)
{
try
{
//get Graphics object for painting original
Graphics gPanelOriginal =
Graphics.FromHwnd(
panelOriginalImage.Handle);
//draw original bitmap into panel
gPanelOriginal.DrawImage(
bitmapOriginal, new Point(0 ,0));
//return if there is no modified image yet
if (bitmapModified==null)
return;
//get Graphics object for painting modified
Graphics gPanelModified =
Graphics.FromHwnd(
panelModifiedImage.Handle);
//draw modified bitmap into panel
gPanelModified.DrawImage(
bitmapModified, new Point(0 ,0));
}
catch (Exception ex)
{
MessageBox.Show(
"Error drawing image." +
ex.Message);
this.Close( );
}
}
private void buttonHideMessage_Click(
object sender, System.EventArgs e)
{
try
{
//show wait cursor
this.Cursor = Cursors.WaitCursor;
//start off with copy of original image
bitmapModified = new Bitmap(
bitmapOriginal,
bitmapOriginal.Width,
bitmapOriginal.Height);
//get original message to be hidden
int numberbytes =
(byte)textBoxOriginalMessage.Text.Length;
byte[] bytesOriginal = new byte[numberbytes+1];
bytesOriginal[0] = (byte)numberbytes;
Encoding.UTF8.GetBytes(
textBoxOriginalMessage.Text,
0,
textBoxOriginalMessage.Text.Length,
bytesOriginal,
1);
//set bits 1, 2, 3 of byte into LSB red
//set bits 4, 5, 6 of byte into LSB green
//set bits 7 and 8 of byte into LSB blue
int byteCount = 0;//----一列一列搞定
for (int i=0; i<bitmapOriginal.Width; i++)
{
for (int j=0; j<bitmapOriginal.Height; j++)
{
if (bytesOriginal.Length==byteCount)
return;
//---返回当前循环的坐标点的颜色数据
Color clrPixelOriginal =
bitmapOriginal.GetPixel(i, j);
//为基元整型类型、枚举类型和 boolean 类型预定义了二元 | 运算符。对于基元整型类型和枚举类型,| 计算操作数的按位“或”。
//--注意这里是对~~血迹之术-的实际应用中的变种
//--这里的算法还是不太清楚估计是-防止三元素重合成1点后产生的错位--如果大大们知道麻烦告诉我下
byte r =
(byte)((clrPixelOriginal.R & ~0x7) |
(bytesOriginal[byteCount]>>0)&0x7);
byte g =
(byte)((clrPixelOriginal.G & ~0x7) |
(bytesOriginal[byteCount]>>3)&0x7);
byte b =
(byte)((clrPixelOriginal.B & ~0x3) |
(bytesOriginal[byteCount]>>6)&0x3);
byteCount++;
//set pixel to modified color
bitmapModified.SetPixel(
i, j, Color.FromArgb(r, g, b));
}
}
}
catch (Exception ex)
{
MessageBox.Show(
"Error hiding message." +
ex.Message);
}
finally
{
//show normal cursor
this.Cursor = Cursors.Arrow;
//repaint
Invalidate();
}
}
private void buttonExtractMessage_Click(
object sender, System.EventArgs e)
{
//get bytes of message from modified image
byte[] bytesExtracted = new byte [256+1];
try
{
//show wait cursor, can be time-consuming
this.Cursor = Cursors.WaitCursor;
//get bits 1, 2, 3 of byte from LSB red
//get bits 4, 5, 6 of byte from LSB green
//get bits 7 and 8 of byte from LSB blue
int byteCount = 0;
for (int i=0; i<bitmapModified.Width; i++)
{
for (int j=0; j<bitmapModified.Height; j++)
{
if (bytesExtracted.Length==byteCount)
return;
Color clrPixelModified =
bitmapModified.GetPixel(i, j);
byte bits123 =
(byte)((clrPixelModified.R&0x7)<<0);
byte bits456 = (
byte)((clrPixelModified.G&0x7)<<3);
byte bits78 = (
byte)((clrPixelModified.B&0x3)<<6);
bytesExtracted[byteCount] =
(byte)(bits78 |bits456 | bits123);
byteCount++;
}
}
}
catch (Exception ex)
{
MessageBox.Show(
"Error extracting message." +
ex.Message);
}
finally
{
//show normal cursor
this.Cursor = Cursors.Arrow;
//get number of bytes from start of array
int numberbytes = bytesExtracted[0];
//get remaining bytes in array into string
textBoxExtractedlMessage.Text =
Encoding.UTF8.GetString(
bytesExtracted,
1,
numberbytes);
}
}
//shared private fields
private Bitmap bitmapOriginal;
private Bitmap bitmapModified;
}
}
转载于:https://www.cnblogs.com/ajaxren/archive/2007/04/23/724489.html
(C#加密)幻术-大踲无形相关推荐
- 文件夹加密超级大师会把文件上传到服务器吗,【共享文件夹加密超级大师怎么用】共享文件夹加密超级大师好不好_使用技巧-ZOL软件百科...
共享文件夹加密超级大师专为企业用户设计,有效保护局域网共享文件夹.软件提供了共享文件夹用户权限设置功能,可以为每一个用户分配不同的权限,完美解决了"共享即不能保密,保密即不能共享" ...
- 加密货币大崩盘:第一季度最大跌幅高达 88%!
点击上方"CSDN",选择"置顶公众号" 关键时刻,第一时间送达! 但是世上没有任何一样事物会轻易走向消亡. 我没见过哪个产业像加密货币一样迅速崛起,又在霎那间 ...
- 全面回顾2022年加密行业大事件:破后而立方能绝处逢生
2022年,加密领域以Luna/UST的崩溃为起点开启了漫长的加密寒冬,在严峻的宏观环境下以及一系列戏剧性事件中遭受了沉重打击.2022年初,加密货币生态系统的市值达到近3万亿美元,而截至年底已蒸发2 ...
- linux红帽给文件加密,红帽大神制作 Linux 工具,用于旧款罗技无线键盘加密设置...
Red Hat 的 Hans de Goede 编写了一个 Linux 实用程序,可为那些老化的罗技键盘配置加密链接状态;同时,也使得之前配置的使用加密链接的罗技键盘可以正确地重新配置. 正如 Han ...
- 电脑大文件夹怎么加密?大文件夹方法介绍
当我们把电脑中的各种数据分类存放在文件夹中时,可以方便我们使用和管理.但这些文件夹也会变得十分庞大,如果想要加密它们,就需要使用更快速.安全的方法.下面我们来了解一下电脑大文件夹的加密方法. 文件夹加 ...
- 咖说 | 硅谷“加密黑帮”大揭秘:一览 37 家科技圈区块链初创企业
" 收集一众行业大咖观点,探索区块链商业及应用.百家争鸣.百花齐放,说理.解密.预测和八卦,了解行业内幕,看咖说就够了! 投稿请联系 :tougao@conflux-chain.org 本文 ...
- python 服务端与c++客户端通讯_[原创]python socket 服务端 与 c++客户端通讯,发包内容加密,支持大文件,并发...
代码经过网络搜索,综合算是原创吧.py脚本为服务端 项目文件在 https://github.com/jinjie412/service_client_socket import socketserv ...
- 以太坊是什么鬼?!媲美比特币的加密币大揭秘
了解为什么以太币不仅仅只是另一种加密货币的终极指南. "比特币"和"以太坊"是常常结对出现的术语,实际上他们之间有着天壤之别. 两者唯一的共同点就是他们均为基于 ...
- 文件夹加密超级大师会把文件上传到服务器吗,共享文件夹加密超级大师怎么加密文件夹?...
共享文件夹加密超级大师是一款非常优秀的文件夹加密软件,它可以帮助我们加密一些重要的文件,从而达到防复制.防截屏.防删除.防另存为的效果,保证了文件的安全.那么,共享文件夹加密超级大师怎么加密文件夹呢? ...
最新文章
- FactoryBean
- 漫画:如何做一款比吃鸡还厉害的游戏
- 安卓应用安全指南 4.9 使用`WebView`
- 北斗轨迹记录_跑步GPS轨迹经常“飘”?要是用咱们的北斗,会好吗...
- MATLAB 不使用科学计数法 显示坐标 及理解
- 文件流的使用以及序列化和反序列化的方法使用
- 极光推送指定用户推送_苹果推送iOS 12.1.4和macOS 10.14.3修复FaceTime 国内用户可酌情...
- java读取txt文件字符串_java读取txt文件,对字符串进行操作后导出txt文件
- linux下低格u盘,拯救U盘,一个靠谱的强制低格的工具
- html银河特效编码,html5 canvas银河星系动画特效
- 自然语言处理NLP简介
- 双稳态电路的两个稳定状态是什么_晶振电路中选择电容的方式有哪些?
- 小孩增高的主要方式:足量动物脂肪;去除大豆;去除植物油;备孕6个月饮食
- 仿ios相机apk_仿苹果相机下载
- 数据类型和存储上的差别,基本数据类型,引用数据类型
- 2.4G模块NRF24L01调试经验
- 解决linux上耳机没有声音
- 如何做好企业抖音内容运营?
- js 取色器和 颜色拾取工具
- 买卖人、生意人、企业家
热门文章
- github下载源码也用命令进行安装包的联系
- Python的知识点 plt.plot()函数细节
- LeetCode简单题之汇总区间
- 使用TensorRT集成推理inference
- 使用NVIDIA A100 TF32获得即时加速
- 人工智能在音频链中找到自己的声音
- 计算机视觉一些项目实战技术(续)
- 2021年大数据Flink(十七):Flink四大基石
- php7安装执行configure报错error: off_t undefined; check your library configuration
- HTTP/HTTPS的请求和响应