Last active
October 8, 2021 07:23
-
-
Save Humphryyy/da5aeac0683a2f79bf72b62efc630484 to your computer and use it in GitHub Desktop.
Java Script Kiddie - Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"strconv" | |
"strings" | |
"unicode/utf8" | |
) | |
var LEN = 16 | |
// HUMPHREY | |
func main() { | |
fmt.Println("Enter bytes:") | |
var bytesRaw string | |
scanner := bufio.NewScanner(os.Stdin) | |
for scanner.Scan() { | |
bytesRaw = scanner.Text() | |
if bytesRaw != "" { | |
break | |
} | |
} | |
byteStrings := strings.Split(string(bytesRaw), " ") | |
bytes := []int{} | |
for _, bs := range byteStrings { | |
num, _ := strconv.Atoi(bs) | |
bytes = append(bytes, num) | |
} | |
var pngHeader = []int{0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52} | |
var shifts = make([][]int, 16) | |
for i := 0; i < LEN; i++ { | |
for s := 0; s < 10; s++ { | |
if bytes[((s*LEN)%len(bytes))+i] == pngHeader[i] { | |
shifts[i] = append(shifts[i], s) | |
} | |
} | |
} | |
var key string | |
for _, shift := range shifts { | |
key += fmt.Sprint(shift[0]) | |
} | |
fmt.Println("Key: " + key) | |
fmt.Println("PNG Bytes:") | |
test(bytes, key) | |
} | |
func charCodeAt(str string, i int) int { | |
r, _ := utf8.DecodeRuneInString(string(str[i])) | |
return int(r) | |
} | |
func test(bytes []int, key string) { | |
var shifter int | |
result := make([]int, len(bytes)*16) | |
for i := 0; i < LEN; i++ { | |
shifter = charCodeAt(key, i) - 48 | |
for j := 0; j < len(bytes)/LEN; j++ { | |
result[(j*LEN + i)] = bytes[(((j+shifter)*LEN)%len(bytes))+i] | |
} | |
} | |
for result[len(result)-1] == 0 { | |
result = result[:len(result)-1] | |
} | |
var strs []string | |
for _, num := range result { | |
strs = append(strs, fmt.Sprintf("%x", num)) | |
} | |
fmt.Println(strings.Join(strs, " ")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment