社区,我需要有关改进以下代码的建议:
为了解决这个问题,程序执行以下操作:
- 它将包含 sha2 哈希的文件读入字符串数组。
- 它接受一个起始数字并连续计算哈希值。
- 它使用文件(列表)中的哈希检查计算的哈希并打印匹配项。
//FILENAME: passcracker.go
package main
import (
"fmt"
"crypto/sha256"
"os"
"io/ioutil"
"strings"
"math/big"
)
func isValueInList(value1 string, list []string) bool {
for _, v := range list {
if v == value1 {
return true
}
}
return false
}
func main() {
if len(os.Args) <= 2 {
fmt.Printf("USAGE : %s <PATTERNFILE> <STARTING_NUMBER>\n", os.Args[0])
os.Exit(0)
}
fileName := os.Args[1]
fileBytes, err := ioutil.ReadFile(fileName)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
strHashArr := strings.Split(string(fileBytes), "\r\n")
startNum := new(big.Int)
startNum.SetString(os.Args[2], 10)
one := big.NewInt(1)
//list := []string{ }
var i int64
for i = 0; i < 262144; i++ {
h := sha256.New()
h.Write([]byte(startNum.Bytes()))
s := fmt.Sprintf("%x", h.Sum(nil))
// Hash values are computed and added to a string list - A probable approach
//list.append(s)
if isValueInList(s, strHashArr) {
fmt.Printf("Matched Hash %s for number %s\n",s,startNum)
}
startNum = startNum.Add(startNum,one)
}
// Probable approach to reduce the time
// Computed hash string list is checked with the file hashes list
// Function takes to string arrays
// Can it also use map or any other method for list in list comparison?
//if isValueInList(list, strHashArr) {
// get all the matched items and print the index value using the startNum value in a loop
//}
}
密码哈希文件位于:https ://pastebin.com/TWPxrb4R
要运行程序,请使用
passcracker hashes.txt 1000
该程序打印匹配的哈希值以及识别的数字。
由于该程序仅计算有限的 262144 个哈希,因此打印速度会更快。
现在为了改进程序以更快地输出匹配,是否可以将哈希计算为字符串数组并调用一个函数来匹配文件中的哈希并在一次调用中返回匹配的索引?
由于该问题与密码破解方法非常相似,但这里的区别是打印顺序计算和匹配的哈希值。它类似于连续运行的用户 ID。
由于输入哈希文件可能会变得非常大(以几千个哈希的形式)并且连续数字也可能很大,因此即使计算只是针对包含 10K 哈希的哈希文件的 32K 循环,程序也会遇到困难.
目前为简洁起见,上述文件中的哈希数为 50,循环检查 256K 个数字,执行速度更快。
一些帮助将不胜感激。谢谢你。