Not really. You already asked about sha256 here How to generate list of set of numbers and generate sha256 in golang
i checked again but no luck.
package main
import (
“fmt”
“strings”
“crypto/sha256”
“github.com/next-master”
“strconv”
)
func join(arr []interface{}) string {
buf := “”
for _, v := range arr {
buf += v.(string)
}
return buf
}
func main() {
temp := strings.Split(“abcd123”, “”)
arr := make([]interface{}, len(temp))
for i, v := range temp {
arr[i] = v
}
for v := range next.Combination(arr, 5, true) {
hash := sha256.Sum256([]byte(strconv.Itoa(join(v))))
fmt.Println("%s %X\n",join(v), hash)
}
}
its giving same error …go:26:52: cannot use join(v) (type string) as type int in argument to strconv.Itoa
Yes, because it doesn’t have any sense at all. Ok, let’s take all parts together:
package main
import (
"crypto/sha256"
"fmt"
"strings"
"github.com/klaidliadon/next"
)
func join(arr []interface{}) string {
buf := ""
for _, v := range arr {
buf += v.(string)
}
return buf
}
func main() {
temp := strings.Split("abcd123", "")
arr := make([]interface{}, len(temp))
for i, v := range temp {
arr[i] = v
}
for v := range next.Combination(arr, 5, true) {
hash := sha256.Sum256([]byte(join(v)))
fmt.Printf("%s %X\n", join(v), hash)
}
}
Thanks,…now its working… So was my mistake about between fmt.Printf and fmt.Println?
I wanted to know where you learned So much about Golang , I would do it if possible. please let me know.
Sorry to Ask Again But This code stops if i change abcd123 to abcdef0123456789 and length 5 to 64 . Don’t know whats going.
it only displayed one line and stopped? why?
From my point of view Go is really simple language (I have some experience with C++ so I can compare :D), there is excellent documentation, many articles, welcoming community here on forum.
Main thing that should learn any developer is how to formulate right question. After that you just learn specific things of one or other language. And better way to do it is working on interesting tasks. Because without wish to accomplish them learning process is really hard.
That easy - there very large numbers of combinations. And by very large I mean really very big number.
But it should run slowly i think but don’t know why is it stopping like this. any solution for this?
Of course - use another package or implement algorithm by hand without memory allocation for result.
Omg. Now I reached Dead End. Looks like I have to start from beginning. one more thing should I start with c or C++ to learn. so golang will be easier? as yesterday only i got to know about some placeholders like %x %c %s %d.
thanks for your Support.
No. Forget about C, C++ and all that stuff if you can
The key almost always in the algorithm not in implementation. There are must be some effective algorithms but you can start from simple one from here:
hello GreyShatter, I got Some Other code from github but there is one thing … Its sha256 is not matching… please see this code and help me out.
package main
import (
"fmt"
"math/big"
"crypto/sha256"
)
func main() {
// Print header
fmt.Printf("%64s %64s\n", "Raw-sha256", "hash-256",)
// Initialise big numbers with small numbers
count, one := big.NewInt(0), big.NewInt(1)
// Create a slice to pad our count to 32 bytes
padded := make([]byte, 32)
// Loop forever because we're never going to hit the end anyway
for {
// Increment our counter
count.Add(count, one)
// Copy count value's bytes to padded slice
copy(padded[32-len(count.Bytes()):], count.Bytes())
sha256 := sha256.Sum256([]byte(padded))
// Print keys
fmt.Printf("%x %x\n", padded, sha256)
}
}
Do you want have string “1” for 1 or wide of string should be some specific wide?
full one line to hash in sha256 and same continues…
means example:- 000000000000000000000000000000000000000000000000000000000000077a
gives 02C62AE7237817928D659F1004A920030FAE9556A6B6FEBF6701B60AD5285961
as sha256
Did you got any result? waiting for correct code.
Code below works for me, you just should know about print-specifiers (%x, %d, %s ,…)
package main
import (
"crypto/sha256"
"fmt"
"math/big"
"strings"
)
func main() {
// Print header
fmt.Printf("%64s %64s\n", "Raw-sha256", "hash-256")
// Initialise big numbers with small numbers
count, one := big.NewInt(0), big.NewInt(1)
// Loop forever because we're never going to hit the end anyway
for i := 0; i < 100; i++ {
// Increment our counter
count.Add(count, one)
str := count.String()
str = strings.Repeat("0", 64-len(str)) + str
sha256 := sha256.Sum256([]byte(str))
// Print keys
fmt.Printf("%s %X\n", str, sha256)
}
}
Code is Nice But But my Charactars are missing abcdef0123456789 and it only has numbers.
Ah, sorry, I just forgot that your task still to variate “abcdef0123456789” string. Fixed:
package main
import (
"crypto/sha256"
"fmt"
"math/big"
)
func main() {
// Print header
fmt.Printf("%64s %64s\n", "Raw-sha256", "hash-256")
// Initialise big numbers with small numbers
count, one := big.NewInt(0), big.NewInt(1)
// Create a slice to pad our count to 32 bytes
padded := make([]byte, 32)
// Loop forever because we're never going to hit the end anyway
for i := 0; i < 100; i++ {
// Increment our counter
count.Add(count, one)
// Copy count value's bytes to padded slice
copy(padded[32-len(count.Bytes()):], count.Bytes())
sha256 := sha256.Sum256([]byte(fmt.Sprintf("%X", padded)))
// Print keys
fmt.Printf("%X %X\n", padded, sha256)
}
}
So I only add convertion to hex here:
fmt.Sprintf(“%X”, padded)
because you must hash exactly the string which display after in hex.
This is the Extract Code. For this Solution. Great Work , Grey Shatter and I learned alot. now i merge this code with another code in github and will look, if it fits in or not.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.