bash 双hash算法sha256的写法

这样是不行的

echo -n "hello" | sha256sum | sha256sum

因为sha256sum的输出有干扰内容

ppl@de:~/tmp$ echo -n "hello" | sha256sum
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824  -

需要这样子

echo -n "hello" | sha256sum | xxd -r -p | sha256sum

python算法:

#!/usr/bin/env python3

import sys, hashlib, binascii

filename=sys.argv[1]
f = open(filename, 'r')
for line in f:
  line = line.replace('\n', '').replace('\r', '')
  round1hex = hashlib.sha256(line.encode('utf-8')).hexdigest().zfill(64)
  round1bin = binascii.unhexlify(round1hex)
  round2hex = hashlib.sha256(round1bin).hexdigest().zfill(64)
  print(round2hex)

Blockchain Demo

相关推荐
life_time_2 小时前
C语言(22)
c语言·开发语言
Minner-Scrapy2 小时前
DApp 开发入门指南
开发语言·python·web app
孤雪心殇2 小时前
简单易懂,解析Go语言中的Map
开发语言·数据结构·后端·golang·go
庸俗今天不摸鱼2 小时前
Canvas进阶-4、边界检测(流光,鼠标拖尾)
开发语言·前端·javascript·计算机外设
菠菠萝宝2 小时前
【Java八股文】10-数据结构与算法面试篇
java·开发语言·面试·红黑树·跳表·排序·lru
奔跑吧邓邓子2 小时前
【Python爬虫(36)】深挖多进程爬虫性能优化:从通信到负载均衡
开发语言·爬虫·python·性能优化·负载均衡·多进程
不会Hello World的小苗3 小时前
Java——链表(LinkedList)
java·开发语言·链表
lsx2024063 小时前
Perl 面向对象编程指南
开发语言
Allen Bright3 小时前
【Java基础-46.3】Java泛型通配符详解:解锁类型安全的灵活编程
java·开发语言