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

相关推荐
L_autinue_Star32 分钟前
手写vector容器:C++模板实战指南(从0到1掌握泛型编程)
java·c语言·开发语言·c++·学习·stl
元气小嘉1 小时前
前端技术小结
开发语言·前端·javascript·vue.js·人工智能
励志的大鹰哥1 小时前
V少JS基础班之第七弹
开发语言·javascript·ecmascript
AI360labs_atyun2 小时前
Java在AI时代的演进与应用:一个务实的视角
java·开发语言·人工智能·科技·学习·ai
凤年徐2 小时前
【数据结构与算法】203.移除链表元素(LeetCode)图文详解
c语言·开发语言·数据结构·算法·leetcode·链表·刷题
nbsaas-boot3 小时前
多租户架构下的多线程处理实践指南
java·开发语言·spring
无小道3 小时前
c++--typedef和#define的用法及区别
c语言·开发语言·汇编·c++
SoniaChen333 小时前
Rust基础-part2-变量和可变类型
开发语言·后端·rust
神所夸赞的夏天4 小时前
c#获取Datatable中某列最大或最小的行数据方法
开发语言·c#
h0l10w4 小时前
【Java】MongoDB
java·开发语言·mongodb