博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用纯Perl语言(不需要任何模块)编写生成验证码图片的程序
阅读量:6414 次
发布时间:2019-06-23

本文共 2279 字,大约阅读时间需要 7 分钟。

hot3.png

使用纯Perl语言(不需要任何模块)编写生成验证码图片的程序,完整代码如下:

#!/usr/bin/perl

open (FILE, '>', 'image.png');
binmode (FILE);
print FILE &bmpNum (&myrand(9999));
close (FILE);
sub bmpNum{
my $verifynum=shift;
local @n0 = ("3c","66","66","66","66","66","66","66","66","3c");
local @n1 = ("1c","0c","0c","0c","0c","0c","0c","0c","1c","0c");
local @n2 = ("7e","60","60","30","18","0c","06","06","66","3c");
local @n3 = ("3c","66","06","06","06","1c","06","06","66","3c");
local @n4 = ("1e","0c","7e","4c","2c","2c","1c","1c","0c","0c");
local = ("3c","66","06","06","06","7c","60","60","60","7e");
local @n6 = ("3c","66","66","66","66","7c","60","60","30","1c");
local @n7 = ("30","30","18","18","0c","0c","06","06","66","7e");
local @n8 = ("3c","66","66","66","66","3c","66","66","66","3c");
local @n9 = ("38","0c","06","06","3e","66","66","66","66","3c");
for (my $i = 0; $i < 10; $i++)
{
for (1 .. 6)
{
    my $a1 = substr("012", int(myrand(3)), 1) . substr("012345", int(myrand(6)), 1);
    my $a2 = substr("012345",int(myrand(6)),1) . substr("0123", int(myrand(4)), 1);
    int(myrand(2)) eq 1 ? push(@{"n$i"}, $a1) : unshift(@{"n$i"},$a1);
    int(myrand(2)) eq 0 ? push(@{"n$i"}, $a1) : unshift(@{"n$i"},$a2);
}
}
my @bitmap = ();
for (my $i = 0; $i < 20; $i++)
{
for (my $j = 0; $j < 4; $j++)
{
    my $n = substr($verifynum, $j, 1);
    my $bytes = ${"n$n"}[$i];
    my $a = int(myrand(15));
    $a eq 1 ? $bytes =~ s/9/8/g : $a eq 3 ? $bytes =~ s/c/e/g : $a eq 6 ? $bytes =~ s/3/b/g : $a eq 8 ? $bytes =~ s/8/9/g : $a eq 0 ? $bytes =~ s/e/f/g : 1;
    push(@bitmap, $bytes);
}
}
for ($i = 0; $i < 8; $i++)
{
my $a = substr("012", int(myrand(3)), 1) . substr("012345", int(myrand(6)), 1);
unshift(@bitmap, $a);
push(@bitmap, $a);
}
my $image = '424d9e000000000000003e0000002800';
$image .= "00002000000018000000010001000000";
$image .= "00006000000000000000000000000000";
$image .= "00000000000000000000FFFFFF00";
$image .= join('', @bitmap);
$image = pack ('H*', $image);
return $image;
}
sub myrand {
    my $max = shift;
    my $result;
    my $randseed = $LBCGI::randseed ;
    $max ||= 1;
    eval("\$result = rand($max);");
    return $result unless ($@);
    $randseed = time unless ($randseed);
    my $x = 0xffffffff;
    $x++;
    $randseed *= 134775813;
    $randseed++;
    $randseed %= $x;
    return $randseed * $max / $x;
}

转载于:https://my.oschina.net/lionel45/blog/82168

你可能感兴趣的文章
ZOJ 1076 Gene Assembly
查看>>
JS数组push会覆盖前面的数据问题
查看>>
用SQL语句创建触发器
查看>>
Sublime Text 2 注册码
查看>>
用endnote导入bib
查看>>
关于除法运算的比较
查看>>
MySQL 存储过程学习笔记
查看>>
Elasticsearch——QueryBuilder简单查询
查看>>
欧拉回路模板
查看>>
查看软件的安装路径
查看>>
将C#文档注释生成.chm帮助文档(转)
查看>>
使用JavaScript缓存图片
查看>>
iOS 正则表达式去除特殊符号
查看>>
简单数据结构之链表(无头节点)
查看>>
js实现数组去重的三个方法、数组的快速排序
查看>>
ORACLE导入遇到ORACLE错误959解决方法
查看>>
排序算法之选择排序
查看>>
区间dp括号匹配
查看>>
Python中变量的命名与使用(个人总结)
查看>>
【风马一族_SQL Server】
查看>>