和谐文字生成小工具

背景:昨天帮一位邻居在小区微信群里了发了一段文字,结果到了晚上街道派出所的民警叔叔就找到我家里,对从小德智体美劳全面发展的我进行了悉心的法制教育。

 这件事想了想 ,会给我带来的问题,身为程序员,如何避免这样的问题。

怎么发现的:估计是有网监程序在各个群里做监控,对于和谐社会的言论关键字进行抓取分析之类的,如果有,再进行人工查阅,下派任务,对该发表人进行定点监听。

带来的问题:由此大约会给我带来两个问题,一个是当前的问题,我的微信估计近期会受到网监的监控,怎么去除我微信的唯一识别是一个点,于是我抓紧换了微信头像和昵称(据以前开发网监程序的朋友说,微信抓取是按昵称和头像来的),也不知道这样靠不靠谱。二是以后的问题,以后发表这种敏感信息的时候,怎样才能不会网监做出关键字识别。识别大约是根据关键字,如果有图片的话,再图片转文字,降噪分析等。

破解的方法:也就是说我们尽量不发表文字,发表图片的话,会带来识别的难度。如果图片里的文字,有特殊字符混淆在里面的话,也会增加识别难度。

正文:进入正题,开工~

1、以C# winform为例写该小程序

2、效果:

输出的图片:

可以直接在微信群里Ctrl+V:

3、代码示例:

using System;
using System.Windows.Forms;
using System.Configuration;
using System.Threading;
using System.Drawing;

namespace WordsToImg
{
    public partial class frmWordToImg : Form
    {
        private char[] _specialChars;
        public frmWordToImg()
        {
            InitializeComponent();
        }

        private void frmWordToImg_Load(object sender, EventArgs e)
        {
            var specialChars = ConfigurationManager.AppSettings["SpecialChars"];
            this._specialChars = specialChars.ToCharArray();
        }

        private void btnGenerator_Click(object sender, EventArgs e)
        {
            string text = txtWords.Text;
            var texts = text.ToCharArray();
            Random rd = new Random();

            string textNew = "";
            foreach (var item in texts)
            {
                var run = rd.Next(3);
                Thread.Sleep(1);
                textNew += item;
                for (int count = 0; count < run; count++)
                {
                    var random = rd.Next(_specialChars.Length);
                    textNew += _specialChars[random];
                    Thread.Sleep(1);
                }

            }

            var img = CreateImage(textNew, false, 9);
            Clipboard.SetImage(img);
        }

        /// <summary>
        /// 生成文字图片
        /// </summary>
        /// <param name="text"></param>
        /// <param name="isBold"></param>
        /// <param name="fontSize"></param>
        public Image CreateImage(string text, bool isBold, int fontSize)
        {
            int wid = 400;
            int high = 200;
            Font font;
            if (isBold)
            {
                font = new Font("Arial", fontSize, FontStyle.Bold);

            }
            else
            {
                font = new Font("Arial", fontSize, FontStyle.Regular);

            }
            //绘笔颜色
            SolidBrush brush = new SolidBrush(Color.Black);
            StringFormat format = new StringFormat(StringFormatFlags.NoClip);
            Bitmap image = new Bitmap(wid, high);
            Graphics g = Graphics.FromImage(image);
            SizeF sizef = g.MeasureString(text, font, PointF.Empty, format);//得到文本的宽高
            int width = (int)(sizef.Width + 1);
            int height = (int)(sizef.Height + 1);
            image.Dispose();
            image = new Bitmap(width, height);
            g = Graphics.FromImage(image);
            g.Clear(Color.White);//透明

            RectangleF rect = new RectangleF(0, 0, width, height);
            //绘制图片
            g.DrawString(text, font, brush, rect);
            //释放对象
            g.Dispose();
            return image;
        }


    }
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!--增加系统变量-->
  <appSettings>
    <!--混淆用的特殊字符-->
    <add key="SpecialChars" value="«¬®¯°±²³☎☏✄☪☣☢☠♨« »☑✔☐☒✘㍿☯☰☷♥♠♤❤♂♀★☆✡※卐" />
  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

4、鉴于别有人拿着这个违法乱纪,工具就不挂出来了,代码很简单,有用的,自己拿代码编译一下~~

猜你喜欢

转载自www.cnblogs.com/LightColorHy/p/9938493.html
今日推荐