代码如下

package mainimport ("bufio""fmt""hash""io""os""time"
)func main() {for {fmt.Print("请输入需要md2亿次加密的字符:")input := bufio.NewScanner(os.Stdin)input.Scan()s := input.Text()start := time.Now().Unix()for i := 0; i < 100000000; i++ {s = md2(s)}end := time.Now().Unix()fmt.Printf("md2亿次加密结果为:%s\n", s)fmt.Printf("耗时:%d秒\n", end-start)}
}func md2(str string) string {c := New()io.WriteString(c, str)has := c.Sum(nil)md5str1 := fmt.Sprintf("%x", has)return md5str1
}// The size of an MD2 checksum in bytes.
const Size = 16// The blocksize of MD2 in bytes.
const BlockSize = 16const _Chunk = 16var PI_SUBST = []uint8{41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6,19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188,76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24,138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251,245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63,148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50,39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165,181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210,150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157,112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27,96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197,234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65,129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123,8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233,203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228,166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237,31, 26, 219, 153, 141, 51, 159, 17, 131, 20,
}// digest represents the partial evaluation of a checksum.
type digest struct {digest [Size]byte   // the digest, Sizestate  [48]byte     // state, 48 intsx      [_Chunk]byte // temp storage buffer, 16 bytes, _Chunknx     uint8        // how many bytes are there in the buffer
}func (d *digest) Reset() {for i := range d.digest {d.digest[i] = 0}for i := range d.state {d.state[i] = 0}for i := range d.x {d.x[i] = 0}d.nx = 0
}// New returns a new hash.Hash computing the MD2 checksum.
func New() hash.Hash {d := new(digest)d.Reset()return d
}func (d *digest) Size() int { return Size }func (d *digest) BlockSize() int { return BlockSize }// Write is the interface for IO Writer
func (d *digest) Write(p []byte) (nn int, err error) {//fmt.Printf("Getting %d bytes %x\n",len(p), p)nn = len(p)//d.len += uint64(nn)// If we have something left in the bufferif d.nx > 0 {n := uint8(len(p))var i uint8// try to copy the rest n bytes free of the buffer into the buffer// then hash the bufferif (n + d.nx) > _Chunk {n = _Chunk - d.nx}for i = 0; i < n; i++ {// copy n bytes to the bufferd.x[d.nx+i] = p[i]}d.nx += n// if we have exactly 1 block in the buffer then hash that blockif d.nx == _Chunk {block(d, d.x[0:_Chunk])d.nx = 0}p = p[n:]}imax := len(p) / _Chunk// For the rest, try hashing by the blocksizefor i := 0; i < imax; i++ {block(d, p[:_Chunk])p = p[_Chunk:]}// Then stuff the rest that doesn't add up to a block to the bufferif len(p) > 0 {d.nx = uint8(copy(d.x[:], p))//fmt.Printf("Length of p = %d, copied %d.\n", len(p), d.nx)}return
}func (d0 *digest) Sum(in []byte) []byte {// fmt.Printf("=== Got sum request ===\n")// Make a copy of d0 so that caller can keep writing and summing.d := *d0// Padding.var tmp [_Chunk]byte//tmp := make([]byte, _Chunk, _Chunk)len := uint8(d.nx)for i := range tmp {tmp[i] = _Chunk - len}//fmt.Printf("Calling block(%x) size %d for last block...\n", tmp, _Chunk-len)d.Write(tmp[0 : _Chunk-len])// At this state we should have nothing left in bufferif d.nx != 0 {panic("d.nx != 0")}d.Write(d.digest[0:16])// At this state we should have nothing left in bufferif d.nx != 0 {panic("d.nx != 0")}//fmt.Printf("=== Sum request done ===\n")//fmt.Printf("\n\n\n\n-------------------\n\n\n");return append(in, d.state[0:16]...)
}func block(dig *digest, p []byte) {//fmt.Printf("block() digest (%x) updating with p(%x) len=%d\n", dig.digest, p, len(p))var t, i, j uint8t = 0for i = 0; i < 16; i++ {dig.state[i+16] = p[i]dig.state[i+32] = byte(p[i] ^ dig.state[i])}for i = 0; i < 18; i++ {//fmt.Printf("t before: %d ", t)for j = 0; j < 48; j++ {dig.state[j] = byte(dig.state[j] ^ PI_SUBST[t])t = dig.state[j]}//fmt.Printf("t before: %d ", t)t = byte(t + i)//fmt.Printf("t after: %d\n", t)}//fmt.Printf("---------------\n")t = dig.digest[15]for i = 0; i < 16; i++ {dig.digest[i] = byte(dig.digest[i] ^ PI_SUBST[p[i]^t])t = dig.digest[i]//fmt.Printf("t after: %d\n", t)}//fmt.Printf(" --> Got digest = (%x)\n", dig.digest)
}

打包程序

在项目下打开控制台,输入命令

go build


双击exe文件即可直接运行程序

Go实现md2亿次加密相关推荐

  1. java md2_java中加密的实现方法(MD5,MD2,SHA)

    java中加密的实现方法(MD5,MD2,SHA) 实例代码:注释都很清楚, import java.security.MessageDigest; import javax.xml.bind.ann ...

  2. MD5,MD2,SHA加密的实现方式

    import java.security.MessageDigest;import javax.xml.bind.annotation.adapters.HexBinaryAdapter;public ...

  3. 乌克兰政府和银行再次遭受DDoS攻击、1亿部三星手机的加密功能存在缺陷|2月24日全球网络安全热点

    安全资讯报告 25个恶意JavaScript库通过官方NPM包存储库分发 一批25个恶意JavaScript库进入了官方NPM软件包注册表,目的是从受感染的系统中窃取Discord令牌和环境变量. D ...

  4. Java常用加密解密算法全解

    数据编码.数字签名.信息加密 是前后端开发都经常需要使用到的技术,应用场景包括了用户登入.交易.信息通讯.OAuth 等等,不同的应用场景也会需要使用到不同的签名加密算法,或者需要搭配不一样的 签名加 ...

  5. 解密红杉资本加密局,一个女人选择 ALL IN

    2月18日,红杉资本宣布推出规模为5-6亿美元的加密货币投资基金,这是红杉资本自 1972 年成立以来的首个特定行业基金. 但是这一切是如何发生的?为何红杉资本从一个传统一线美元基金大步跨越,试图引领 ...

  6. 财路网每日原创推送:用市值来评估加密货币是毫无意义的

    如果你询问加密货币社区的普通参与者去哪里寻找有关某种特定加密货币是否成功的信息,他们可能会说道诸如 WorldCoinIndex.CoinMarketCap 等评估加密货币市值的平台.基于这些平台列出 ...

  7. 加密解密、信息摘要常用算法收集~~

    MD5算法研究  综述 md5的全称是message-digest algorithm 5(信息-摘要算法),在90年代初由mit laboratory for computer science和rs ...

  8. 加密解密、信息摘要算法收集

    MD5算法研究 综述 md5的全称是message-digest algorithm 5(信息-摘要算法),在90年代初由mit laboratory for computer science和rsa ...

  9. WhatsApp加密功能也成了美国政府“眼中钉”

    3月13日消息,据<纽约时报>报道,美国官员和其他相关人士称,在司法部公开与苹果争论访问加密iPhone的问题时,美国政府官员私下还讨论如何解决与另一家科技公司.Facebook旗下的Wh ...

最新文章

  1. 二叉搜索树(binary search tree)的建立、删除、查找
  2. 关系型数据库到HBase的数据储存方式变迁
  3. wifi共享大师电脑版_手机开wifi热点,共享网络给电脑,变身4G无线路由器
  4. UE4 custom depth 自定义深度
  5. 一个指针的引用引发的血案
  6. Google IO 谈 AI First,我们却发现了更多
  7. 巴菲特的价值投资的第二版本
  8. 当时我就震惊了:无穷带来的各种悖论
  9. Go 语言之父详述切片与其他编程语言数组的不同
  10. 考试一个程序员,1f=0.1
  11. 如何把微信和支付宝的收款二维码合成一个?
  12. 什么是银行行号,银行联行号有哪些功能?
  13. c#获取软件版本、windows用户名、windows用户目录、.net版本、windows版本等
  14. 软件工程网络15结对编程作业1(201521123018谢元将)
  15. 大数据开发和java的前景_大数据开发和软件开发哪个前景好?
  16. Linux 网络设置(ifconfig、route、traceroute、netstat、ss、nslookup、dig、ping状态返回分析)
  17. 计算机安装硬盘后无法启动不了,双硬盘无法启动提示"invalid partition table"开不了机怎么解决?...
  18. 使用lgb.cv时出现ValueError: Supported target types are: (‘binary‘, ‘multiclass‘). Got ‘continuous‘ instea
  19. Qt setFocus无法生效问题
  20. 管理员禁止运行此应用的解决办法

热门文章

  1. 渗透测试-Kali入侵Win7主机
  2. smbclient php,smbclient 用法
  3. iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 81 -j DNAT --to-destination
  4. 2022-4-16 服务器集中写
  5. 2022-3-31 Leetcode 415.字符串相加
  6. SQL Server 视图创建点滴
  7. leetcode系列-107.二叉树的层序遍历II
  8. android app安装,Android App更新安装APK
  9. php rabbitmq非阻塞,Python-RabbitMQ-RPC(非阻塞版)
  10. java web权限框架_Java Web通用用户权限管理框架设计与实现